Categorygithub.com/svedok/mongostore
modulepackage
0.0.0-20200715133431-d6e21d524f3e
Repository: https://github.com/svedok/mongostore.git
Documentation: pkg.go.dev

# README

mongostore

MongoDB implementation for Gorilla's Session store using the official MongoDB driver for Go.

Installation

go get github.com/svedok/mongostore

Example

    func foo(rw http.ResponseWriter, req *http.Request) {
        // Fetch new store.
        m, err := mongo.Connect(context.Background())
        if err != nil {
            panic(err)
        }
        defer m.Disconnect(context.Background())

        store, err := NewMongoStore(m.Database("test").Collection("test_session"), 3600, true, []byte("secret-key"))
        if err != nil {
            panic(err)
        }

        // Get a session.
        session, err := store.Get(req, "session-key")
        if err != nil {
            log.Println(err.Error())
        }

        // 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.

# Structs

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

# Interfaces

No description provided by the author