Skip to content

Commit

Permalink
Merge pull request #9 from m-terra/bugfix/health-method-pointer
Browse files Browse the repository at this point in the history
Various fixes: pointers for API structs, expose service ip port API, health check options
  • Loading branch information
ureuzy authored Mar 29, 2023
2 parents adfa2ff + c008320 commit ef47db8
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 65 deletions.
4 changes: 1 addition & 3 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
run:
timeout: 1m
timeout: 5m
linters:
enable:
- asciicheck
- deadcode
- depguard
- dogsled
- durationcheck
Expand All @@ -28,7 +27,6 @@ linters:
- typecheck
- unconvert
- unused
- varcheck
disable:
# https://github.com/golangci/golangci-lint/issues/2649
- structcheck
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
test: lint unit-test

lint: lint-bin ## Run go golangci-lint against code.
$(GOLANGCI_LINT) run --timeout 5m0s
$(GOLANGCI_LINT) run

unit-test: mocks
go test -v ./... --vet=off -coverprofile cover.out
Expand All @@ -12,7 +12,7 @@ mocks: mockgen

GOLANGCI_LINT = ./bin/golangci-lint
lint-bin: ## Download golangci-lint locally if necessary.
$(call go-get-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint@v1.47.2)
$(call go-get-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint@v1.49.0)

