Go to file
Darko Luketic 308f474a12 README.md
2020-04-02 22:04:53 +02:00
go.mod fixed new logic 2020-04-02 21:32:02 +02:00
go.sum initial 2020-03-22 01:01:55 +01:00
model.go Save(), save(), remove() 2020-04-02 19:16:51 +02:00
README.md README.md 2020-04-02 22:04:53 +02:00
store_test.go README.md 2020-04-02 22:04:53 +02:00
store.go fixed new logic 2020-04-02 21:32:02 +02:00

import (
    "github.com/dalu/mongostore"
)

    func main() {
	    ctx := context.Background()
	    client, err := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://localhost:27017"))
	    err = client.Ping(ctx, readpref.Primary())
	    if err != nil {
    		panic(err)
    	}

	    store := mongostore.NewMongoStore(client, "test", "sessions", 3*time.Second, []byte("hellol-worlol"))
	    store.Options.Path = "/"
	    store.Options.MaxAge = 86400 * 30 * 365
	    defer store.Close()

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