Go to file
2020-06-17 18:56:09 +02:00
go.mod Update 'go.mod' 2020-06-17 18:55:43 +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 Update 'README.md' 2020-06-17 18:56:09 +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 (
    "git.icod.de/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)
        }
    }