-
Notifications
You must be signed in to change notification settings - Fork 54
/
destination.go
58 lines (49 loc) · 1.66 KB
/
destination.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
package payloads
import (
"code.cloudfoundry.org/korifi/api/repositories"
korifiv1alpha1 "code.cloudfoundry.org/korifi/controllers/api/v1alpha1"
)
type DestinationListCreate struct {
Destinations []Destination `json:"destinations" validate:"required,dive"`
}
type Destination struct {
App *AppResource `json:"app" validate:"required"`
Port *int `json:"port"`
Protocol *string `json:"protocol" validate:"omitempty,oneof=http1"`
}
type AppResource struct {
GUID string `json:"guid" validate:"required"`
Process *DestinationAppProcess `json:"process"`
}
type DestinationAppProcess struct {
Type string `json:"type" validate:"required"`
}
func (dc DestinationListCreate) ToMessage(routeRecord repositories.RouteRecord) repositories.AddDestinationsToRouteMessage {
addDestinations := make([]repositories.DestinationMessage, 0, len(dc.Destinations))
for _, destination := range dc.Destinations {
processType := korifiv1alpha1.ProcessTypeWeb
if destination.App.Process != nil {
processType = destination.App.Process.Type
}
port := 8080
if destination.Port != nil {
port = *destination.Port
}
protocol := "http1"
if destination.Protocol != nil {
protocol = *destination.Protocol
}
addDestinations = append(addDestinations, repositories.DestinationMessage{
AppGUID: destination.App.GUID,
ProcessType: processType,
Port: port,
Protocol: protocol,
})
}
return repositories.AddDestinationsToRouteMessage{
RouteGUID: routeRecord.GUID,
SpaceGUID: routeRecord.SpaceGUID,
ExistingDestinations: routeRecord.Destinations,
NewDestinations: addDestinations,
}
}