session

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 27, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrIllegalUID represents a invalid uid
	ErrIllegalUID = errors.New("illegal uid")
)
View Source
var Lifetime = &lifetime{}

Functions

This section is empty.

Types

type LifetimeHandler

type LifetimeHandler func(*Session)

LifetimeHandler represents a callback that will be called when a session close or session low-level connection broken.

type NetworkEntity

type NetworkEntity interface {
	Push(route string, v interface{}) error
	RPC(route string, v interface{}) error
	LastMid() uint64
	Response(v interface{}) error
	ResponseMid(mid uint64, v interface{}) error
	Close() error
	RemoteAddr() net.Addr
}

NetworkEntity represent low-level network instance

type Router

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

Router is used to select remote service address

func (*Router) Bind

func (r *Router) Bind(service, address string)

Bind bound an address to remote service

func (*Router) Find

func (r *Router) Find(service string) (string, bool)

Find finds the address corresponding a remote service

type Session

type Session struct {
	sync.RWMutex // protect data
	// contains filtered or unexported fields
}

Session represents a client session which could storage temp data during low-level keep connected, all data will be released when the low-level connection was broken. Session instance related to the client will be passed to Handler method as the first parameter.

func New

func New(entity NetworkEntity) *Session

New returns a new session instance a NetworkEntity is a low-level network instance

func (*Session) Bind

func (s *Session) Bind(uid int64) error

Bind UID to current session

func (*Session) Clear

func (s *Session) Clear()

Clear releases all data related to current session

func (*Session) Close

func (s *Session) Close()

Close terminate current session, session related data will not be released, all related data should be Clear explicitly in Session closed callback

func (*Session) Float32

func (s *Session) Float32(key string) float32

Float32 returns the value associated with the key as a float32.

func (*Session) Float64

func (s *Session) Float64(key string) float64

Float64 returns the value associated with the key as a float64.

func (*Session) HasKey

func (s *Session) HasKey(key string) bool

HasKey decides whether a key has associated value

func (*Session) ID

func (s *Session) ID() int64

ID returns the session id

func (*Session) Int

func (s *Session) Int(key string) int

Int returns the value associated with the key as a int.

func (*Session) Int16

func (s *Session) Int16(key string) int16

Int16 returns the value associated with the key as a int16.

func (*Session) Int32

func (s *Session) Int32(key string) int32

Int32 returns the value associated with the key as a int32.

func (*Session) Int64

func (s *Session) Int64(key string) int64

Int64 returns the value associated with the key as a int64.

func (*Session) Int8

func (s *Session) Int8(key string) int8

Int8 returns the value associated with the key as a int8.

func (*Session) LastMid

func (s *Session) LastMid() uint64

LastMid returns the last message id

func (*Session) NetworkEntity

func (s *Session) NetworkEntity() NetworkEntity

NetworkEntity returns the low-level network agent object

func (*Session) Push

func (s *Session) Push(route string, v interface{}) error

Push message to client

func (*Session) RPC

func (s *Session) RPC(route string, v interface{}) error

RPC sends message to remote server

func (*Session) RemoteAddr

func (s *Session) RemoteAddr() net.Addr

RemoteAddr returns the remote network address.

func (*Session) Remove

func (s *Session) Remove(key string)

Remove delete data associated with the key from session storage

func (*Session) Response

func (s *Session) Response(v interface{}) error

Response message to client

func (*Session) ResponseMID

func (s *Session) ResponseMID(mid uint64, v interface{}) error

ResponseMID responses message to client, mid is request message ID

func (*Session) Restore

func (s *Session) Restore(data map[string]interface{})

Restore session state after reconnect

func (*Session) Router

func (s *Session) Router() *Router

Router returns the service router

func (*Session) Set

func (s *Session) Set(key string, value interface{})

Set associates value with the key in session storage

func (*Session) State

func (s *Session) State() map[string]interface{}

State returns all session state

func (*Session) String

func (s *Session) String(key string) string

String returns the value associated with the key as a string.

func (*Session) UID

func (s *Session) UID() int64

UID returns uid that bind to current session

func (*Session) Uint

func (s *Session) Uint(key string) uint

Uint returns the value associated with the key as a uint.

func (*Session) Uint16

func (s *Session) Uint16(key string) uint16

Uint16 returns the value associated with the key as a uint16.

func (*Session) Uint32

func (s *Session) Uint32(key string) uint32

Uint32 returns the value associated with the key as a uint32.

func (*Session) Uint64

func (s *Session) Uint64(key string) uint64

Uint64 returns the value associated with the key as a uint64.

func (*Session) Uint8

func (s *Session) Uint8(key string) uint8

Uint8 returns the value associated with the key as a uint8.

func (*Session) Value

func (s *Session) Value(key string) interface{}

Value returns the value associated with the key as a interface{}.

Jump to

Keyboard shortcuts

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