MOCKGEN = ./bin/mockgen
mockgen: ## Download mockgen locally if necessary.
Expand Down
27 changes: 15 additions & 12 deletions pkg/axapi/gslb/gslb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gslb
import (
"github.com/ureuzy/acos-client-go/pkg/axapi/gslb/policy"
"github.com/ureuzy/acos-client-go/pkg/axapi/gslb/serviceip"
"github.com/ureuzy/acos-client-go/pkg/axapi/gslb/serviceip/serviceipport"
"github.com/ureuzy/acos-client-go/pkg/axapi/gslb/site"
"github.com/ureuzy/acos-client-go/pkg/axapi/gslb/site/siteipserver"
"github.com/ureuzy/acos-client-go/pkg/axapi/gslb/zone"
Expand All @@ -14,21 +15,23 @@ import (
const path = "gslb"

type Operator struct {
Policy rest.Operator[policy.Body, policy.ListBody]
ServiceIP rest.Operator[serviceip.Body, serviceip.ListBody]
Site rest.Operator[site.Body, site.ListBody]
SiteIPServer rest.Operator[siteipserver.Body, siteipserver.ListBody]
Zone rest.Operator[zone.Body, zone.ListBody]
ZoneService rest.Operator[zoneservice.Body, zoneservice.ListBody]
Policy rest.Operator[policy.Body, policy.ListBody]
ServiceIP rest.Operator[serviceip.Body, serviceip.ListBody]
ServiceIPPort rest.Operator[serviceipport.Body, serviceipport.ListBody]
Site rest.Operator[site.Body, site.ListBody]
SiteIPServer rest.Operator[siteipserver.Body, siteipserver.ListBody]
Zone rest.Operator[zone.Body, zone.ListBody]
ZoneService rest.Operator[zoneservice.Body, zoneservice.ListBody]
}

func New(c utils.HTTPClient) *Operator {
return &Operator{
Policy: policy.New(c, path),
ServiceIP: serviceip.New(c, path),
Site: site.New(c, path),
SiteIPServer: siteipserver.New(c, path),
Zone: zone.New(c, path),
ZoneService: zoneservice.New(c, path),
Policy: policy.New(c, path),
ServiceIP: serviceip.New(c, path),
ServiceIPPort: serviceipport.New(c, path),
Site: site.New(c, path),
SiteIPServer: siteipserver.New(c, path),
Zone: zone.New(c, path),
ZoneService: zoneservice.New(c, path),
}
}
72 changes: 36 additions & 36 deletions pkg/axapi/gslb/policy/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,42 @@ import "github.com/ureuzy/acos-client-go/pkg/axapi/shared"

type Object struct {
shared.AxaBase `json:",inline"`
Name string `json:"name,omitempty"`
HealthCheck shared.Boolean `json:"health-check,omitempty"`
HealthCheckPreferenceEnable shared.Boolean `json:"health-check-preference-enable,omitempty"`
HealthPreferenceTop int `json:"health-preference-top,omitempty"`
AmountFirst shared.Boolean `json:"amount-first,omitempty"`
WeightedIPEnable shared.Boolean `json:"weighted-ip-enable,omitempty"`
WeightedIPTotalHits shared.Boolean `json:"weighted-ip-total-hits,omitempty"`
WeightedSiteEnable shared.Boolean `json:"weighted-site-enable,omitempty"`
WeightedSiteTotalHits shared.Boolean `json:"weighted-site-total-hits,omitempty"`
WeightedAlias shared.Boolean `json:"weighted-alias,omitempty"`
ActiveServersEnable shared.Boolean `json:"active-servers-enable,omitempty"`
ActiveServersFailBreak shared.Boolean `json:"active-servers-fail-break,omitempty"`
BwCostEnable shared.Boolean `json:"bw-cost-enable,omitempty"`
BwCostFailBreak shared.Boolean `json:"bw-cost-fail-break,omitempty"`
Geographic shared.Boolean `json:"geographic,omitempty"`
NumSessionEnable shared.Boolean `json:"num-session-enable,omitempty"`
NumSessionTolerance int `json:"num-session-tolerance,omitempty"`
AdminPreference shared.Boolean `json:"admin-preference,omitempty"`
AliasAdminPreference shared.Boolean `json:"alias-admin-preference,omitempty"`
LeastResponse shared.Boolean `json:"least-response,omitempty"`
AdminIPEnable shared.Boolean `json:"admin-ip-enable,omitempty"`
AdminIPTopOnly shared.Boolean `json:"admin-ip-top-only,omitempty"`
OrderedIPTopOnly shared.Boolean `json:"ordered-ip-top-only,omitempty"`
RoundRobin shared.Boolean `json:"round-robin,omitempty"`
MetricForceCheck shared.Boolean `json:"metric-force-check,omitempty"`
IPList string `json:"ip-list,omitempty"`
MetricOrder shared.Boolean `json:"metric-order,omitempty"`
MetricType shared.Boolean `json:"metric-type,omitempty"` // "enum":[ "health-check", "weighted-ip", "weighted-site", "capacity", "active-servers", "active-rdt", "geographic", "connection-load", "num-session", "admin-preference", "bw-cost", "least-response", "admin-ip"]
Capacity Capacity `json:"capacity,omitempty"`
ConnectionLoad ConnectionLoad `json:"connection-load,omitempty"`
DNS DNS `json:"dns,omitempty"`
GeoLocationList []GeoLocation `json:"geo-location-list,omitempty"`
GeoLocationMatch GeoLocationMatch `json:"geo-location-match,omitempty"`
ActiveRdt ActiveRdt `json:"active-rdt,omitempty"`
AutoMap AutoMap `json:"auto-map,omitempty"`
EDNS EDNS `json:"edns,omitempty"`
Name string `json:"name,omitempty"`
HealthCheck shared.Boolean `json:"health-check,omitempty"`
HealthCheckPreferenceEnable shared.Boolean `json:"health-check-preference-enable,omitempty"`
HealthPreferenceTop int `json:"health-preference-top,omitempty"`
AmountFirst shared.Boolean `json:"amount-first,omitempty"`
WeightedIPEnable shared.Boolean `json:"weighted-ip-enable,omitempty"`
WeightedIPTotalHits shared.Boolean `json:"weighted-ip-total-hits,omitempty"`
WeightedSiteEnable shared.Boolean `json:"weighted-site-enable,omitempty"`
WeightedSiteTotalHits shared.Boolean `json:"weighted-site-total-hits,omitempty"`
WeightedAlias shared.Boolean `json:"weighted-alias,omitempty"`
ActiveServersEnable shared.Boolean `json:"active-servers-enable,omitempty"`
ActiveServersFailBreak shared.Boolean `json:"active-servers-fail-break,omitempty"`
BwCostEnable shared.Boolean `json:"bw-cost-enable,omitempty"`
BwCostFailBreak shared.Boolean `json:"bw-cost-fail-break,omitempty"`
Geographic shared.Boolean `json:"geographic,omitempty"`
NumSessionEnable shared.Boolean `json:"num-session-enable,omitempty"`
NumSessionTolerance int `json:"num-session-tolerance,omitempty"`
AdminPreference shared.Boolean `json:"admin-preference,omitempty"`
AliasAdminPreference shared.Boolean `json:"alias-admin-preference,omitempty"`
LeastResponse shared.Boolean `json:"least-response,omitempty"`
AdminIPEnable shared.Boolean `json:"admin-ip-enable,omitempty"`
AdminIPTopOnly shared.Boolean `json:"admin-ip-top-only,omitempty"`
OrderedIPTopOnly shared.Boolean `json:"ordered-ip-top-only,omitempty"`
RoundRobin shared.Boolean `json:"round-robin,omitempty"`
MetricForceCheck shared.Boolean `json:"metric-force-check,omitempty"`
IPList string `json:"ip-list,omitempty"`
MetricOrder shared.Boolean `json:"metric-order,omitempty"`
MetricType shared.Boolean `json:"metric-type,omitempty"` // "enum":[ "health-check", "weighted-ip", "weighted-site", "capacity", "active-servers", "active-rdt", "geographic", "connection-load", "num-session", "admin-preference", "bw-cost", "least-response", "admin-ip"]
Capacity *Capacity `json:"capacity,omitempty"`
ConnectionLoad *ConnectionLoad `json:"connection-load,omitempty"`
DNS *DNS `json:"dns,omitempty"`
GeoLocationList []GeoLocation `json:"geo-location-list,omitempty"`
GeoLocationMatch *GeoLocationMatch `json:"geo-location-match,omitempty"`
ActiveRdt *ActiveRdt `json:"active-rdt,omitempty"`
AutoMap *AutoMap `json:"auto-map,omitempty"`
EDNS *EDNS `json:"edns,omitempty"`
}

type Capacity struct {
Expand Down
4 changes: 2 additions & 2 deletions pkg/axapi/gslb/site/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ type Object struct {
ProtoAgingFast shared.Boolean `json:"proto-aging-fast,omitempty"`
Controller string `json:"controller,omitempty"`
IPServerList []siteipserver.IPServer `json:"ip-server-list,omitempty"`
ActiveRdt ActiveRdt `json:"active-rdt,omitempty"`
EasyRdt EasyRdt `json:"easy-rdt,omitempty"`
ActiveRdt *ActiveRdt `json:"active-rdt,omitempty"`
EasyRdt *EasyRdt `json:"easy-rdt,omitempty"`
SlbDevList []SlbDevList `json:"slb-dev-list,omitempty"`
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/axapi/gslb/zone/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Object struct {
Template Template `json:"template,omitempty"`
TTL int `json:"ttl,omitempty"`
UseServerTTL shared.Boolean `json:"use-server-ttl,omitempty"`
DNSSOARecord zoneservice.DNSSOARecord `json:"dns-soa-record,omitempty"`
DNSSOARecord *zoneservice.DNSSOARecord `json:"dns-soa-record,omitempty"`
SamplingEnable []shared.SamplingEnable `json:"sampling-enable,omitempty"` //"enum":[ "all", "received-query", "sent-response", "proxy-mode-response", "cache-mode-response", "server-mode-response", "sticky-mode-response", "backup-mode-response"]
DNSMXRecordList []zoneservice.DNSMXRecord `json:"dns-mx-record-list,omitempty"`
DNSNSRecordList []zoneservice.DNSNSRecord `json:"dns-ns-record-list,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/axapi/gslb/zone/zoneservice/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Service struct {
HealthCheckPort []HealthCheckPort `json:"health-check-port,omitempty"`
Policy string `json:"policy,omitempty"`
SamplingEnable []shared.SamplingEnable `json:"sampling-enable,omitempty"` // "enum":[ "all", "received-query", "sent-response", "proxy-mode-response", "cache-mode-response", "server-mode-response", "sticky-mode-response", "backup-mode-response"]
DNSARecord DNSARecord `json:"dns-a-record,omitempty"`
DNSARecord *DNSARecord `json:"dns-a-record,omitempty"`
DNSCNAMERecordList []DNSCnameRecord `json:"dns-cname-record-list,omitempty"`
DNSMXRecordList []DNSMXRecord `json:"dns-mx-record-list,omitempty"`
DNSNSRecordList []DNSMXRecord `json:"dns-ns-record-list,omitempty"`
Expand Down
17 changes: 13 additions & 4 deletions pkg/axapi/health/healthmonitor/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ type Object struct {
type HTTPMethod string

type Method struct {
TCP TCP `json:"tcp,omitempty"`
HTTP HTTP `json:"http,omitempty"`
HTTPS HTTPS `json:"https,omitempty"`
TCP *TCP `json:"tcp,omitempty"`
HTTP *HTTP `json:"http,omitempty"`
HTTPS *HTTPS `json:"https,omitempty"`
ICMP *ICMP `json:"icmp,omitempty"`
}

type HTTP struct {
Expand All @@ -48,7 +49,7 @@ type HTTP struct {
TextRegex string `json:"text-regex,omitempty"`
HTTPHost string `json:"http-host,omitempty"`
HTTPMaintenanceCode string `json:"http-maintenance-code,omitempty"`
HTTPURL string `json:"http-url,omitempty"`
HTTPURL shared.Boolean `json:"http-url,omitempty"`
URLType HTTPMethod `json:"url-type,omitempty"`
Maintenance shared.Boolean `json:"maintenance,omitempty"`
MaintenanceText string `json:"maintenance-text,omitempty"`
Expand Down Expand Up @@ -114,6 +115,14 @@ type TCP struct {
MaintenanceText string `json:"maintenance-text,omitempty"`
}

type ICMP struct {
shared.AxaBase `json:",inline"`
ICMP shared.Boolean `json:"icmp,omitempty"`
IP string `json:"ip,omitempty"`
IPV6 string `json:"ipv6,omitempty"`
Transparent shared.Boolean `json:"transparent,omitempty"`
}

type KerberosKdc struct {
HTTPKerberosHostIP string `json:"http-kerberos-hostip,omitempty"`
HTTPKerberosHostIPV6 string `json:"http-kerberos-hostipv6,omitempty"`
Expand Down
5 changes: 1 addition & 4 deletions utils/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,5 @@ func (r *Response) UnmarshalJSON(v interface{}) error {
if _, err := io.Copy(buf, r.Body); err != nil {
return err
}
if err := json.Unmarshal(buf.Bytes(), v); err != nil {
return err
}
return nil
return json.Unmarshal(buf.Bytes(), v)
}

0 comments on commit ef47db8

Please sign in to comment.