nssession
packagemodule v0.0.0-...-8b6a2e2
Go to latest Published: Sep 2, 2025 License:Apache-2.0
Opens a new window with list of versions in this module.
Latest LatestThis package is not in the latest version of its module.
Opens a new window with license information.
Imports:8 Opens a new window with list of imports.
Imported by:0 Opens a new window with list of known importers.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
README¶
nssession
Installation
go get -u github.com/no-src/nssessionQuick Start
package mainimport ("net/http""time""github.com/no-src/log""github.com/no-src/nssession""github.com/no-src/nssession/store""github.com/no-src/nssession/store/memory")func main() {// initial default session configc := &nssession.Config{Connection: "memory:",Expiration: time.Hour,Store: store.NewStore(memory.Driver),}err := nssession.InitDefaultConfig(c)if err != nil {log.Error(err, "init the default config error")return}http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {// get session componentsession, err := nssession.Default(request, writer)if err != nil {log.Error(err, "get session component error")return}// set session datak := "hello"var v stringerr = session.Set(k, "world")if err != nil {log.Error(err, "set session data error")return}// get session dataerr = session.Get(k, &v)if err != nil {log.Error(err, "get session data error")return}log.Info("get the session data success, k=%s v=%s", k, v)// remove session dataerr = session.Remove(k)if err != nil {log.Error(err, "remove session data error")return}// clear all session data for the current sessionerr = session.Clear()if err != nil {log.Error(err, "clear session data error")return}})http.ListenAndServe(":8080", nil)}
Documentation¶
Index¶
Constants¶
This section is empty.
Variables¶
View Source
var (// DefaultCookieName the default cookie name for sessionDefaultCookieName = "ns-session-id"// DefaultSessionPrefix the default session prefix for session storeDefaultSessionPrefix = "session")
View Source
var ErrNil =errors.New("nssession: nil")ErrNil get nil data
Functions¶
funcInitDefaultConfig¶
InitDefaultConfig initial the default global session config
Types¶
typeConfig¶
type Config struct {// Connection the connection string of the sessionConnectionstring// Expiration the expiration time of the sessionExpirationtime.Duration// SessionPrefix the session prefix for session storeSessionPrefixstring// Store the session store componentStorestore.Store// Cookie the settings of the cookieCookieCookie}Config the configuration of session
typeCookie¶
type Cookie struct {// Name the cookie name for sessionNamestring// Path set the Path property of the cookiePathstring// Domain set the Domain property of the cookieDomainstring// Expires set the Expires property of the cookieExpirestime.Time// MaxAge set the Max-Age property of the cookieMaxAgeint// Secure set the Secure property of the cookieSecurebool// SameSite set the SameSite property of the cookieSameSitehttp.SameSite}Cookie the settings of the cookie
typeNSSession¶
type NSSession interface {// ID returns the session idID()string// Get get cache data by keyGet(kstring, vany)error// Set set new cache dataSet(kstring, vany)error// Remove remove the specified keyRemove(kstring)error// Clear remove all the key of current sessionClear()error}NSSession the session operation interface
Click to show internal directories.
Click to hide internal directories.