Movatterモバイル変換


[0]ホーム

URL:


nssession

packagemodule
v0.0.0-...-8b6a2e2Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2025 License:Apache-2.0Imports:8Imported by:0

Details

Repository

github.com/no-src/nssession

Links

README

nssession

BuildLicenseGo ReferenceGo Report CardcodecovRelease

Installation

go get -u github.com/no-src/nssession

Quick 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

func InitDefaultConfig(c *Config)error

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

funcDefault

func Default(req *http.Request, writerhttp.ResponseWriter) (NSSession,error)

Default get the session with the global session config

funcNew

func New(c *Config, req *http.Request, writerhttp.ResponseWriter) (NSSession,error)

New get the session with the specified session config

Source Files

View all Source files

Directories

PathSynopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp