Documentation
¶
Index ¶
- Constants
- Variables
- func DateTime() string
- func Now() time.Time
- func NowString() string
- func StartClock()
- func StopClock()
- func WallClock() *datetime.Clock
- type Endpoint
- type EndpointFlag
- type EndpointMap
- func (e *EndpointMap) Add(node NodeID, endpoint Endpoint)
- func (e *EndpointMap) Delete(node NodeID) bool
- func (e *EndpointMap) Get(node NodeID) Endpoint
- func (e *EndpointMap) List() []Endpoint
- func (e *EndpointMap) Range(f func(Endpoint) bool)
- func (e *EndpointMap) Reset()
- func (e *EndpointMap) Size() int
- type IPacket
- type MessageEndpoint
- type NodeID
- type NodeIDSet
- type PacketFlag
- type PacketHandler
- type PacketType
- type Service
- type ServiceContext
- func (c *ServiceContext) Close()
- func (c *ServiceContext) InboundQueue() chan<- IPacket
- func (c *ServiceContext) InitRegistrar(hostAddr, namespace string) error
- func (c *ServiceContext) Instance() Service
- func (c *ServiceContext) MessageQueue() <-chan IPacket
- func (c *ServiceContext) Registrar() *discovery.Client
- func (c *ServiceContext) RunID() string
- func (c *ServiceContext) Send(pkt IPacket)
- func (c *ServiceContext) WaitDone() <-chan struct{}
- func (c *ServiceContext) WorkCtx() context.Context
Constants ¶
View Source
const ( SERVICE_ALL = 0xFF INSTANCE_ALL = 0xFFFF )
View Source
const ( NodeServiceShift = 16 NodeServiceMask = 0xFF00FFFF NodeInstanceMask = 0xFFFF0000 NodeTypeShift = 31 )
View Source
const VERSION = "0.1.6"
Variables ¶
View Source
var (
ClockEpoch int64 = 1577836800 // 2020-01-01 00:00:00 UTC
)
Functions ¶
Types ¶
type Endpoint ¶
type Endpoint interface {
MessageEndpoint
RawConn() net.Conn
Stats() *stats.Stats
Go(EndpointFlag)
// 加密解密
SetEncryptPair(cipher.BlockCryptor, cipher.BlockCryptor)
}
网络连接端点
type EndpointFlag ¶
type EndpointFlag uint32
const ( EndpointReader EndpointFlag = 0x01 EndpointWriter EndpointFlag = 0x02 EndpointReadWriter EndpointFlag = 0x03 )
type EndpointMap ¶
线程安全的endpoint map
func NewEndpointMap ¶
func NewEndpointMap() *EndpointMap
func (*EndpointMap) Add ¶
func (e *EndpointMap) Add(node NodeID, endpoint Endpoint)
func (*EndpointMap) Delete ¶
func (e *EndpointMap) Delete(node NodeID) bool
func (*EndpointMap) Get ¶
func (e *EndpointMap) Get(node NodeID) Endpoint
func (*EndpointMap) List ¶
func (e *EndpointMap) List() []Endpoint
func (*EndpointMap) Range ¶
func (e *EndpointMap) Range(f func(Endpoint) bool)
func (*EndpointMap) Reset ¶
func (e *EndpointMap) Reset()
func (*EndpointMap) Size ¶
func (e *EndpointMap) Size() int
type IPacket ¶
type IPacket interface {
Command() int32
SetCommand(int32)
Seq() uint16
SetSeq(uint16)
Type() PacketType
SetType(PacketType)
Flag() PacketFlag
SetFlag(PacketFlag)
Errno() int32
SetErrno(ec int32)
Node() NodeID
SetNode(NodeID)
Refers() []NodeID
SetRefers([]NodeID)
AddRefers(...NodeID)
Endpoint() MessageEndpoint
SetEndpoint(MessageEndpoint)
Clone() IPacket
Body() interface{}
SetBody(v interface{})
BodyToInt() int64
BodyToFloat() float64
BodyToString() string
BodyToBytes() []byte
DecodeTo(msg proto.Message) error
Decode() error
Reply(command int32, body interface{}) error
ReplyMsg(ack proto.Message) error
Refuse(errno int32) error
RefuseWith(command, errno int32) error
}
定义应用层消息接口
type MessageEndpoint ¶
type NodeID ¶
type NodeID uint32
节点号
func MakeNodeID ¶
func MustParseNodeID ¶
func (NodeID) IsTypeBackend ¶
type PacketFlag ¶
type PacketFlag uint8
消息标志位
const ( PFlagCompressed PacketFlag = 0x01 // 压缩 PFlagEncrypted PacketFlag = 0x02 // 加密 PFlagError PacketFlag = 0x10 // 错误标记 PFlagRpc PacketFlag = 0x20 // RPC标记 )
type PacketHandler ¶
type PacketType ¶
type PacketType int8
消息编码类型
const ( PTypePacket PacketType = 0 // 应用消息 PTypeRoute PacketType = 1 // 路由消息 PTypeMulticast PacketType = 2 // 组播消息 )
type Service ¶
type Service interface {
Type() uint8
Name() string
NodeID() NodeID
SetNodeID(id NodeID)
Context() *ServiceContext
Init(*ServiceContext) error
Startup() error
}
定义应用层服务接口
type ServiceContext ¶
type ServiceContext struct {
// contains filtered or unexported fields
}
服务的上下文
func NewServiceContext ¶
func NewServiceContext(ctx context.Context, srv Service, queueSize int) *ServiceContext
func (*ServiceContext) Close ¶
func (c *ServiceContext) Close()
func (*ServiceContext) InboundQueue ¶ added in v0.1.6
func (c *ServiceContext) InboundQueue() chan<- IPacket
消息队列,仅接收
func (*ServiceContext) InitRegistrar ¶ added in v0.1.5
func (c *ServiceContext) InitRegistrar(hostAddr, namespace string) error
func (*ServiceContext) Instance ¶ added in v0.1.2
func (c *ServiceContext) Instance() Service
service实例
func (*ServiceContext) MessageQueue ¶
func (c *ServiceContext) MessageQueue() <-chan IPacket
消息队列,仅消费
func (*ServiceContext) Registrar ¶ added in v0.1.5
func (c *ServiceContext) Registrar() *discovery.Client
服务注册器
func (*ServiceContext) Send ¶ added in v0.1.5
func (c *ServiceContext) Send(pkt IPacket)
投递一条消息到context
func (*ServiceContext) WaitDone ¶ added in v0.1.2
func (c *ServiceContext) WaitDone() <-chan struct{}
等待close完成
func (*ServiceContext) WorkCtx ¶ added in v0.1.4
func (c *ServiceContext) WorkCtx() context.Context
业务context
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
x
|
|
|
uuid
This package provides immutable UUID structs and the functions NewV3, NewV4, NewV5 and Parse() for generating versions 3, 4 and 5 UUIDs as specified in RFC 4122.
|
This package provides immutable UUID structs and the functions NewV3, NewV4, NewV5 and Parse() for generating versions 3, 4 and 5 UUIDs as specified in RFC 4122. |
Click to show internal directories.
Click to hide internal directories.