Update zh/04.4.md

more readable code with token
This commit is contained in:
胡子豪
2021-03-02 21:08:21 +08:00
committed by GitHub
parent 72d959bfa7
commit 546b604cba

View File

@@ -21,10 +21,10 @@
func login(w http.ResponseWriter, r *http.Request) {
fmt.Println("method:", r.Method) //获取请求的方法
if r.Method == "GET" {
crutime := time.Now().Unix()
h := md5.New()
io.WriteString(h, strconv.FormatInt(crutime, 10))
token := fmt.Sprintf("%x", h.Sum(nil))
timestamp := strconv.Itoa(time.Now().Nanosecond())
hashWr := md5.New()
hashWr.Write([]byte(timestamp))
token := fmt.Sprintf("%x", hashWr.Sum(nil))
t, _ := template.ParseFiles("login.gtpl")
t.Execute(w, token)