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
- Host: GitHub
- URL: https://github.com/timob/httpsession
- Owner: timob
- License: bsd-2-clause
- Created: 2014-05-11T14:50:42.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2014-10-21T15:33:36.000Z (over 11 years ago)
- Last Synced: 2024-06-21T13:15:07.541Z (almost 2 years ago)
- Language: Go
- Size: 223 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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)
}
}```