An open API service indexing awesome lists of open source software.

https://github.com/timob/httpsession

Go HTTP session package
https://github.com/timob/httpsession

Last synced: 5 months ago
JSON representation

Go HTTP session package

Awesome Lists containing this project

README

          

httpsession
==========
Go HTTP session library. Sessions consist of an id token given to client and an entry in a key-value store on the server.
Support for authentication token which changes periodically.

Documentation
-------------
http://godoc.org/github.com/timob/httpsession

Example
-------
```Go
package main

import (
"fmt"
"github.com/timob/httpsession"
"github.com/timob/httpsession/store/mapstore"
"log"
"net/http"
"time"
)

var store = mapstore.NewMapSessionStore()

func main() {
http.Handle("/", http.HandlerFunc(
func(resp http.ResponseWriter, req *http.Request) {
session, _ := httpsession.OpenCookieSession("websess", store, resp, req)
counter := session.IntVar("counter")
session.SetVar("counter", counter+1)
session.Save(time.Minute)
fmt.Fprintf(resp, "counter = %d", counter)
},
))

err := http.ListenAndServe(":7878", nil)
if err != nil {
log.Fatal(err)
}
}```