From 01a634a8379b26697042938538782b0c23259787 Mon Sep 17 00:00:00 2001 From: LyricTian Date: Fri, 10 Dec 2021 07:27:36 +0800 Subject: [PATCH] Use /v3 module and fix some warning --- .gitignore | 2 ++ README.md | 20 +++++++++++--------- context_test.go | 6 +++--- default_test.go | 10 +++++----- doc.go | 2 +- go.mod | 2 +- go.sum | 4 ---- session_test.go | 10 +++++----- 8 files changed, 28 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index a1338d6..9e95391 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ # Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 .glide/ + +.vscode diff --git a/README.md b/README.md index 0d249d2..eb933b3 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,15 @@ # session -> A efficient, safely and easy-to-use session library for Go. +> A efficient, safely and easy-to-use session library for Go. -[![Build][Build-Status-Image]][Build-Status-Url] [![Codecov][codecov-image]][codecov-url] [![ReportCard][reportcard-image]][reportcard-url] [![GoDoc][godoc-image]][godoc-url] [![License][license-image]][license-url] +[![Build][build-status-image]][build-status-url] [![Codecov][codecov-image]][codecov-url] [![ReportCard][reportcard-image]][reportcard-url] [![GoDoc][godoc-image]][godoc-url] [![License][license-image]][license-url] ## Quick Start ### Download and install ```bash -$ go get -v github.com/go-session/session +go get -v github.com/go-session/session/v3 ``` ### Create file `server.go` @@ -22,7 +22,7 @@ import ( "fmt" "net/http" - "github.com/go-session/session" + session "github.com/go-session/session/v3" ) func main() { @@ -65,15 +65,17 @@ func main() { ### Build and run ```bash -$ go build server.go -$ ./server +go build server.go +./server ``` ### Open in your web browser +```text foo:bar +``` ## Features @@ -102,10 +104,10 @@ $ ./server ## MIT License - Copyright (c) 2020 Lyric + Copyright (c) 2021 Lyric -[Build-Status-Url]: https://travis-ci.org/go-session/session -[Build-Status-Image]: https://travis-ci.org/go-session/session.svg?branch=master +[build-status-url]: https://travis-ci.org/go-session/session +[build-status-image]: https://travis-ci.org/go-session/session.svg?branch=master [codecov-url]: https://codecov.io/gh/go-session/session [codecov-image]: https://codecov.io/gh/go-session/session/branch/master/graph/badge.svg [reportcard-url]: https://goreportcard.com/report/github.com/go-session/session diff --git a/context_test.go b/context_test.go index f769d81..4b171cb 100644 --- a/context_test.go +++ b/context_test.go @@ -12,15 +12,15 @@ import ( func TestContext(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - var ctxKey interface{} = "ctx" - ctx := context.WithValue(context.Background(), ctxKey, "bar") + type ctxKey struct{} + ctx := context.WithValue(context.Background(), ctxKey{}, "bar") store, err := Start(ctx, w, r) if err != nil { t.Error(err) return } - ctxValue := store.Context().Value(ctxKey) + ctxValue := store.Context().Value(ctxKey{}) if !reflect.DeepEqual(ctxValue, "bar") { t.Error("Not expected value:", ctxValue) return diff --git a/default_test.go b/default_test.go index d452e1f..3acc28f 100644 --- a/default_test.go +++ b/default_test.go @@ -20,7 +20,7 @@ func init() { func TestDefaultStart(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - store, err := Start(nil, w, r) + store, err := Start(r.Context(), w, r) if err != nil { t.Error(err) return @@ -69,7 +69,7 @@ func TestDefaultStart(t *testing.T) { func TestDefaultDestroy(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.URL.Query().Get("logout") == "1" { - err := Destroy(nil, w, r) + err := Destroy(r.Context(), w, r) if err != nil { t.Error(err) return @@ -78,7 +78,7 @@ func TestDefaultDestroy(t *testing.T) { return } - store, err := Start(nil, w, r) + store, err := Start(r.Context(), w, r) if err != nil { t.Error(err) return @@ -133,14 +133,14 @@ func TestDefaultDestroy(t *testing.T) { func TestDefaultRefresh(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - store, err := Start(nil, w, r) + store, err := Start(r.Context(), w, r) if err != nil { t.Error(err) return } if r.URL.Query().Get("refresh") == "1" { - vstore, verr := Refresh(nil, w, r) + vstore, verr := Refresh(r.Context(), w, r) if verr != nil { t.Error(err) return diff --git a/doc.go b/doc.go index 295a420..a6f3c1d 100644 --- a/doc.go +++ b/doc.go @@ -11,7 +11,7 @@ Example: "fmt" "net/http" - "github.com/go-session/session" + session "github.com/go-session/session/v3" ) func main() { diff --git a/go.mod b/go.mod index eb4c65f..30e1195 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/go-session/session +module github.com/go-session/session/v3 go 1.14 diff --git a/go.sum b/go.sum index d2f0ef1..045b839 100644 --- a/go.sum +++ b/go.sum @@ -3,17 +3,13 @@ github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 h1:l5lAOZEym3oK3 github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= 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 v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/assertions v1.1.0 h1:MkTeG1DMwsrdH7QtLXy5W+fUxWq+vmb6cLmyJ7aRtF0= github.com/smartystreets/assertions v1.1.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo= github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= 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 h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= 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 h1:TFlARGu6Czu1z7q93HTxcP1P+/ZFC/IKythI5RzrnRg= golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= diff --git a/session_test.go b/session_test.go index 58f3669..6a331cf 100644 --- a/session_test.go +++ b/session_test.go @@ -17,7 +17,7 @@ func TestSessionStart(t *testing.T) { ) ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - store, err := manager.Start(nil, w, r) + store, err := manager.Start(r.Context(), w, r) if err != nil { t.Error(err) return @@ -72,7 +72,7 @@ func TestSessionDestroy(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.URL.Query().Get("logout") == "1" { - err := manager.Destroy(nil, w, r) + err := manager.Destroy(r.Context(), w, r) if err != nil { t.Error(err) return @@ -81,7 +81,7 @@ func TestSessionDestroy(t *testing.T) { return } - store, err := manager.Start(nil, w, r) + store, err := manager.Start(r.Context(), w, r) if err != nil { t.Error(err) return @@ -142,14 +142,14 @@ func TestSessionRefresh(t *testing.T) { ) ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - store, err := manager.Start(nil, w, r) + store, err := manager.Start(r.Context(), w, r) if err != nil { t.Error(err) return } if r.URL.Query().Get("refresh") == "1" { - vstore, verr := manager.Refresh(nil, w, r) + vstore, verr := manager.Refresh(r.Context(), w, r) if verr != nil { t.Error(err) return