server

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRegisterMethods

func GetRegisterMethods(name string) ([]string, error)

func NewService

func NewService(opts ...Option) *service

func Register

func Register(rcvr any, name string, opts ...Option) error

Register publishes uses the provided name in the dispatcher the set of methods of the receiver value that satisfy the following conditions:

  • exported method of exported type
  • two arguments, both of exported type
  • the second argument is a pointer
  • one return value, of type error

It returns an error if the receiver is not an exported type or has no suitable methods. It also logs the error using package log. The client accesses each method using a string of the form "Type.Method", where Type is the receiver's concrete type.

func SetRecoveryHandler

func SetRecoveryHandler(handle func(string, any))

By default, it will print the time and stack information of the error

Types

type AccessHandle

type AccessHandle func(ctx *SkynetContext, sname, method string, cost time.Duration, err error)

type Dispatcher

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

dispatcher represents an RPC disoatcher.

func GetDispatcher

func GetDispatcher() *Dispatcher

func (*Dispatcher) DispatchReq

func (disp *Dispatcher) DispatchReq(sname string, methodName string, data []byte, isPush bool) ([]byte, error)

func (*Dispatcher) GetService added in v1.1.0

func (disp *Dispatcher) GetService(sname string) *service

type Gate

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

func NewGate

func NewGate(address string, ops ...netpoll.Option) (*Gate, error)

Open open address with netpoll.Option opts disable WithOnPrepare and WithOnConnect

func (*Gate) Close

func (gate *Gate) Close(timeout time.Duration)

Close is used to graceful exit. It will close all idle connections on the server, but will not change the underlying pollers.

func (*Gate) Start

func (gate *Gate) Start() error

Serve registers a listener and runs blockingly to provide services, including listening to ports, accepting connections and processing trans data. When an exception occurs or Shutdown is invoked, Serve will return an error which describes the specific reason.

type GateAgent

type GateAgent struct {
	Reader chan netpoll.Reader // use for reader socket data
	// contains filtered or unexported fields
}

func NewGateAgent

func NewGateAgent(conn netpoll.Connection) *GateAgent

func (*GateAgent) Dispatch

func (agent *GateAgent) Dispatch(req *codec.ReqPack)

func (*GateAgent) ResponseErr

func (agent *GateAgent) ResponseErr(session uint32, err error)

func (*GateAgent) ResponseOk

func (agent *GateAgent) ResponseOk(session uint32, payload []byte)

func (*GateAgent) Start

func (agent *GateAgent) Start()

type Option

type Option func(*Options)

func WithAccessLog

func WithAccessLog(hdl AccessHandle) Option

func WithMonitorInterval added in v1.1.0

func WithMonitorInterval(interval time.Duration) Option

Synchronous mode monitor message maybe in endlessloop interval. Default 5 time.Seconds. must greate than 1 time.Seconds

func WithPayloadCodec

func WithPayloadCodec(c codec.PayloadCodec) Option

func WithSyncDispatch added in v1.1.0

func WithSyncDispatch() Option

Default Message dispatch mod is async. The order of messages is not guaranteed. SyncDispatch guarenteed order of messages. But be careful of endlessloop

type Options

type Options struct {
	PayloadCodec    codec.PayloadCodec
	AccessHdle      AccessHandle
	SyncDisptch     bool
	MonitorInterval time.Duration
}

type SkynetContext

type SkynetContext struct {
	context.Context
	// contains filtered or unexported fields
}

func NewSkynetContext

func NewSkynetContext(ctx context.Context) *SkynetContext

Jump to

Keyboard shortcuts

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