-
Notifications
You must be signed in to change notification settings - Fork 1
/
rule.go
75 lines (64 loc) · 2.08 KB
/
rule.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
// Copyright e-Xpert Solutions SA. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gtm
import "github.com/hillmai/f5client/f5"
// RuleList holds a list of Rule configuration.
type RuleList struct {
Items []Rule `json:"items,omitempty"`
Kind string `json:"kind,omitempty"`
SelfLink string `json:"selflink,omitempty"`
}
// Rule holds the configuration of a single Rule.
type Rule struct {
APIAnonymous string `json:"apiAnonymous,omitempty"`
FullPath string `json:"fullPath,omitempty"`
Generation int `json:"generation,omitempty"`
Kind string `json:"kind,omitempty"`
Name string `json:"name,omitempty"`
Partition string `json:"partition,omitempty"`
SelfLink string `json:"selfLink,omitempty"`
}
// RuleEndpoint represents the REST resource for managing Rule.
const RuleEndpoint = "/rule"
// RuleResource provides an API to manage Rule configurations.
type RuleResource struct {
c *f5.Client
}
// ListAll lists all the Rule configurations.
func (r *RuleResource) ListAll() (*RuleList, error) {
var list RuleList
if err := r.c.ReadQuery(BasePath+RuleEndpoint, &list); err != nil {
return nil, err
}
return &list, nil
}
// Get a single Rule configuration identified by id.
func (r *RuleResource) Get(id string) (*Rule, error) {
var item Rule
if err := r.c.ReadQuery(BasePath+RuleEndpoint, &item); err != nil {
return nil, err
}
return &item, nil
}
// Create a new Rule configuration.
func (r *RuleResource) Create(item Rule) error {
if err := r.c.ModQuery("POST", BasePath+RuleEndpoint, item); err != nil {
return err
}
return nil
}
// Edit a Rule configuration identified by id.
func (r *RuleResource) Edit(id string, item Rule) error {
if err := r.c.ModQuery("PUT", BasePath+RuleEndpoint+"/"+id, item); err != nil {
return err
}
return nil
}
// Delete a single Rule configuration identified by id.
func (r *RuleResource) Delete(id string) error {
if err := r.c.ModQuery("DELETE", BasePath+RuleEndpoint+"/"+id, nil); err != nil {
return err
}
return nil
}