service

package
v1.1.15 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidRelayMessage         = errors.New("invalid relay message")
	ErrInvalidRelayPassthroughType = errors.New("invalid relay passthrough type")
)
View Source
var (
	LinkRules []MatchRule // 互联发现规则
)

Functions

func AddRemoteService

func AddRemoteService(ses cellnet.Session, svcid, name string)

func ConnectDiscovery

func ConnectDiscovery()

连接到服务发现, 建议在service.Init后, 以及服务器逻辑开始前调用

func DiscoveryService

func DiscoveryService(tgtSvcName string, opt DiscoveryOption, peerCreator func(MultiPeer, *discovery.ServiceDesc)) cellnet.Peer

发现一个服务,服务可能拥有多个地址,每个地址返回时,创建一个connector并开启 DiscoveryService返回值返回持有多个Peer的peer, 判断Peer的IsReady可以得到所有连接准备好的状态

func GetCommtype added in v1.0.7

func GetCommtype() string

func GetDiscoveryAddr

func GetDiscoveryAddr() string

func GetLocalSvcID

func GetLocalSvcID() string

获得本进程的服务id

func GetPassThrough

func GetPassThrough(ev cellnet.Event, ptrList ...interface{}) error

获取Event中relay的透传数据

func GetProcName

func GetProcName() string

获取当前服务进程名称

func GetRemoteService

func GetRemoteService(svcid string) cellnet.Session

根据svcid获取远程服务的会话

func GetSvcGroup

func GetSvcGroup() string

func GetSvcIndex

func GetSvcIndex() string

func GetWANIP

func GetWANIP() string

获取外网IP

func Init

func Init(name string)

func InitServerConfig added in v1.0.8

func InitServerConfig(serviceConf map[string]string)

func LogParameter

func LogParameter()

func MakeLocalSvcID

func MakeLocalSvcID(svcName string) string

构造指定服务的ID

func MakeSvcID

func MakeSvcID(svcName string, svcIndex int, svcGroup string) string

构造服务ID

func ParseSvcID

func ParseSvcID(svcid string) (svcName string, svcIndex int, svcGroup string, err error)

func QueryService

func QueryService(svcName string, filterList ...FilterFunc) (ret interface{})

根据给定的查询服务名,将结果经过各种过滤器处理后输出

func QueryServiceEx

func QueryServiceEx(svcName string, opt QueryServiceOption, filterList ...FilterFunc) (ret interface{})

func Register

func Register(p cellnet.Peer, options ...interface{}) *discovery.ServiceDesc

将Acceptor注册到服务发现,IP自动取本地IP

func RemoveRemoteService

func RemoveRemoteService(ses cellnet.Session)

func Reply

func Reply(ev cellnet.Event, msg interface{})

回复event来源一个消息

func SetRemoteServiceNotify

func SetRemoteServiceNotify(mode string, callback NotifyFunc)

设置服务的通知

func Unregister

func Unregister(p cellnet.Peer)

解除peer注册

func VisitRemoteService

func VisitRemoteService(callback func(ses cellnet.Session, ctx *RemoteServiceContext) bool)

遍历远程服务(已经连接到本进程)

func WaitExitSignal

func WaitExitSignal()

Types

type DiscoveryOption

type DiscoveryOption struct {
	Rules         []MatchRule
	MaxCount      int    // 连接数,默认发起多条连接
	MatchSvcGroup string // 空时,匹配所有同类服务,否则找指定组的服务
}

type FilterFunc

type FilterFunc func(*discovery.ServiceDesc) interface{}

返回值含义: 1. true等效于QueryServiceOp_NextFilter,转到下一个内层循环 2. false等效于QueryServiceOp_NextDesc, 转到下一个外层循环 3. QueryServiceOp_End: 终止所有遍历循环 4. Filter中将类型转为QueryResult,则在QueryService函数返回

func Filter_MatchRule

func Filter_MatchRule(rules []MatchRule) FilterFunc

匹配指定的规则,一般由命令行指定

func Filter_MatchSvcGroup

func Filter_MatchSvcGroup(svcGroup string) FilterFunc

匹配指定的服务组,服务组空时,匹配所有

func Filter_MatchSvcID

func Filter_MatchSvcID(svcid string) FilterFunc

匹配指定的服务ID

type MatchRule

type MatchRule struct {
	Target string
}

func ParseMatchRule

func ParseMatchRule(rule string) (ret []MatchRule)

type MultiPeer

type MultiPeer interface {
	GetPeers() []cellnet.Peer

	cellnet.ContextSet

	AddPeer(sd *discovery.ServiceDesc, p cellnet.Peer)
}

一类服务发起多个连接(不是同一地址), 比如 login1 login2

type NotifyFunc

type NotifyFunc func(ctx *RemoteServiceContext, ses cellnet.Session)

type QueryResult

type QueryResult interface{}

type QueryServiceOp

type QueryServiceOp int
const (
	QueryServiceOp_NextFilter QueryServiceOp = iota
	QueryServiceOp_NextDesc
	QueryServiceOp_End
)

type QueryServiceOption

type QueryServiceOption struct {
	Sort bool
}

type RemoteServiceContext

type RemoteServiceContext struct {
	Name  string
	SvcID string
}

func SessionToContext

func SessionToContext(ses cellnet.Session) *RemoteServiceContext

取得其他服务器的会话对应的上下文

type ServiceIdentifyACK

type ServiceIdentifyACK struct {
	SvcName string
	SvcID   string
}

func (*ServiceIdentifyACK) String

func (self *ServiceIdentifyACK) String() string

type ServiceMeta

type ServiceMeta map[string]string

type SvcEventHooker

type SvcEventHooker struct {
}

服务互联消息处理

func (SvcEventHooker) OnInboundEvent

func (SvcEventHooker) OnInboundEvent(inputEvent cellnet.Event) (outputEvent cellnet.Event)

func (SvcEventHooker) OnOutboundEvent

func (SvcEventHooker) OnOutboundEvent(inputEvent cellnet.Event) (outputEvent cellnet.Event)

Jump to

Keyboard shortcuts

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