本文整理匯總了Golang中github.com/gorilla/securecookie.SecureCookie.Decode方法的典型用法代碼示例。如果您正苦於以下問題:Golang SecureCookie.Decode方法的具體用法?Golang SecureCookie.Decode怎麽用?Golang SecureCookie.Decode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/gorilla/securecookie.SecureCookie
的用法示例。
在下文中一共展示了SecureCookie.Decode方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: LoggedIn
func LoggedIn(w http.ResponseWriter, r *http.Request, s *securecookie.SecureCookie) bool {
if cookie, err := r.Cookie("whiteboard"); err == nil {
value := make(map[string]string)
if err = s.Decode("whiteboard", cookie.Value, &value); err == nil {
return true
}
return false
}
return false
}
示例2: FetchCookie
func FetchCookie(r *http.Request, storedCookie *securecookie.SecureCookie, cookieName string) string {
if cookie, err := r.Cookie(cookieName); err == nil {
value := make(map[string]string)
if cookie != nil {
err = storedCookie.Decode(cookieName, cookie.Value, &value)
if len(value[cookieName]) > 0 && err == nil {
return value[cookieName]
}
}
}
return ""
}
示例3: VerifyXSRFToken
func VerifyXSRFToken(w http.ResponseWriter, r *http.Request, sessionStore sessions.Store, secureCookie *securecookie.SecureCookie) bool {
xsrftoken := r.Header.Get(XSRFTOKENHEADER)
userID := ""
err := secureCookie.Decode(XSRFTOKEN, xsrftoken, &userID)
if err == nil {
session, _ := sessionStore.Get(r, SESSIONNAME)
if userID != "" && userID == session.Values["username"].(string) {
xlog.Infof("XSRF verification success for user %s", session.Values["username"].(string))
return true
}
xlog.Errorf("XSRF issue: userID = %s session = %s", userID, session.Values["username"].(string))
}
xlog.Errorf("XSRF verification failed: %v (Request: %#v", err, *r)
http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
StatCount("XSRF verification failed", 1)
return false
}