session

package
v1.1.72 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AfterInited added in v1.0.0

func AfterInited(f func(*Session))

AfterInited set a func that will be called after session inited

func BeforeClosed added in v1.0.0

func BeforeClosed(f func(*Session))

BeforeClosed set a func that will be called before session closed

func Closed added in v1.0.0

func Closed(s *Session)

Closed call all funcs that was registered by OnClosed

func Inited added in v1.0.0

func Inited(s *Session)

Inited call all funcs that was registered by OnInited

func OnClosed added in v1.0.0

func OnClosed(f func(*Session))

OnClosed set a func that will be called on session closed

func OnInited added in v1.0.0

func OnInited(f func(*Session))

OnInited set a func that will be called on session inited

func SafeCall added in v1.1.66

func SafeCall(f func())

Types

type EventCallback added in v1.0.0

type EventCallback func(*Session, ...interface{})

EventCallback is the func called after event trigged

type KernelSession added in v1.0.1

type KernelSession struct {
	sync.RWMutex // protect data

	VersionBound bool // session version bound

	MaxMid   atomic.Uint64
	DataType atomic.Uint32
	// 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 NewKernelSession added in v1.0.1

func NewKernelSession(entity NetworkEntity, id uint64) *KernelSession

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

func (*KernelSession) AddRemoteSessionAddr added in v1.1.1

func (s *KernelSession) AddRemoteSessionAddr(addr string)

func (*KernelSession) Deserialize added in v1.1.38

func (s *KernelSession) Deserialize(data []byte, v interface{}) error

func (*KernelSession) ID added in v1.1.67

func (s *KernelSession) ID() uint64

ID returns the session id

func (*KernelSession) NetworkEntity added in v1.0.1

func (s *KernelSession) NetworkEntity() NetworkEntity

NetworkEntity returns the low-level network agent object

func (*KernelSession) Push added in v1.0.1

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

Push message to client

func (*KernelSession) RPC added in v1.0.1

func (s *KernelSession) RPC(mid uint64, route string, v interface{}) error

RPC sends message to remote server

func (*KernelSession) RemoteSessionAddrs added in v1.1.1

func (s *KernelSession) RemoteSessionAddrs() []string

func (*KernelSession) Response added in v1.0.1

func (s *KernelSession) Response(mid uint64, route string, v interface{}) error

Response message to client

func (*KernelSession) Router added in v1.0.1

func (s *KernelSession) Router() *Router

Router returns the service router

func (*KernelSession) Serialize added in v1.1.38

func (s *KernelSession) Serialize(v interface{}) ([]byte, error)

func (*KernelSession) UID added in v1.1.67

func (s *KernelSession) UID() int64

UID returns uid that bind to current session

type NetworkEntity

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

NetworkEntity represent low-level network instance

type Router added in v1.0.0

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

Router is used to select remote service address

func (*Router) Bind added in v1.0.0

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

Bind bound an address to remote service

func (*Router) Find added in v1.0.0

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

Find finds the address corresponding a remote service

type Session

type Session struct {
	*KernelSession
	// contains filtered or unexported fields
}

func Context added in v1.0.1

func Context(s *Session, lastMid uint64) *Session

func New

func New(entity NetworkEntity, id uint64) *Session

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

func NewSession added in v1.1.68

func NewSession(s *KernelSession) *Session

func (*Session) BindBranch added in v1.0.1

func (s *Session) BindBranch(branch uint32)

func (*Session) BindShortVer added in v1.0.0

func (s *Session) BindShortVer(shortVer uint32)

func (*Session) BindUID added in v1.0.0

func (s *Session) BindUID(uid int64)

Bind bind UID to current session

func (*Session) BindVersion added in v1.0.0

func (s *Session) BindVersion(version string)

func (*Session) Bool added in v1.0.0

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

Bool returns the value associated with the key as a boolean.

func (*Session) Branch added in v1.0.1

func (s *Session) Branch() uint32

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() uint64

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 added in v1.0.0

func (s *Session) LastMid() uint64

func (*Session) NID added in v1.1.21

func (s *Session) NID() uint64

func (*Session) On added in v1.0.0

func (s *Session) On(ev string, f func(s *Session))

On is to register callback on events

func (*Session) OnData added in v1.0.0

func (s *Session) OnData(ev string, f func(s *Session, i ...interface{}))

OnData is to register callback on events

func (*Session) RPC added in v1.0.0

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

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(route string, v interface{}) error

func (*Session) Restore

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

Restore session state after reconnect

func (*Session) SID added in v1.0.1

func (s *Session) SID() uint64

func (*Session) Set

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

Set associates value with the key in session storage

func (*Session) ShortVer added in v1.0.0

func (s *Session) ShortVer() uint32

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) Trigger added in v1.0.0

func (s *Session) Trigger(ev string, i ...interface{})

Trigger is to trigger an event with args

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{}.

func (*Session) Version added in v1.0.0

func (s *Session) Version() string

Jump to

Keyboard shortcuts

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