/
endpoint.go
138 lines (120 loc) · 3.64 KB
/
endpoint.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
//
// Last.Backend LLC CONFIDENTIAL
// __________________
//
// [2014] - [2018] Last.Backend LLC
// All Rights Reserved.
//
// NOTICE: All information contained herein is, and remains
// the property of Last.Backend LLC and its suppliers,
// if any. The intellectual and technical concepts contained
// herein are proprietary to Last.Backend LLC
// and its suppliers and may be covered by Russian Federation and Foreign Patents,
// patents in process, and are protected by trade secret or copyright law.
// Dissemination of this information or reproduction of this material
// is strictly forbidden unless prior written permission is obtained
// from Last.Backend LLC.
//
package types
import "fmt"
const (
// EndpointSpecRouteStrategyRR - round robin balancing strategy type
EndpointSpecRouteStrategyRR = "rr"
// EndpointSpecBindStrategyDefault - default scheduling endpoint across all nodes
EndpointSpecBindStrategyDefault = "default"
)
// swagger:ignore
// Endpoint - service endpoint
type Endpoint struct {
Runtime
Meta EndpointMeta `json:"meta"`
Status EndpointStatus `json:"status"`
Spec EndpointSpec `json:"spec"`
}
type EndpointList struct {
Runtime
Items []*Endpoint
}
type EndpointMap struct {
Runtime
Items map[string]*Endpoint
}
// swagger:ignore
// EndpointMeta - endpoint meta data
type EndpointMeta struct {
Meta
// Namespace name
Namespace string `json:"namespace"`
}
// swagger:ignore
// EndpointStatus - endpoint status
type EndpointStatus struct {
State string `json:"state"`
Ready map[string]bool `json:"ready"`
}
// EndpointSpec spec data
// swagger:model types_endpoint_spec
type EndpointSpec struct {
// Endpoint state
State string `json:"state"`
External bool `json:"external"`
IP string `json:"ip"`
Domain string `json:"domain"`
PortMap map[uint16]string `json:"port_map"`
Strategy EndpointSpecStrategy `json:"strategy"`
Policy string `json:"policy"`
Upstreams []string `json:"upstreams"`
}
type EndpointState struct {
EndpointSpec
}
// EndpointSpecStrategy describes route and bind
// swagger:model types_endpoint_spec_strategy
type EndpointSpecStrategy struct {
Route string `json:"route"`
Bind string `json:"bind"`
}
// swagger:ignore
// EndpointUpstream describe endpoint backend data
type EndpointUpstream struct {
Host string `json:"host"`
Port int `json:"port"`
}
// swagger:ignore
// SelfLink generates and returning link to object in platform
func (e *Endpoint) SelfLink() string {
if e.Meta.SelfLink == "" {
e.Meta.SelfLink = e.CreateSelfLink(e.Meta.Namespace, e.Meta.Name)
}
return e.Meta.SelfLink
}
func (e *Endpoint) CreateSelfLink(namespace, name string) string {
return fmt.Sprintf("%s:%s", namespace, name)
}
// swagger:ignore
type EndpointCreateOptions struct {
IP string `json:"ip"`
Domain string `json:"domain"`
Ports map[uint16]string `json:"ports"`
RouteStrategy string `json:"route_strategy"`
Policy string `json:"policy"`
BindStrategy string `json:"bind_strategy"`
}
// swagger:ignore
type EndpointUpdateOptions struct {
IP *string `json:"ip"`
Ports map[uint16]string `json:"ports"`
RouteStrategy string `json:"route_strategy"`
Policy string `json:"policy"`
BindStrategy string `json:"bind_strategy"`
}
func NewEndpointList() *EndpointList {
dm := new(EndpointList)
dm.Items = make([]*Endpoint, 0)
return dm
}
func NewEndpointMap() *EndpointMap {
dm := new(EndpointMap)
dm.Items = make(map[string]*Endpoint)
return dm
}