https://github.com/golangtoolkits/go-secure-sessions
A new golang session module works like sessions should work.
https://github.com/golangtoolkits/go-secure-sessions
gorilla-mux gorilla-sessions session-cookie session-management sessions sessionstorage
Last synced: 3 months ago
JSON representation
A new golang session module works like sessions should work.
- Host: GitHub
- URL: https://github.com/golangtoolkits/go-secure-sessions
- Owner: GolangToolKits
- License: mit
- Created: 2023-02-12T01:13:17.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-23T23:48:09.000Z (over 2 years ago)
- Last Synced: 2025-03-02T08:44:45.839Z (7 months ago)
- Topics: gorilla-mux, gorilla-sessions, session-cookie, session-management, sessions, sessionstorage
- Language: Go
- Homepage:
- Size: 14.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-secure-sessions
A new session module to replace gorilla/sessions.
This go-secure-sessions is not dependant on any router.Uses AES-128, AES-192, or AES-256 to store sessions as cookies.
### Using go-secure-sessions
```go
import "github.com/GolangToolKits/go-secure-sessions"
// securekey must be at least 16 char long
// The key argument should be the AES key,
// either 16, 24, or 32 bytes to select
// AES-128, AES-192, or AES-256.
var secretKey = "dsdfs6dfs61dssdfsdfdsdsfsdsdllsd"var cf ConfigOptions
cf.maxAge = 3600
cf.path= "/"
sessionManager, err := NewSessionManager(secretKey, cf)
if err != nil {
fmt.Println(err)
}r, _ := http.NewRequest("POST", "/test/test1", nil)
var w http.ResponseWriter// If a session cookie already exists in the request, it is loaded
// Otherwise a completely new session is created with the name given
session := sessionManager.NewSession(r, "new_test_sesstion")type SomeObject struct{
Id int
Name string
}obj := SomeObject{
Id: 1,
Name: "test"
}
// needed to serialize and deserialize this object
gob.Register(SomeObject{})//set some session values
session.Set("test1", "some test1 value")
session.Set("test2", "some test2 value")
session.Set("test3", obj)
// save the session before quitting or the values will be lost
// session is saved securly as a cookie in the user's browser
err:= session.Save(w)
if err != nil{
log.Println("Session not saved")
}// Read a value out of the session
v1:= session.Get("test1")
fmt.Println(v1)```