diff --git a/cookie.go b/cookie.go index 9aafa0f..fe383b3 100644 --- a/cookie.go +++ b/cookie.go @@ -6,7 +6,7 @@ import ( "sync" "time" - "github.com/go-session/session" + "github.com/go-session/session/v3" "github.com/gorilla/securecookie" ) @@ -46,8 +46,8 @@ func NewCookieStore(opt ...Option) session.ManagerStore { } type managerStore struct { - opts options cookie *securecookie.SecureCookie + opts options } func (s *managerStore) Create(ctx context.Context, sid string, expired int64) (session.Store, error) { @@ -171,12 +171,12 @@ func newStore(ctx context.Context, s *managerStore, sid string, expired int64, v type store struct { sync.RWMutex - opts options + ctx context.Context cookie *securecookie.SecureCookie + values map[string]interface{} sid string - ctx context.Context + opts options expired int64 - values map[string]interface{} } func (s *store) Context() context.Context { diff --git a/cookie_test.go b/cookie_test.go index 3139627..da269de 100644 --- a/cookie_test.go +++ b/cookie_test.go @@ -3,17 +3,15 @@ package cookie import ( "context" "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "testing" - "github.com/go-session/session" + "github.com/go-session/session/v3" ) -var ( - hashKey = []byte("FF51A553-72FC-478B-9AEF-93D6F506DE91") -) +var hashKey = []byte("FF51A553-72FC-478B-9AEF-93D6F506DE91") func TestCookie(t *testing.T) { sess := session.NewManager( @@ -55,7 +53,7 @@ func TestCookie(t *testing.T) { return } - buf, _ := ioutil.ReadAll(res.Body) + buf, _ := io.ReadAll(res.Body) if string(buf) != "ok" { t.Error("Not expected value:", string(buf)) return @@ -78,7 +76,7 @@ func TestCookie(t *testing.T) { return } - buf, _ = ioutil.ReadAll(res.Body) + buf, _ = io.ReadAll(res.Body) res.Body.Close() if string(buf) != "bar:true" { t.Error("Not expected value:", string(buf)) diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..4de9b2c --- /dev/null +++ b/go.mod @@ -0,0 +1,10 @@ +module github.com/go-session/cookie + +go 1.19 + +require ( + github.com/go-session/session/v3 v3.1.7 + github.com/gorilla/securecookie v1.1.1 +) + +require github.com/smartystreets/goconvey v1.7.2 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..1f6234d --- /dev/null +++ b/go.sum @@ -0,0 +1,19 @@ +github.com/go-session/session v3.1.2+incompatible h1:yStchEObKg4nk2F7JGE7KoFIrA/1Y078peagMWcrncg= +github.com/go-session/session v3.1.2+incompatible/go.mod h1:8B3iivBQjrz/JtC68Np2T1yBBLxTan3mn/3OM0CyRt0= +github.com/go-session/session/v3 v3.1.7 h1:itIpJrGInZ4TCcxHM0JhrcQmbAuDTxBKs/RusiZqB/U= +github.com/go-session/session/v3 v3.1.7/go.mod h1:PieA4nuP9myN/vnXEOMZasQZ28cj77KP2K0SyLiZ6dk= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 h1:l5lAOZEym3oK3SQ2HBHWsJUfbNBiTXJDeW2QDxw9AQ0= +github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ= +github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= +github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs= +github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo= +github.com/smartystreets/goconvey v1.7.2 h1:9RBaZCeXEQ3UselpuwUQHltGVXvdwm6cv1hgR6gDIPg= +github.com/smartystreets/goconvey v1.7.2/go.mod h1:Vw0tHAZW6lzCRk3xgdin6fKYcG+G3Pg9vgXWeJpQFMM= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= diff --git a/options.go b/options.go index 7a8bfd6..09a56b8 100644 --- a/options.go +++ b/options.go @@ -14,15 +14,15 @@ var defaultOptions = options{ } type options struct { + hashFunc func() hash.Hash + blockFunc func([]byte) (cipher.Block, error) cookieName string - secure bool hashKey []byte - hashFunc func() hash.Hash blockKey []byte - blockFunc func([]byte) (cipher.Block, error) maxLength int maxAge int minAge int + secure bool } // Option A cookie parameter options