-
Notifications
You must be signed in to change notification settings - Fork 124
/
route.go
145 lines (125 loc) · 3.47 KB
/
route.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
//
// 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"
"time"
)
// Route
// swagger:ignore
// swagger:model types_route
type Route struct {
Runtime
Meta RouteMeta `json:"meta" yaml:"meta"`
Status RouteStatus `json:"status" yaml:"status"`
Spec RouteSpec `json:"spec" yaml:"spec"`
}
// swagger:ignore
type RouteMap struct {
Runtime
Items map[string]*Route
}
// swagger:ignore
type RouteList struct {
Runtime
Items []*Route
}
// swagger:ignore
// swagger:model types_route_meta
type RouteMeta struct {
Meta `yaml:",inline"`
Namespace string `json:"namespace" yaml:"namespace"`
Ingress string `json:"ingress" yaml:"ingress"`
}
// swagger:model types_route_spec
type RouteSpec struct {
Selector RouteSelector `json:"selector" yaml:"selector"`
State string `json:"state" yaml:"state"`
Domain string `json:"domain" yaml:"domain"`
Port uint16 `json:"port" yaml:"port"`
Rules []RouteRule `json:"rules" yaml:"rules"`
Updated time.Time `json:"updated"`
}
type RouteSelector struct {
Ingress string `json:"ingress" yaml:"ingress"`
Label map[string]string `json:"label" yaml:"label"`
}
// swagger:ignore
// swagger:model types_route_status
// RouteStatus - status of current route state
type RouteStatus struct {
State string `json:"state" yaml:"state"`
Message string `json:"message" yaml:"message"`
}
// swagger:model types_route_rule
type RouteRule struct {
Service string `json:"service" yaml:"service"`
Path string `json:"path" yaml:"path"`
Endpoint string `json:"endpoint" yaml:"endpoint"`
Port int `json:"port" yaml:"port"`
}
func (r *Route) SelfLink() string {
if r.Meta.SelfLink == "" {
r.Meta.SelfLink = r.CreateSelfLink(r.Meta.Namespace, r.Meta.Name)
}
return r.Meta.SelfLink
}
func (r *Route) CreateSelfLink(namespace, name string) string {
return fmt.Sprintf("%s:%s", namespace, name)
}
type RouteManifest struct {
State string `json:"state"`
Domain string `json:"domain"`
Port uint16 `json:"port"`
Endpoint string `json:"endpoint"`
Rules []RouteRule `json:"rules"`
}
type RouteManifestList struct {
Runtime
Items []*RouteManifest
}
type RouteManifestMap struct {
Runtime
Items map[string]*RouteManifest
}
func (r *RouteManifest) Set(route *Route) {
r.State = route.Spec.State
r.Domain = route.Spec.Domain
r.Rules = route.Spec.Rules
r.Port = route.Spec.Port
}
func NewRouteList() *RouteList {
dm := new(RouteList)
dm.Items = make([]*Route, 0)
return dm
}
func NewRouteMap() *RouteMap {
dm := new(RouteMap)
dm.Items = make(map[string]*Route)
return dm
}
func NewRouteManifestList() *RouteManifestList {
dm := new(RouteManifestList)
dm.Items = make([]*RouteManifest, 0)
return dm
}
func NewRouteManifestMap() *RouteManifestMap {
dm := new(RouteManifestMap)
dm.Items = make(map[string]*RouteManifest)
return dm
}