/
struct.go
executable file
·180 lines (159 loc) · 5.63 KB
/
struct.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package registry
import "github.com/go-chassis/go-chassis/core/common"
// MicroService struct having full info about micro-service
type MicroService struct {
ServiceID string
AppID string
ServiceName string
Version string
Paths []ServicePath
Environment string
Status string
Level string
Schemas []string
Metadata map[string]string
Framework *Framework
RegisterBy string
Alias string
}
// ServicePath has info about service path and property
type ServicePath struct {
Path string
Property map[string]string
}
// Framework struct having info about micro-service version, name
type Framework struct {
Name string
Version string
}
// MicroServiceInstance struct having full info about micro-service instance
type MicroServiceInstance struct {
InstanceID string
HostName string
ServiceID string
DefaultProtocol string
DefaultEndpoint string
Status string
EndpointsMap map[string]string
Metadata map[string]string
DataCenterInfo *DataCenterInfo
}
func (m *MicroServiceInstance) appID() string { return m.Metadata[common.BuildinTagApp] }
func (m *MicroServiceInstance) version() string { return m.Metadata[common.BuildinTagVersion] }
// Has return whether microservice has tags
func (m *MicroServiceInstance) Has(tags map[string]string) bool {
for k, v := range tags {
if mt, ok := m.Metadata[k]; !ok || mt != v {
return false
}
}
return true
}
// WithAppID add app tag for microservice instance
func (m *MicroServiceInstance) WithAppID(v string) *MicroServiceInstance {
m.Metadata[common.BuildinTagApp] = v
return m
}
//Equal compares 2 instances is same or not
func (m *MicroServiceInstance) Equal(ins *MicroServiceInstance) bool {
if m.InstanceID != ins.InstanceID {
return false
}
if m.ServiceID != ins.ServiceID {
return false
}
return true
}
// MicroServiceDependency is for to represent dependencies of micro-service
type MicroServiceDependency struct {
Consumer *MicroService
Providers []*MicroService
}
// DataCenterInfo represents micro-service data center info
type DataCenterInfo struct {
Name string
Region string
AvailableZone string
}
// SourceInfo represent the consumer service name and metadata.
// it is used in route management
type SourceInfo struct {
Name string
Tags map[string]string
}
// Schema to represents schema info
type Schema struct {
Schema string `json:"schema"`
}
// SchemaContent represents schema contents info
type SchemaContent struct {
Swagger string `yaml:"swagger"`
Info map[string]string `yaml:"info"`
BasePath string `yaml:"basePath"`
Produces []string `yaml:"produces"`
Paths map[string]map[string]MethodInfo `yaml:"paths"`
Definition map[string]Definition `yaml:"definitions"`
}
// SchemaContents represents array of schema contents
type SchemaContents struct {
Schemas []*SchemaContent
}
// MethodInfo represents method info
type MethodInfo struct {
OperationID string `yaml:"operationId"`
Parameters []Parameter `yaml:"parameters"`
Response map[string]Response `yaml:"responses"`
}
// Parameter represents schema parameters
type Parameter struct {
Name string `yaml:"name"`
In string `yaml:"in"`
Required bool `yaml:"required"`
Type string `yaml:"type"`
Format string `yaml:"format"`
Items Item `yaml:"items"`
ColFormat string `yaml:"collectionFormat"`
Schema SchemaValue `yaml:"schema"`
}
// SchemaValue represents additional info of schema
type SchemaValue struct {
Reference string `yaml:"$ref"`
Format string `yaml:"format"`
Title string `yaml:"title"`
Description string `yaml:"description"`
Default string `yaml:"default"`
MultipleOf int `yaml:"multipleOf"`
ExclusiveMaximum int `yaml:"exclusiveMaximum"`
Minimum int `yaml:"minimum"`
ExclusiveMinimum int `yaml:"exclusiveMinimum"`
MaxLength int `yaml:"maxLength"`
MinLength int `yaml:"minLength"`
Pattern int `yaml:"pattern"`
MaxItems int `yaml:"maxItems"`
MinItems int `yaml:"minItems"`
UniqueItems bool `yaml:"uniqueItems"`
MaxProperties int `yaml:"maxProperties"`
MinProperties int `yaml:"minProperties"`
Required bool `yaml:"required"`
Enum []interface{} `yaml:"enum"`
Type string `yaml:"type"`
Items Item `yaml:"items"`
Properties map[string]interface{} `yaml:"properties"`
AdditionalProperties map[string]string `yaml:"additionalProperties"`
}
// Item represents type of the schema
type Item struct {
Type string `yaml:"type"`
XML map[string]interface{} `yaml:"xml"`
}
// Response represents schema response
type Response struct {
Description string `yaml:"description"`
Schema map[string]string `yaml:"schema"`
}
// Definition struct represents types, xjavaclass, properities
type Definition struct {
Types string `yaml:"type"`
XJavaClass string `yaml:"x-java-class"`
Properties map[string]interface{} `yaml:"properties"`
}