Documentation
¶
Overview ¶
Package server is an interface for a micro server
Index ¶
- Variables
- type Message
- type Option
- func Address(a string) Option
- func Advertise(a string) Option
- func ID(id string) Option
- func Metadata(md map[string]string) Option
- func Name(n string) Option
- func RegisterInterval(t time.Duration) Option
- func RegisterTTL(t time.Duration) Option
- func Registry(r registry.Registry) Option
- func Version(v string) Option
- func Wait(b bool) Option
- type Options
- type Request
- type Server
- type Stream
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // DefaultAddress DefaultAddress DefaultAddress = ":0" // DefaultName DefaultName DefaultName = "go-server" // DefaultVersion DefaultVersion DefaultVersion = "1.0.0" // DefaultID DefaultID DefaultID = uuid.NewUUID().String() )
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Options)
Option Option
func RegisterInterval ¶
RegisterInterval specifies the interval on which to re-register
func RegisterTTL ¶
RegisterTTL Register the service with a TTL
type Options ¶
type Options struct {
Registry registry.Registry
Metadata map[string]string
Name string
Address string // use host:port nats_server.addr 不重要
Advertise string // use host:port (优先) 不重要
ID string
Version string // module的版本
RegisterInterval time.Duration
RegisterTTL time.Duration
// Other options for implementations of the interface
// can be stored in a context
Context context.Context
}
Options Options
type Request ¶
type Request interface {
Service() string
Method() string
ContentType() string
Request() any
// indicates whether the request will be streamed
Stream() bool
}
Request Request
type Server ¶
type Server interface {
ID() string // 模块服务ID
Options() Options
UpdMetadata(key, val string) // 更新元数据(正常需要等到下次注册时生效,如果要立即生效还需要调用ServiceRegister)
OnInit(module app.IModule, settings *conf.ModuleSettings) error
OnDestroy() error
Register(id string, f any) // 注册RPC方法
RegisterGO(id string, f any) // 注册RPC方法
SetListener(listener mqrpc.RPCListener)
ServiceRegister() error // 向Registry注册自己
ServiceDeregister() error // 向Registry注销自己
Start() error
Stop() error
String() string
}
Server Server
type Stream ¶
type Stream interface {
Context() context.Context
Request() Request
Send(any) error
Recv(any) error
Error() error
Close() error
}
Stream represents a stream established with a client. A stream can be bidirectional which is indicated by the request. The last error will be left in Error(). EOF indicated end of the stream.
Click to show internal directories.
Click to hide internal directories.