Added IP and Browser string to submit routines

This commit is contained in:
Christopher Ramey 2018-11-18 01:27:51 +00:00 committed by cdramey
parent fefd6dbdce
commit 4d3a84b6b3

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"html/template" "html/template"
"net/http" "net/http"
"net"
"qurl/qurl" "qurl/qurl"
"qurl/static" "qurl/static"
"qurl/storage" "qurl/storage"
@ -53,6 +54,12 @@ func (ctx *SubmitHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
URL: u, URL: u,
Created: time.Now(), Created: time.Now(),
} }
if h, _, err := net.SplitHostPort(r.RemoteAddr); err == nil && h != "" {
q.IP = net.ParseIP(h)
}
if b := r.Header.Get("User-Agent"); b != "" {
q.Browser = b
}
err := q.CheckValid() err := q.CheckValid()
if err != nil { if err != nil {