mirror of
https://codeberg.org/mycelium/emojiquest.git
synced 2024-09-29 14:57:54 +00:00
save request to local file, csv format
This commit is contained in:
parent
3c029c9563
commit
441927946c
23
main.go
23
main.go
|
@ -2,9 +2,13 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type EmojiDetails struct {
|
type EmojiDetails struct {
|
||||||
|
@ -28,8 +32,10 @@ func handleForm(w http.ResponseWriter, r *http.Request) {
|
||||||
Url: r.FormValue("url"),
|
Url: r.FormValue("url"),
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Print(details.Label)
|
now := time.Now().UTC().Format(time.RFC3339)
|
||||||
log.Print(details.Url)
|
entry := strings.Join([]string{now, details.Label, details.Url}, ",")
|
||||||
|
log.Print("inserting: ", entry)
|
||||||
|
insertEntry(entry)
|
||||||
|
|
||||||
tmpl.Execute(w, struct{ Success bool }{true})
|
tmpl.Execute(w, struct{ Success bool }{true})
|
||||||
}
|
}
|
||||||
|
@ -39,6 +45,19 @@ func setupRoutes() {
|
||||||
http.ListenAndServe(":8080", nil)
|
http.ListenAndServe(":8080", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func insertEntry(entry string) {
|
||||||
|
f, err := os.OpenFile("requests.txt",
|
||||||
|
os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
entryFormatted := fmt.Sprintf("%s\n", entry)
|
||||||
|
if _, err := f.WriteString(entryFormatted); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
setupRoutes()
|
setupRoutes()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue