-
Notifications
You must be signed in to change notification settings - Fork 584
/
server.go
78 lines (70 loc) · 1.75 KB
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Package server is an interface for a micro server
package server
import (
"context"
"github.com/liangdas/mqant/conf"
"github.com/liangdas/mqant/module"
"github.com/liangdas/mqant/rpc"
"github.com/pborman/uuid"
)
// Server Server
type Server interface {
Options() Options
OnInit(module module.Module, app module.App, settings *conf.ModuleSettings) error
Init(...Option) error
SetListener(listener mqrpc.RPCListener)
Register(id string, f interface{})
RegisterGO(id string, f interface{})
ServiceRegister() error
ServiceDeregister() error
Start() error
Stop() error
OnDestroy() error
String() string
ID() string
// Deprecated: 因为命名规范问题函数将废弃,请用ID代替
Id() string
}
// Message RPC消息头
type Message interface {
Topic() string
Payload() interface{}
ContentType() string
}
// Request Request
type Request interface {
Service() string
Method() string
ContentType() string
Request() interface{}
// indicates whether the request will be streamed
Stream() bool
}
// 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.
type Stream interface {
Context() context.Context
Request() Request
Send(interface{}) error
Recv(interface{}) error
Error() error
Close() error
}
// Option Option
type Option func(*Options)
var (
// DefaultAddress DefaultAddress
DefaultAddress = ":0"
// DefaultName DefaultName
DefaultName = "go-server"
// DefaultVersion DefaultVersion
DefaultVersion = "1.0.0"
// DefaultID DefaultID
DefaultID = uuid.NewUUID().String()
)
// NewServer returns a new server with options passed in
func NewServer(opt ...Option) Server {
return newRPCServer(opt...)
}