session

package
v0.0.0-...-ae40e7c Latest Latest
Warning

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

Go to latest
Published: May 3, 2018 License: MIT Imports: 5 Imported by: 2

Documentation

Overview

Package session 实现了基于内存的session管理功能

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(kind string, creator SessionContainerCreator) error

Register 注册SessionContainer创建器

Types

type Error

type Error string

错误信息

const (
	ErrorInvalidSessionProvider Error = "ErrorInvalidSessionProvider(S10000):无效的Session提供器"
	ErrorInvalidSessionKind     Error = "ErrorInvalidSessionKind(S10010):无效的Session类型(%s)"
)

错误码

func (Error) Error

func (this Error) Error() error

Error 生成error类型

func (Error) Format

func (this Error) Format(data ...interface{}) Error

Format 格式化错误信息并生成新的错误信息

func (Error) String

func (this Error) String() string

String 返回错误字符串描述

type MemSession

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

内存Session,每次操作都会使Session有效时间延长

func (*MemSession) Bool

func (this *MemSession) Bool(key string) (bool, bool)

Bool 获取bool值

func (*MemSession) Dead

func (this *MemSession) Dead() bool

Dead 判断Session是否过期

func (*MemSession) Deadline

func (this *MemSession) Deadline() int

Deadline 获取Session过期时间

func (*MemSession) Delete

func (this *MemSession) Delete(key string)

Delete 删除键

func (*MemSession) Die

func (this *MemSession) Die()

Die 让Session立即过期

func (*MemSession) Float

func (this *MemSession) Float(key string) (float64, bool)

Float 获取浮点值

func (*MemSession) Int

func (this *MemSession) Int(key string) (int, bool)

Int 获取整数值

func (*MemSession) SessionId

func (this *MemSession) SessionId() string

SessionId 返回Session的Id

func (*MemSession) SetBool

func (this *MemSession) SetBool(key string, value bool)

SetBool 设置bool值

func (*MemSession) SetDeadline

func (this *MemSession) SetDeadline(second int)

SetDeadline 设置有效期限

second:从当前时间开始有效的秒数

func (*MemSession) SetFloat

func (this *MemSession) SetFloat(key string, value float64)

SetFloat 设置浮点值

func (*MemSession) SetInt

func (this *MemSession) SetInt(key string, value int)

SetInt 设置整数值

func (*MemSession) SetString

func (this *MemSession) SetString(key string, value string)

SetString 设置字符串

func (*MemSession) SetValue

func (this *MemSession) SetValue(key string, value interface{})

SetValue 设置值

func (*MemSession) String

func (this *MemSession) String(key string) (string, bool)

String 获取字符串

func (*MemSession) Value

func (this *MemSession) Value(key string) (interface{}, bool)

Value 获取值

type MemSessionContainer

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

内存Session容器

func (*MemSessionContainer) Clean

func (this *MemSessionContainer) Clean() int

Clean 清理过期Session 并返回清理的数量

func (*MemSessionContainer) Close

func (this *MemSessionContainer) Close()

Close 关闭SessionProvider,关闭之后将无法使用

func (*MemSessionContainer) Closed

func (this *MemSessionContainer) Closed() bool

Closed 确认当前SessionProvider是否已经关闭

func (*MemSessionContainer) CreateSession

func (this *MemSessionContainer) CreateSession() (Session, bool)

CreateSession 创建Session

func (*MemSessionContainer) Session

func (this *MemSessionContainer) Session(sessionId string) (Session, bool)

Session 获取Session

type Session

type Session interface {
	// SessionId 返回Session的Id
	SessionId() string
	// Value 获取值
	Value(key string) (interface{}, bool)
	// String 获取字符串
	String(key string) (string, bool)
	//  Int 获取整数值
	Int(key string) (int, bool)
	// Bool 获取bool值
	Bool(key string) (bool, bool)
	// Float 获取浮点值
	Float(key string) (float64, bool)
	// SetValue 设置值
	SetValue(key string, value interface{})
	// SetString 设置字符串
	SetString(key string, value string)
	// SetInt 设置整数值
	SetInt(key string, value int)
	// SetBool 设置bool值
	SetBool(key string, value bool)
	// SetFloat 设置浮点值
	SetFloat(key string, value float64)
	// Delete 删除指定键
	Delete(key string)
	// SetDeadline 设置有效期限
	SetDeadline(second int)
	// Deadline 获取过期时间
	Deadline() int
	// Dead 让Session立即过期
	Die()
	// Dead 判断Session是否过期
	Dead() bool
}

Session

type SessionContainer

type SessionContainer interface {
	// CreateSession 创建Session
	CreateSession() (Session, bool)
	// Session 获取Session
	Session(sessionId string) (Session, bool)
	// Close 关闭SessionProvider,关闭之后将无法使用
	Close()
	// Closed 确认当前SessionProvider是否已经关闭
	Closed() bool
}

Session容器

func NewMemSessionContainer

func NewMemSessionContainer(expire int, source string) (SessionContainer, error)

NewMemSessionContainer 创建Session提供器(数据存储在内存中,source参数无效)

func NewSessionContainer

func NewSessionContainer(kind string, expire int, source string) (SessionContainer, error)

NewSessionContainer 创建一个新的Session容器

expire:最大过期时间(秒)

type SessionContainerCreator

type SessionContainerCreator func(expire int, source string) (SessionContainer, error)

SessionContainer创建器

expire:session有效期
source:存储源

Jump to

Keyboard shortcuts

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