session

package
v1.5.4 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: MIT Imports: 16 Imported by: 11

Documentation

Index

Constants

View Source
const (
	Credential = "Credential"
	Signature  = "Signature"
)
View Source
const (
	HMAC_SECRET_KEY           = "HMAC_SECRET"
	SESSION_TIMEOUT_VALUE_KEY = "SESSION_TIMEOUT_VALUE"
)
View Source
const (
	StatusUpdate = iota
	StatusTerminate
)
View Source
const (

	// InnerRemoteAccessAddr 会话来源地址
	InnerRemoteAccessAddr = "_remoteAccessAddr"
	// InnerUseAgent 会话来源UA
	InnerUseAgent = "_userAgent"
	// account/endpoint 认证方式
	InnerAuthType = "_authType"
	// innserSessionStartTime 会话开始时间
	InnerStartTime = "innerSessionStartTime"

	// AuthExpireTime 会话强制有效期,该有效期通过session Option进行强制设置,与innerExpireTime在使用时,取两者之间最大值为实际会话有效期
	AuthExpireTime = "authExpireTime"
	// Authorization info, from request header
	Authorization = "Authorization"
)
View Source
const (
	SessionToken        = "session_token"
	AuthJWTSession      = "jwt"
	AuthEndpointSession = "endpoint"
)
View Source
const (
	DefaultSessionTimeOutValue = 10 * time.Minute // 10 minute
)

Variables

This section is empty.

Functions

func EncryptEndpoint

func EncryptEndpoint(endpoint *Endpoint) (string, error)

func GetSessionTimeOutValue added in v1.5.4

func GetSessionTimeOutValue() time.Duration

func GetSessionValue added in v1.5.4

func GetSessionValue[T any](session Session, key string) (ret T, ok bool)

func ReadSessionTokenFromCookie added in v1.5.4

func ReadSessionTokenFromCookie(req *http.Request) string

func SignatureEndpoint

func SignatureEndpoint(endpoint string, authToken string) (string, error)

func SignatureJWT

func SignatureJWT(mc jwt.MapClaims) (string, error)

func WriteSessionTokenToCookie added in v1.5.4

func WriteSessionTokenToCookie(res http.ResponseWriter, sessionToken string)

Types

type AuthSecret added in v1.3.69

type AuthSecret struct {
	Endpoint  string `json:"endpoint"`
	AuthToken string `json:"authToken"`
}

type BaseClient

type BaseClient struct {
	// contains filtered or unexported fields
}

func NewBaseClient

func NewBaseClient(serverUrl string) BaseClient

func (*BaseClient) AttachAuthorization

func (s *BaseClient) AttachAuthorization(authorization string)

func (*BaseClient) AttachContext

func (s *BaseClient) AttachContext(ctx Context)

func (*BaseClient) BindAuthSecret added in v1.3.69

func (s *BaseClient) BindAuthSecret(authSecret *AuthSecret)

func (*BaseClient) DetachAuthorization

func (s *BaseClient) DetachAuthorization()

func (*BaseClient) DetachContext

func (s *BaseClient) DetachContext()

func (*BaseClient) GetContextValues

func (s *BaseClient) GetContextValues() url.Values

func (*BaseClient) GetHTTPClient

func (s *BaseClient) GetHTTPClient() *http.Client

func (*BaseClient) GetServerURL

func (s *BaseClient) GetServerURL() string

func (*BaseClient) Release

func (s *BaseClient) Release()

func (*BaseClient) UnBindAuthSecret added in v1.3.69

func (s *BaseClient) UnBindAuthSecret()

type Client

type Client interface {
	GetServerURL() string
	GetHTTPClient() *http.Client

	// Context 通过Header进行传递至服务器
	AttachContext(ctx Context)
	DetachContext()

	AttachAuthorization(authorization string)
	DetachAuthorization()

	// for endpoint
	BindAuthSecret(authSecret *AuthSecret)
	UnBindAuthSecret()

	Release()
}

type Context

type Context interface {
	Decode(req *http.Request)
	Encode(vals url.Values) url.Values
	Get(key string) (string, bool)
	Set(key, value string)
	Remove(key string)
	Clear()
}

Context context info

func NewDefaultHeaderContext added in v1.5.4

func NewDefaultHeaderContext() Context

NewDefaultHeaderContext 创建新的默认会话上下文

type Endpoint

type Endpoint struct {
	Endpoint string         `json:"endpoint"`
	Context  map[string]any `json:"context"`
}

type Observer

type Observer interface {
	ID() string
	OnStatusChange(session Session, status Status)
}

Observer session Observer

type Registry

type Registry interface {
	GetSession(res http.ResponseWriter, req *http.Request) Session
	CountSession(filter util.Filter) int
	Release()
}

Registry 会话仓库

func DefaultRegistry added in v1.5.4

func DefaultRegistry() Registry

DefaultRegistry 创建Session仓库

func NewRegistry added in v1.5.4

func NewRegistry(obSvr Observer) Registry

type Session

type Session interface {
	ID() string
	Signature() (string, error)
	Reset()
	BindObserver(observer Observer)
	UnbindObserver(observer Observer)

	GetString(key string) (string, bool)
	GetInt(key string) (int64, bool)
	GetUint(key string) (uint64, bool)
	GetFloat(key string) (float64, bool)
	GetBool(key string) (bool, bool)
	GetOption(key string) (any, bool)
	SetOption(key string, value any)
	RemoveOption(key string)
	SubmitOptions()
}

Session 会话

type Status

type Status int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL