Skip to content

izinga/mongostore

 
 

Repository files navigation

mongostore

Gorilla's Session store implementation with MongoDB

Requirements

Depends on the mgo library.

Installation

go get https://github.com/laziercoder/mongostore

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

About

Gorilla's Session store implementation with MongoDB

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%