forked from pulse-vadc/go-vtm
/
config_rate.go
106 lines (94 loc) · 3 KB
/
config_rate.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
// Copyright (C) 2018-2019, Pulse Secure, LLC.
// Licensed under the terms of the MPL 2.0. See LICENSE file for details.
// Go library for Pulse Virtual Traffic Manager REST version 6.0.
package vtm
import (
"encoding/json"
)
type Rate struct {
connector *vtmConnector
RateProperties `json:"properties"`
}
func (vtm VirtualTrafficManager) GetRate(name string) (*Rate, *vtmErrorResponse) {
if name == "" {
panic("Provided an empty \"name\" parameter to VirtualTrafficManager.GetRate(name)")
}
conn := vtm.connector.getChildConnector("/tm/6.0/config/active/rate/" + name)
data, ok := conn.get()
if ok != true {
object := new(vtmErrorResponse)
json.NewDecoder(data).Decode(object)
return nil, object
}
object := new(Rate)
object.connector = conn
if err := json.NewDecoder(data).Decode(object); err != nil {
panic(err)
}
return object, nil
}
func (object Rate) Apply() (*Rate, *vtmErrorResponse) {
marshalled, err := json.Marshal(object)
if err != nil {
panic(err)
}
data, ok := object.connector.put(string(marshalled), STANDARD_OBJ)
if ok != true {
object := new(vtmErrorResponse)
json.NewDecoder(data).Decode(object)
return nil, object
}
if err := json.NewDecoder(data).Decode(&object); err != nil {
panic(err)
}
return &object, nil
}
func (vtm VirtualTrafficManager) NewRate(name string) *Rate {
object := new(Rate)
conn := vtm.connector.getChildConnector("/tm/6.0/config/active/rate/" + name)
object.connector = conn
return object
}
func (vtm VirtualTrafficManager) DeleteRate(name string) *vtmErrorResponse {
conn := vtm.connector.getChildConnector("/tm/6.0/config/active/rate/" + name)
data, ok := conn.delete()
if ok != true {
object := new(vtmErrorResponse)
json.NewDecoder(data).Decode(object)
return object
}
return nil
}
func (vtm VirtualTrafficManager) ListRates() (*[]string, *vtmErrorResponse) {
conn := vtm.connector.getChildConnector("/tm/6.0/config/active/rate")
data, ok := conn.get()
if ok != true {
object := new(vtmErrorResponse)
json.NewDecoder(data).Decode(object)
return nil, object
}
objectList := new(vtmObjectChildren)
if err := json.NewDecoder(data).Decode(objectList); err != nil {
panic(err)
}
var stringList []string
for _, obj := range objectList.Children {
stringList = append(stringList, obj.Name)
}
return &stringList, nil
}
type RateProperties struct {
Basic struct {
// Requests that are associated with this rate class will be rate-shaped
// to this many requests per minute, set to "0" to disable the limit.
MaxRatePerMinute *int `json:"max_rate_per_minute,omitempty"`
// Although requests will be rate-shaped to the "max_rate_per_minute",
// the traffic manager will also rate limit per-second. This smooths
// traffic so that a full minute's traffic will not be serviced
// in the first second of the minute, set this to "0" to disable
// the per-second limit.
MaxRatePerSecond *int `json:"max_rate_per_second,omitempty"`
// A description of the rate class.
Note *string `json:"note,omitempty"`
} `json:"basic"`
}