File: operatingsystems.go

package info (click to toggle)
golang-github-packethost-packngo 0.2.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 440 kB
  • sloc: makefile: 2
file content (42 lines) | stat: -rw-r--r-- 954 bytes parent folder | download | duplicates (2)
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
package packngo

const osBasePath = "/operating-systems"

// OSService interface defines available operating_systems methods
type OSService interface {
	List() ([]OS, *Response, error)
}

type osRoot struct {
	OperatingSystems []OS `json:"operating_systems"`
}

// OS represents a Packet operating system
type OS struct {
	Name            string   `json:"name"`
	Slug            string   `json:"slug"`
	Distro          string   `json:"distro"`
	Version         string   `json:"version"`
	ProvisionableOn []string `json:"provisionable_on"`
}

func (o OS) String() string {
	return Stringify(o)
}

// OSServiceOp implements OSService
type OSServiceOp struct {
	client *Client
}

// List returns all available operating systems
func (s *OSServiceOp) List() ([]OS, *Response, error) {
	root := new(osRoot)

	resp, err := s.client.DoRequest("GET", osBasePath, nil, root)
	if err != nil {
		return nil, resp, err
	}

	return root.OperatingSystems, resp, err
}