File: zone.go

package info (click to toggle)
golang-github-mimuret-golang-iij-dpf 0.9.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,340 kB
  • sloc: makefile: 55
file content (101 lines) | stat: -rw-r--r-- 3,316 bytes parent folder | download
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
package core

import (
	"fmt"
	"net/url"

	"github.com/google/go-querystring/query"
	"github.com/mimuret/golang-iij-dpf/pkg/api"
	"github.com/mimuret/golang-iij-dpf/pkg/apis"
	"github.com/mimuret/golang-iij-dpf/pkg/types"
)

var _ api.Spec = &Zone{}

// +k8s:deepcopy-gen:interfaces=github.com/mimuret/golang-iij-dpf/pkg/api.Object

type Zone struct {
	AttributeMeta
	ID               string         `read:"id"`
	CommonConfigID   int64          `read:"common_config_id"`
	ServiceCode      string         `read:"service_code"`
	State            types.State    `read:"state"`
	Favorite         types.Favorite `read:"favorite" update:"favorite"`
	Name             string         `read:"name"`
	Network          string         `read:"network"`
	Description      string         `read:"description" update:"description"`
	ZoneProxyEnabled types.Boolean  `read:"zone_proxy_enabled"`
}

func (c *Zone) GetName() string { return "zones" }
func (c *Zone) GetPathMethod(action api.Action) (string, string) {
	switch action {
	case api.ActionRead, api.ActionUpdate:
		return action.ToMethod(), fmt.Sprintf("/zones/%s", c.ID)
	}
	return "", ""
}

func (c *Zone) SetPathParams(args ...interface{}) error {
	return apis.SetPathParams(args, &c.ID)
}

var _ apis.CountableListSpec = &ZoneList{}

// +k8s:deepcopy-gen:interfaces=github.com/mimuret/golang-iij-dpf/pkg/api.Object

type ZoneList struct {
	AttributeMeta
	api.Count
	Items []Zone `read:"items"`
}

func (c *ZoneList) GetName() string         { return "zones" }
func (c *ZoneList) GetItems() interface{}   { return &c.Items }
func (c *ZoneList) Len() int                { return len(c.Items) }
func (c *ZoneList) Index(i int) interface{} { return c.Items[i] }
func (c *ZoneList) GetMaxLimit() int32      { return 10000 }
func (c *ZoneList) ClearItems()             { c.Items = []Zone{} }
func (c *ZoneList) AddItem(v interface{}) bool {
	if a, ok := v.(Zone); ok {
		c.Items = append(c.Items, a)
		return true
	}
	return false
}

func (c *ZoneList) GetPathMethod(action api.Action) (string, string) {
	switch action {
	case api.ActionList:
		return action.ToMethod(), "/zones"
	case api.ActionCount:
		return action.ToMethod(), "/zones/count"
	}
	return "", ""
}
func (c *ZoneList) Init() {}
func (c *ZoneList) SetPathParams(args ...interface{}) error {
	return nil
}

var _ api.SearchParams = &ZoneListSearchKeywords{}

// +k8s:deepcopy-gen=false
type ZoneListSearchKeywords struct {
	api.CommonSearchParams
	FullText         api.KeywordsString   `url:"_keywords_full_text[],omitempty"`
	ServiceCode      api.KeywordsString   `url:"_keywords_service_code[],omitempty"`
	Name             api.KeywordsString   `url:"_keywords_name[],omitempty"`
	Network          api.KeywordsString   `url:"_keywords_network[],omitempty"`
	State            api.KeywordsState    `url:"_keywords_state[],omitempty"`
	Favorite         api.KeywordsFavorite `url:"_keywords_favorite[],omitempty"`
	Description      api.KeywordsString   `url:"_keywords_description[],omitempty"`
	CommonConfigID   api.KeywordsID       `url:"_keywords_common_config_id[],omitempty"`
	ZoneProxyEnabled api.KeywordsBoolean  `url:"_keywords_zone_proxy_enabled[],omitempty"`
}

func (s *ZoneListSearchKeywords) GetValues() (url.Values, error) { return query.Values(s) }

func init() {
	register(&Zone{}, &ZoneList{})
}