nano: Index | Files | Directories

package nano

import ""


Package Files

errors.go group.go interface.go options.go


var (
    ErrCloseClosedGroup   = errors.New("close closed group")
    ErrClosedGroup        = errors.New("group closed")
    ErrMemberNotFound     = errors.New("member not found in the group")
    ErrSessionDuplication = errors.New("session has existed in the current group")

Errors that could be occurred during message handling.

var VERSION = "0.5.0"

VERSION returns current nano version

func Listen Uses

func Listen(addr string, opts ...Option)

Listen listens on the TCP network address addr and then calls Serve with handler to handle requests on incoming connections.

func Shutdown Uses

func Shutdown()

Shutdown send a signal to let 'nano' shutdown itself.

type Group Uses

type Group struct {
    // contains filtered or unexported fields

Group represents a session group which used to manage a number of sessions, data send to the group will send to all session in it.

func NewGroup Uses

func NewGroup(n string) *Group

NewGroup returns a new group instance

func (*Group) Add Uses

func (c *Group) Add(session *session.Session) error

Add add session to group

func (*Group) Broadcast Uses

func (c *Group) Broadcast(route string, v interface{}) error

Broadcast push the message(s) to all members

func (*Group) Close Uses

func (c *Group) Close() error

Close destroy group, which will release all resource in the group

func (*Group) Contains Uses

func (c *Group) Contains(uid int64) bool

Contains check whether a UID is contained in current group or not

func (*Group) Count Uses

func (c *Group) Count() int

Count get current member amount in the group

func (*Group) Leave Uses

func (c *Group) Leave(s *session.Session) error

Leave remove specified UID related session from group

func (*Group) LeaveAll Uses

func (c *Group) LeaveAll() error

LeaveAll clear all sessions in the group

func (*Group) Member Uses

func (c *Group) Member(uid int64) (*session.Session, error)

Member returns specified UID's session

func (*Group) Members Uses

func (c *Group) Members() []int64

Members returns all member's UID in current group

func (*Group) Multicast Uses

func (c *Group) Multicast(route string, v interface{}, filter SessionFilter) error

Multicast push the message to the filtered clients

type Option Uses

type Option func(*cluster.Options)

func WithAdvertiseAddr Uses

func WithAdvertiseAddr(addr string, retryInterval ...time.Duration) Option

WithAdvertiseAddr sets the advertise address option, it will be the listen address in master node and an advertise address which cluster member to connect

func WithCheckOriginFunc Uses

func WithCheckOriginFunc(fn func(*http.Request) bool) Option

WithCheckOriginFunc sets the function that check `Origin` in http headers

func WithClientAddr Uses

func WithClientAddr(addr string) Option

WithMemberAddr sets the listen address which is used to establish connection between cluster members. Will select an available port automatically if no member address setting and panic if no available port

func WithComponents Uses

func WithComponents(components *component.Components) Option

WithComponents sets the Components

func WithDebugMode Uses

func WithDebugMode() Option

WithDebugMode let 'nano' to run under Debug mode.

func WithDictionary Uses

func WithDictionary(dict map[string]uint16) Option

SetDictionary sets routes map

func WithGrpcOptions Uses

func WithGrpcOptions(opts ...grpc.DialOption) Option

WithGrpcOptions sets the grpc dial options

func WithHeartbeatInterval Uses

func WithHeartbeatInterval(d time.Duration) Option

WithHeartbeatInterval sets Heartbeat time interval

func WithIsWebsocket Uses

func WithIsWebsocket(enableWs bool) Option

WithIsWebsocket indicates whether current node WebSocket is enabled

func WithLabel Uses

func WithLabel(label string) Option

WithLabel sets the current node label in cluster

func WithLogger Uses

func WithLogger(l log.Logger) Option

WithLogger overrides the default logger

func WithMaster Uses

func WithMaster() Option

WithMaster sets the option to indicate whether the current node is master node

func WithPipeline Uses

func WithPipeline(pipeline pipeline.Pipeline) Option

func WithSerializer Uses

func WithSerializer(serializer serialize.Serializer) Option

WithSerializer customizes application serializer, which automatically Marshal and UnMarshal handler payload

func WithTSLConfig Uses

func WithTSLConfig(certificate, key string) Option

WithTSLConfig sets the `key` and `certificate` of TSL

func WithTimerPrecision Uses

func WithTimerPrecision(precision time.Duration) Option

SetTimerPrecision sets the ticker precision, and time precision can not less than a Millisecond, and can not change after application running. The default precision is time.Second

func WithWSPath Uses

func WithWSPath(path string) Option

type SessionFilter Uses

type SessionFilter func(*session.Session) bool

SessionFilter represents a filter which was used to filter session when Multicast, the session will receive the message while filter returns true.


cluster/clusterpbPackage clusterpb is a generated protocol buffer package.
internal/envenv represents the environment of the current process, includes work path and config path etc.

Package nano imports 22 packages (graph). Updated 2020-10-10. Refresh now. Tools for package owners.