wangshan 4 månader sedan
förälder
incheckning
66e3dcea11
1 ändrade filer med 30 tillägg och 0 borttagningar
  1. 30 0
      common/src/qfw/util/jy/cookie.go

+ 30 - 0
common/src/qfw/util/jy/cookie.go

@@ -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
+	}())
+}