Skip to content

Commit

Permalink
Merge pull request #8 from laziness-coders/deepsource-transform-f2943884
Browse files Browse the repository at this point in the history
style: format code with Go fmt and Gofumpt
  • Loading branch information
bos-hieu authored Feb 15, 2024
2 parents 1b7f637 + eae17c2 commit cf995a9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
5 changes: 3 additions & 2 deletions mgostore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ package mongostore
import (
"context"
"encoding/gob"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"net/http"
"net/http/httptest"
"testing"

"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"

"github.com/gorilla/sessions"
)

Expand Down
17 changes: 9 additions & 8 deletions mongostore.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ import (
"go.mongodb.org/mongo-driver/mongo/options"
)

var (
ErrInvalidId = errors.New("mgostore: invalid session id")
)
var ErrInvalidId = errors.New("mgostore: invalid session id")

// Session object store in MongoDB
type Session struct {
Expand All @@ -44,7 +42,8 @@ var base32RawStdEncoding = base32.StdEncoding.WithPadding(base32.NoPadding)
// NewMongoStore returns a new MongoStore.
// Set ensureTTL to true let the database auto-remove expired object by maxAge.
func NewMongoStore(c *mongo.Collection, maxAge int, ensureTTL bool,
keyPairs ...[]byte) *MongoStore {
keyPairs ...[]byte,
) *MongoStore {
store := &MongoStore{
Codecs: securecookie.CodecsFromPairs(keyPairs...),
Options: &sessions.Options{
Expand Down Expand Up @@ -80,13 +79,15 @@ func NewMongoStore(c *mongo.Collection, maxAge int, ensureTTL bool,
// Get registers and returns a session for the given name and session store.
// It returns a new session if there are no sessions registered for the name.
func (m *MongoStore) Get(r *http.Request, name string) (
*sessions.Session, error) {
*sessions.Session, error,
) {
return sessions.GetRegistry(r).Get(m, name)
}

// New returns a session for the given name without adding it to the registry.
func (m *MongoStore) New(r *http.Request, name string) (
*sessions.Session, error) {
*sessions.Session, error,
) {
session := sessions.NewSession(m, name)
session.Options = &sessions.Options{
Path: m.Options.Path,
Expand Down Expand Up @@ -115,7 +116,8 @@ func (m *MongoStore) New(r *http.Request, name string) (

// Save saves all sessions registered for the current request.
func (m *MongoStore) Save(_ *http.Request, w http.ResponseWriter,
session *sessions.Session) error {
session *sessions.Session,
) error {
if session.Options.MaxAge < 0 {
if err := m.delete(session); err != nil {
return err
Expand Down Expand Up @@ -173,7 +175,6 @@ func (m *MongoStore) load(session *sessions.Session) error {
}

func (m *MongoStore) upsert(session *sessions.Session) error {

var modified time.Time
if val, ok := session.Values["modified"]; ok {
modified, ok = val.(time.Time)
Expand Down
3 changes: 2 additions & 1 deletion token.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func (*CookieToken) GetToken(req *http.Request, name string) (string, error) {
}

func (*CookieToken) SetToken(rw http.ResponseWriter, name, value string,
options *sessions.Options) {
options *sessions.Options,
) {
http.SetCookie(rw, sessions.NewCookie(name, value, options))
}

0 comments on commit cf995a9

Please sign in to comment.