-
Notifications
You must be signed in to change notification settings - Fork 1
/
listener.go
59 lines (52 loc) · 1.99 KB
/
listener.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
package loadbalancer
import (
"fmt"
"net/url"
"github.com/FrenchBen/oracle-sdk-go/bmc"
"github.com/Sirupsen/logrus"
)
// Listener represents the listener's configuration: https://docs.us-phoenix-1.oraclecloud.com/api/#/en/loadbalancer/20170115/Listener/
type Listener struct {
BackendSetName string `json:"defaultBackendSetName"`
Name string `json:"name"`
Port int `json:"port"`
Protocol string `json:"protocol"` // HTTP or TCP
SSLConfig *SSLConfiguration `json:"sslConfiguration,omitempty"`
}
// CreateListener adds a listener to a load balancer
func (c *Client) CreateListener(loadBalancerID string, listener *Listener) (bool, *bmc.Error) {
loadBalancerID = url.PathEscape(loadBalancerID)
resp, err := c.Request("POST", fmt.Sprintf("/loadBalancers/%s/listeners", loadBalancerID), *listener)
if err != nil {
logrus.Error(err)
bmcError := bmc.Error{Code: string(resp.StatusCode), Message: err.Error()}
return false, &bmcError
}
logrus.Debug("StatusCode: ", resp.StatusCode)
if resp.StatusCode != 204 {
return false, bmc.NewError(*resp)
}
return true, nil
}
// UpdateListener updates a listener from a load balancer
func (c *Client) UpdateListener(listener *Listener) {
// PUT loadBalancers/{loadBalancerId}/listeners/{listenerName}
logrus.Warning("Method not yet implemented")
return
}
// DeleteListener deletes a listener from a load balancer
func (c *Client) DeleteListener(loadBalancerID string, listenerName string) (bool, *bmc.Error) {
loadBalancerID = url.PathEscape(loadBalancerID)
listenerName = url.PathEscape(listenerName)
resp, err := c.Request("DELETE", fmt.Sprintf("/loadBalancers/%s/listeners/%s", loadBalancerID, listenerName), nil)
if err != nil {
logrus.Error(err)
bmcError := bmc.Error{Code: string(resp.StatusCode), Message: err.Error()}
return false, &bmcError
}
logrus.Debug("StatusCode: ", resp.StatusCode)
if resp.StatusCode != 204 {
return false, bmc.NewError(*resp)
}
return true, nil
}