Categorygithub.com/laziness-coders/mongostore
modulepackage
0.0.14
Repository: https://github.com/laziness-coders/mongostore.git
Documentation: pkg.go.dev

# README

mongostore

CodeQL Run Tests Go Report Card GoDoc codecov

Gorilla's Session store implementation with MongoDB

Requirements

Depends on the mgo library.

Installation

For the latest go version, run:

go get github.com/laziness-coders/mongostore

For the go version 1.20 and under, run:

go get github.com/laziness-coders/[email protected]

Documentation

Available on godoc.org.

Example

    func foo(rw http.ResponseWriter, req *http.Request) {
        // Fetch new store..
    	client, err := mongo.NewClient(options.Client().ApplyURI("mongodb://localhost:27017"))
    	if err != nil {
    		panic(err)
    	}
    	
    	if err := client.Connect(context.Background()); err != nil {
    		panic(err)
    	}
    	defer client.Disconnect(context.Background())

        // Get a session.
        store := NewMongoStore(
            client.Database("test").Collection("test_session"),
            3600,
            false,
            []byte("secret-key"),
        )

        // Add a value.
        session.Values["foo"] = "bar"

        // Save.
        if err = sessions.Save(req, rw); err != nil {
            log.Printf("Error saving session: %v", err)
        }

        fmt.Fprintln(rw, "ok")
    }

# Functions

NewMongoStore returns a new MongoStore.

# Variables

No description provided by the author

# Structs

No description provided by the author
MongoStore stores sessions in MongoDB.
Session object store in MongoDB.

# Interfaces

No description provided by the author