Skip to content

Commit

Permalink
make compatible with session/v3
Browse files Browse the repository at this point in the history
  • Loading branch information
bokunodev committed Aug 30, 2022
1 parent ef6d610 commit 78ace53
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 15 deletions.
10 changes: 5 additions & 5 deletions cookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"sync"
"time"

"github.com/go-session/session"
"github.com/go-session/session/v3"
"github.com/gorilla/securecookie"
)

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 5 additions & 7 deletions cookie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand Down
10 changes: 10 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
6 changes: 3 additions & 3 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 78ace53

Please sign in to comment.