From 546b604cba6996336d0deada7258607f52c07cc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AD=90=E8=B1=AA?= Date: Tue, 2 Mar 2021 21:08:21 +0800 Subject: [PATCH] Update zh/04.4.md more readable code with token --- zh/04.4.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/zh/04.4.md b/zh/04.4.md index 8fa82923..cbe175a9 100644 --- a/zh/04.4.md +++ b/zh/04.4.md @@ -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)