diff --git a/main.go b/main.go index 6752d50..ae63e60 100644 --- a/main.go +++ b/main.go @@ -2,9 +2,13 @@ package main import ( "embed" + "fmt" "html/template" "log" "net/http" + "os" + "strings" + "time" ) type EmojiDetails struct { @@ -28,8 +32,10 @@ func handleForm(w http.ResponseWriter, r *http.Request) { Url: r.FormValue("url"), } - log.Print(details.Label) - log.Print(details.Url) + now := time.Now().UTC().Format(time.RFC3339) + entry := strings.Join([]string{now, details.Label, details.Url}, ",") + log.Print("inserting: ", entry) + insertEntry(entry) tmpl.Execute(w, struct{ Success bool }{true}) } @@ -39,6 +45,19 @@ func setupRoutes() { 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() { setupRoutes() }