Skip to content

Commit 78ace53

Browse files
committed
make compatible with session/v3
1 parent ef6d610 commit 78ace53

File tree

5 files changed

+42
-15
lines changed

5 files changed

+42
-15
lines changed

cookie.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"sync"
77
"time"
88

9-
"github.com/go-session/session"
9+
"github.com/go-session/session/v3"
1010
"github.com/gorilla/securecookie"
1111
)
1212

@@ -46,8 +46,8 @@ func NewCookieStore(opt ...Option) session.ManagerStore {
4646
}
4747

4848
type managerStore struct {
49-
opts options
5049
cookie *securecookie.SecureCookie
50+
opts options
5151
}
5252

5353
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
171171

172172
type store struct {
173173
sync.RWMutex
174-
opts options
174+
ctx context.Context
175175
cookie *securecookie.SecureCookie
176+
values map[string]interface{}
176177
sid string
177-
ctx context.Context
178+
opts options
178179
expired int64
179-
values map[string]interface{}
180180
}
181181

182182
func (s *store) Context() context.Context {

cookie_test.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@ package cookie
33
import (
44
"context"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"net/http"
88
"net/http/httptest"
99
"testing"
1010

11-
"github.com/go-session/session"
11+
"github.com/go-session/session/v3"
1212
)
1313

14-
var (
15-
hashKey = []byte("FF51A553-72FC-478B-9AEF-93D6F506DE91")
16-
)
14+
var hashKey = []byte("FF51A553-72FC-478B-9AEF-93D6F506DE91")
1715

1816
func TestCookie(t *testing.T) {
1917
sess := session.NewManager(
@@ -55,7 +53,7 @@ func TestCookie(t *testing.T) {
5553
return
5654
}
5755

58-
buf, _ := ioutil.ReadAll(res.Body)
56+
buf, _ := io.ReadAll(res.Body)
5957
if string(buf) != "ok" {
6058
t.Error("Not expected value:", string(buf))
6159
return
@@ -78,7 +76,7 @@ func TestCookie(t *testing.T) {
7876
return
7977
}
8078

81-
buf, _ = ioutil.ReadAll(res.Body)
79+
buf, _ = io.ReadAll(res.Body)
8280
res.Body.Close()
8381
if string(buf) != "bar:true" {
8482
t.Error("Not expected value:", string(buf))

go.mod

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module github.com/go-session/cookie
2+
3+
go 1.19
4+
5+
require (
6+
github.com/go-session/session/v3 v3.1.7
7+
github.com/gorilla/securecookie v1.1.1
8+
)
9+
10+
require github.com/smartystreets/goconvey v1.7.2 // indirect

go.sum

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
github.com/go-session/session v3.1.2+incompatible h1:yStchEObKg4nk2F7JGE7KoFIrA/1Y078peagMWcrncg=
2+
github.com/go-session/session v3.1.2+incompatible/go.mod h1:8B3iivBQjrz/JtC68Np2T1yBBLxTan3mn/3OM0CyRt0=
3+
github.com/go-session/session/v3 v3.1.7 h1:itIpJrGInZ4TCcxHM0JhrcQmbAuDTxBKs/RusiZqB/U=
4+
github.com/go-session/session/v3 v3.1.7/go.mod h1:PieA4nuP9myN/vnXEOMZasQZ28cj77KP2K0SyLiZ6dk=
5+
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
6+
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 h1:l5lAOZEym3oK3SQ2HBHWsJUfbNBiTXJDeW2QDxw9AQ0=
7+
github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=
8+
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
9+
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
10+
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
11+
github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs=
12+
github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
13+
github.com/smartystreets/goconvey v1.7.2 h1:9RBaZCeXEQ3UselpuwUQHltGVXvdwm6cv1hgR6gDIPg=
14+
github.com/smartystreets/goconvey v1.7.2/go.mod h1:Vw0tHAZW6lzCRk3xgdin6fKYcG+G3Pg9vgXWeJpQFMM=
15+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
16+
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
17+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
18+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
19+
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=

options.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ var defaultOptions = options{
1414
}
1515

1616
type options struct {
17+
hashFunc func() hash.Hash
18+
blockFunc func([]byte) (cipher.Block, error)
1719
cookieName string
18-
secure bool
1920
hashKey []byte
20-
hashFunc func() hash.Hash
2121
blockKey []byte
22-
blockFunc func([]byte) (cipher.Block, error)
2322
maxLength int
2423
maxAge int
2524
minAge int
25+
secure bool
2626
}
2727

2828
// Option A cookie parameter options

0 commit comments

Comments
 (0)