Skip to content

MongoDB store implementation for Gorilla Sessions using the official MongoDB Go driver.

License

Notifications You must be signed in to change notification settings

svedok/mongostore

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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")
    }

About

MongoDB store implementation for Gorilla Sessions using the official MongoDB Go driver.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%