Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: format code with Go fmt and Gofumpt #8

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
}
Loading