@@ -0,0 +1,30 @@
+package jy
+
+import (
+ "net/http"
+ "time"
+)
+// SetCookie 更新cookie信息
+func SetCookie(w http.ResponseWriter, r *http.Request, name, val, domain string, timeOut int) {
+ if name == "" {
+ return
+ }
+ if domain == "" {
+ domain = r.Host
+ http.SetCookie(w, func() *http.Cookie {
+ maxAge := timeOut //单位秒
+ expires := time.Now().Add(time.Duration(timeOut) * time.Second)
+ cookie := &http.Cookie{
+ Name: name,
+ Value: val,
+ Path: "/",
+ HttpOnly: false,
+ MaxAge: maxAge,
+ Expires: expires,
+ Domain: domain,
+ return cookie
+ }())
+}