-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.go
93 lines (87 loc) · 1.59 KB
/
service.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
82
83
84
85
86
87
88
89
90
91
92
93
package goservice
type CallOpts struct {
}
type Call func(action string, params interface{}, opts ...CallOpts) (interface{}, error)
type Context struct {
RequestId string
TraceParentId string
TraceParentRootId string
ResponseId string
Params interface{}
Meta interface{}
FromService string
FromAction string
FromEvent string
FromNode string
CallingLevel int
Call Call
Service *Service
}
func (c *Context) LogInfo(message string) {
c.Service.Broker.LogInfo(message)
}
func (c *Context) LogWarning(message string) {
c.Service.Broker.LogWarning(message)
}
func (c *Context) LogError(message string) {
c.Service.Broker.LogError(message)
}
type Method int
const (
GET Method = iota + 1
POST
PUT
DELETE
PATCH
HEAD
OPTIONS
)
func (m Method) String() string {
switch m {
case GET:
return "GET"
break
case POST:
return "POST"
break
case PUT:
return "PUT"
break
case DELETE:
return "DELETE"
break
case PATCH:
return "PATCH"
break
case HEAD:
return "HEAD"
break
case OPTIONS:
return "OPTIONS"
break
}
return ""
}
type Rest struct {
Method Method `json:"method" mapstructure:"method"`
Path string `json:"path" mapstructure:"path"`
}
type Action struct {
Name string
Params interface{}
Rest Rest
Handle func(*Context) (interface{}, error)
}
type Event struct {
Name string
Params interface{}
Handle func(*Context)
}
type Service struct {
Name string
Actions []Action
Events []Event
Started func(*Context)
Stoped func(*Context)
Broker *Broker
}