Skip to content

Repository files navigation

session

A efficient, safely and easy-to-use session library for Go.

BuildCodecovReportCardGoDocLicense

Quick Start

Download and install

go get -v github.com/go-session/session/v3

Create file server.go

package main
import (
"context""fmt""net/http"
session "github.com/go-session/session/v3"
)
funcmain() {
http.HandleFunc("/", func(w http.ResponseWriter, r*http.Request) {
store, err:=session.Start(context.Background(), w, r)
iferr!=nil {
fmt.Fprint(w, err)
return
}
store.Set("foo", "bar")
err=store.Save()
iferr!=nil {
fmt.Fprint(w, err)
return
}
http.Redirect(w, r, "/foo", 302)
})
http.HandleFunc("/foo", func(w http.ResponseWriter, r*http.Request) {
store, err:=session.Start(context.Background(), w, r)
iferr!=nil {
fmt.Fprint(w, err)
return
}
foo, ok:=store.Get("foo")
ifok {
fmt.Fprintf(w, "foo:%s", foo)
return
}
fmt.Fprint(w, "does not exist")
})
http.ListenAndServe(":8080", nil)
}

Build and run

go build server.go
./server

Open in your web browser

http://localhost:8080

 foo:bar

Features

  • Easy to use
  • Multi-storage support
  • Multi-middleware support
  • More secure, signature-based tamper-proof
  • Context support
  • Support request header and query parameters

Store Implementations

Middlewares

MIT License

Copyright (c) 2021 Lyric

About

A efficient, safely and easy-to-use session library for Go.

Topics

Resources

Stars

234 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages