From 22985f7f5f0772f29809c6f107515a287d6e4243 Mon Sep 17 00:00:00 2001 From: lyric Date: Wed, 5 Dec 2018 20:34:28 +0800 Subject: [PATCH] update vendor --- src/util/string.go | 10 +++ src/web/context/context.go | 4 +- .../github.com/go-session/session/session.go | 68 ++++++++++--------- vendor/vendor.json | 6 +- 4 files changed, 50 insertions(+), 38 deletions(-) diff --git a/src/util/string.go b/src/util/string.go index 4214fbb6..c2c5c7e7 100644 --- a/src/util/string.go +++ b/src/util/string.go @@ -11,6 +11,11 @@ func (s S) String() string { return string(s) } +// Bytes 转换为[]byte +func (s S) Bytes() []byte { + return []byte(s) +} + // Int64 转换为int64 func (s S) Int64() int64 { i, err := strconv.ParseInt(s.String(), 10, 64) @@ -47,3 +52,8 @@ func (s S) Float64() float64 { } return f } + +// ToJSON 转换为JSON +func (s S) ToJSON(v interface{}) error { + return json.Unmarshal(s.Bytes(), v) +} diff --git a/src/web/context/context.go b/src/web/context/context.go index 2f811fdd..89b62279 100644 --- a/src/web/context/context.go +++ b/src/web/context/context.go @@ -44,7 +44,7 @@ func (a *Context) NewContext() context.Context { // GetPageIndex 获取分页的页索引 func (a *Context) GetPageIndex() uint { if v := a.Query("current"); v != "" { - if iv := util.T(v).Uint(); iv > 0 { + if iv := util.S(v).Uint(); iv > 0 { return iv } } @@ -54,7 +54,7 @@ func (a *Context) GetPageIndex() uint { // GetPageSize 获取分页的页大小 func (a *Context) GetPageSize() uint { if v := a.Query("pageSize"); v != "" { - if iv := util.T(v).Uint(); iv > 0 { + if iv := util.S(v).Uint(); iv > 0 { if iv > 50 { iv = 50 } diff --git a/vendor/github.com/go-session/session/session.go b/vendor/github.com/go-session/session/session.go index 9a994635..05556b83 100644 --- a/vendor/github.com/go-session/session/session.go +++ b/vendor/github.com/go-session/session/session.go @@ -199,21 +199,23 @@ func (m *Manager) decodeSessionID(value string) (string, error) { func (m *Manager) sessionID(r *http.Request) (string, error) { var cookieValue string - cookie, err := r.Cookie(m.opts.cookieName) - if err == nil && cookie.Value != "" { - cookieValue = cookie.Value - } else { - if m.opts.enableSIDInURLQuery { - err := r.ParseForm() - if err != nil { - return "", err - } - cookieValue = r.FormValue(m.opts.cookieName) + if m.opts.enableSetCookie { + cookie, err := r.Cookie(m.opts.cookieName) + if err == nil && cookie.Value != "" { + cookieValue = cookie.Value } + } - if m.opts.enableSIDInHTTPHeader && cookieValue == "" { - cookieValue = r.Header.Get(m.opts.sessionNameInHTTPHeader) + if m.opts.enableSIDInURLQuery && cookieValue == "" { + err := r.ParseForm() + if err != nil { + return "", err } + cookieValue = r.FormValue(m.opts.cookieName) + } + + if m.opts.enableSIDInHTTPHeader && cookieValue == "" { + cookieValue = r.Header.Get(m.opts.sessionNameInHTTPHeader) } if cookieValue != "" { @@ -244,26 +246,26 @@ func (m *Manager) isSecure(r *http.Request) bool { func (m *Manager) setCookie(sessionID string, w http.ResponseWriter, r *http.Request) { cookieValue := m.encodeSessionID(sessionID) - cookie := &http.Cookie{ - Name: m.opts.cookieName, - Value: cookieValue, - Path: "/", - HttpOnly: true, - Secure: m.isSecure(r), - Domain: m.opts.domain, - } - - if v := m.opts.cookieLifeTime; v > 0 { - cookie.MaxAge = v - cookie.Expires = time.Now().Add(time.Duration(v) * time.Second) - } if m.opts.enableSetCookie { + cookie := &http.Cookie{ + Name: m.opts.cookieName, + Value: cookieValue, + Path: "/", + HttpOnly: true, + Secure: m.isSecure(r), + Domain: m.opts.domain, + } + + if v := m.opts.cookieLifeTime; v > 0 { + cookie.MaxAge = v + cookie.Expires = time.Now().Add(time.Duration(v) * time.Second) + } + http.SetCookie(w, cookie) + r.AddCookie(cookie) } - r.AddCookie(cookie) - if m.opts.enableSIDInHTTPHeader { key := m.opts.sessionNameInHTTPHeader r.Header.Set(key, cookieValue) @@ -340,12 +342,6 @@ func (m *Manager) Destroy(ctx context.Context, w http.ResponseWriter, r *http.Re return err } - if m.opts.enableSIDInHTTPHeader { - key := m.opts.sessionNameInHTTPHeader - r.Header.Del(key) - w.Header().Del(key) - } - if m.opts.enableSetCookie { cookie := &http.Cookie{ Name: m.opts.cookieName, @@ -358,5 +354,11 @@ func (m *Manager) Destroy(ctx context.Context, w http.ResponseWriter, r *http.Re http.SetCookie(w, cookie) } + if m.opts.enableSIDInHTTPHeader { + key := m.opts.sessionNameInHTTPHeader + r.Header.Del(key) + w.Header().Del(key) + } + return nil } diff --git a/vendor/vendor.json b/vendor/vendor.json index 49d597a8..c8a92a77 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -160,10 +160,10 @@ "revisionTime": "2018-10-28T14:48:24Z" }, { - "checksumSHA1": "dH36OQigThXmmJRoFJLmRcWW9c4=", + "checksumSHA1": "gufNtKOpj7eLFn5rHYUuKdyrh4U=", "path": "github.com/go-session/session", - "revision": "5148957874831f27a7d95f708d41eff3d76ec658", - "revisionTime": "2018-11-20T03:52:31Z" + "revision": "cdd85262bbc8417a570bbf5f26ffc3a85540f809", + "revisionTime": "2018-12-05T12:29:55Z" }, { "checksumSHA1": "/A5P2s8crcwfDyqHKCh16Yt9jd4=",