Skip to content

Commit

Permalink
added sqlite store
Browse files Browse the repository at this point in the history
  • Loading branch information
Prokopenko Andrey committed Jul 2, 2021
1 parent de01a56 commit 12066bc
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 3 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ require (
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8
github.com/gomodule/redigo v2.0.0+incompatible
github.com/gorilla/context v1.1.1
github.com/gorilla/sessions v1.2.0
github.com/gorilla/sessions v1.2.1
github.com/kidstuff/mongostore v0.0.0-20181113001930-e650cd85ee4b
github.com/memcachier/mc v2.0.1+incompatible
github.com/quasoft/memstore v0.0.0-20191010062613-2bce066d2b0b
github.com/terem42/sqlite3store v1.0.0
)
12 changes: 10 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
crawshaw.io/iox v0.0.0-20181124134642-c51c3df30797 h1:yDf7ARQc637HoxDho7xjqdvO5ZA2Yb+xzv/fOnnvZzw=
crawshaw.io/iox v0.0.0-20181124134642-c51c3df30797/go.mod h1:sXBiorCo8c46JlQV3oXPKINnZ8mcqnye1EkVkqsectk=
crawshaw.io/sqlite v0.3.2 h1:N6IzTjkiw9FItHAa0jp+ZKC6tuLzXqAYIv+ccIWos1I=
crawshaw.io/sqlite v0.3.2/go.mod h1:igAO5JulrQ1DbdZdtVq48mnZUBAPOeFzer7VhDWNtW4=
github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff h1:RmdPFa+slIr4SCBg4st/l/vZWVe9QJKMXGO60Bxbe04=
github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff/go.mod h1:+RTT1BOk5P97fT2CiHkbFQwkK3mjsFAP6zCYV2aXtjw=
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b h1:L/QXpzIa3pOvUGt1D1lA5KjYhPBAN/3iWdP7xeFS9F0=
Expand Down Expand Up @@ -32,8 +36,8 @@ github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51
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/gorilla/sessions v1.1.1/go.mod h1:8KCfur6+4Mqcc6S0FEfKuN15Vl5MgXW92AE8ovaJD0w=
github.com/gorilla/sessions v1.2.0 h1:S7P+1Hm5V/AT9cjEcUD5uDaQSX0OE577aCXgoaKpYbQ=
github.com/gorilla/sessions v1.2.0/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
github.com/gorilla/sessions v1.2.1 h1:DHd3rPN5lE3Ts3D8rKkQ8x/0kqfeNmBAaiSi+o7FsgI=
github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/kidstuff/mongostore v0.0.0-20181113001930-e650cd85ee4b h1:TLCm7HR+P9HM2NXaAJaIiHerOUMedtFJeAfaYwZ8YhY=
Expand All @@ -48,6 +52,8 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OH
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/quasoft/memstore v0.0.0-20191010062613-2bce066d2b0b h1:aUNXCGgukb4gtY99imuIeoh8Vr0GSwAlYxPAhqZrpFc=
Expand All @@ -57,6 +63,8 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/terem42/sqlite3store v1.0.0 h1:6q+yNxFLFBp0hqAt2THswusdLOkqSj/E/Oaqeipk4BU=
github.com/terem42/sqlite3store v1.0.0/go.mod h1:BULc/GWhyahcGF3WkvFrqNyR0frMhuNhfI+h9P/fXqw=
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
Expand Down
28 changes: 28 additions & 0 deletions sqlite/sqlite.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package sqlite

import (
"net/http"

"github.com/gin-contrib/sessions"
"github.com/terem42/sqlite3store"
)

type Store interface {
sessions.Store
}

func NewStore(db_file_location string, db_pool_size int, db_table_name string, maxAge int, keyPairs ...[]byte) (Store, error) {
s, err := sqlite3store.NewSqliteStore(db_file_location, db_pool_size, db_table_name, "/", "", false, false, http.SameSiteNoneMode, maxAge, keyPairs...)
if err != nil {
return nil, err
}
return &store{s}, nil
}

type store struct {
*sqlite3store.SqliteStore
}

func (c *store) Options(options sessions.Options) {
c.SqliteStore.Options = options.ToGorillaOptions()
}
54 changes: 54 additions & 0 deletions sqlite/sqlite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package sqlite

import (
"os"
"testing"

"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/tester"
)

var newStore = func(t *testing.T) sessions.Store {
store, err := NewStore("test.db", 10, "sessions", 600, []byte("secret-key"))
if err != nil {
t.Fatal(err.Error())
}

return store
}

func TestSqlite_SessionGetSet(t *testing.T) {
tester.GetSet(t, newStore)
t.Cleanup(cleanup)
}

func TestSqlite_SessionDeleteKey(t *testing.T) {
tester.DeleteKey(t, newStore)
t.Cleanup(cleanup)
}

func TestSqlite_SessionFlashes(t *testing.T) {
tester.Flashes(t, newStore)
t.Cleanup(cleanup)
}

func TestSqlite_SessionClear(t *testing.T) {
tester.Clear(t, newStore)
t.Cleanup(cleanup)
}

func TestSqlite_SessionOptions(t *testing.T) {
tester.Options(t, newStore)
t.Cleanup(cleanup)
}

func TestSqlite_SessionMany(t *testing.T) {
tester.Many(t, newStore)
t.Cleanup(cleanup)
}

func cleanup() {
os.Remove("test.db")
os.Remove("test.db-shm")
os.Remove("test.db-wal")
}

0 comments on commit 12066bc

Please sign in to comment.