Skip to content

Commit

Permalink
Use /v3 module and fix some warning
Browse files Browse the repository at this point in the history
  • Loading branch information
LyricTian committed Dec 9, 2021
1 parent 77451f6 commit 01a634a
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@

# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/

.vscode
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -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`
Expand All @@ -22,7 +22,7 @@ import (
"fmt"
"net/http"

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

func main() {
Expand Down Expand Up @@ -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

<http://localhost:8080>

```text
foo:bar
```

## Features

Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Example:
"fmt"
"net/http"
"github.com/go-session/session"
session "github.com/go-session/session/v3"
)
func main() {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/go-session/session
module github.com/go-session/session/v3

go 1.14

Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
10 changes: 5 additions & 5 deletions session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 01a634a

Please sign in to comment.