This repository has been archived by the owner on Sep 24, 2022. It is now read-only.
forked from carousell/Orion
/
types.go
81 lines (70 loc) · 2.73 KB
/
types.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
79
80
81
package orion
import (
"time"
"github.com/go-orion/Orion/orion/handlers"
"google.golang.org/grpc"
)
const (
//ProtoGenVersion1_0 is the version of protoc-gen-orion plugin compatible with current code base
ProtoGenVersion1_0 = true
//BANNER is the orion banner text
BANNER = `
___ ____ ___ ___ _ _
/ _ \| _ \|_ _/ _ \| \ | |
| | | | |_) || | | | | \| |
| |_| | _ < | | |_| | |\ |
\___/|_| \_\___\___/|_| \_|
`
)
// Server is the interface that needs to be implemented by any orion server
// 'DefaultServerImpl' should be enough for most users.
type Server interface {
//Start starts the orion server, this is non blocking call
Start()
//RegisterService registers the service to origin server
RegisterService(sd *grpc.ServiceDesc, sf interface{}) error
//Wait waits for the Server loop to exit
Wait() error
//Stop stops the Server
Stop(timeout time.Duration) error
//GetOrionConfig returns current orion config
GetOrionConfig() Config
//GetConfig returns current config as parsed from the file/defaults
GetConfig() map[string]interface{}
//AddInitializers adds the initializers to orion server
AddInitializers(ins ...Initializer)
}
//Initializer is the interface needed to be implemented by custom initializers
type Initializer interface {
Init(svr Server) error
ReInit(svr Server) error
}
// ServiceFactory is the interface that need to be implemented by client that provides with a new service object
type ServiceFactory interface {
// NewService function receives the server object for which service has to be initialized
NewService(Server) interface{}
//DisposeService function disposes the service object
DisposeService(svc interface{})
}
// FactoryParams are the parameters used by the ServiceFactoryV2
type FactoryParams struct {
// ServiceName contains the proto service name
ServiceName string
// Version is a counter that is incremented every time a new service object is requested
// NOTE: version might rollover in long running services
Version uint64
}
// ServiceFactoryV2 is the interface that needs to be implemented by client that provides a new service object for multiple services
// this allows a single struct to implement multiple services
type ServiceFactoryV2 interface {
// NewService function receives the server object for which service has to be initialized
NewService(svr Server, params FactoryParams) interface{}
//DisposeService function disposes the service object
DisposeService(svc interface{}, params FactoryParams)
}
//Encoder is the function type needed for request encoders
type Encoder = handlers.Encoder
//Decoder is the function type needed for request decoders
type Decoder = handlers.Decoder
//HTTPHandler is the http interceptor
type HTTPHandler = handlers.HTTPHandler