-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathpresets.go
More file actions
40 lines (35 loc) · 1022 Bytes
/
presets.go
File metadata and controls
40 lines (35 loc) · 1022 Bytes
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
package codersdk
import (
"context"
"encoding/json"
"fmt"
"net/http"
"github.com/google/uuid"
"golang.org/x/xerrors"
)
type Preset struct {
ID uuid.UUID
Name string
Parameters []PresetParameter
Default bool
DesiredPrebuildInstances *int
Description string
Icon string
}
type PresetParameter struct {
Name string
Value string
}
// TemplateVersionPresets returns the presets associated with a template version.
func (c *Client) TemplateVersionPresets(ctx context.Context, templateVersionID uuid.UUID) ([]Preset, error) {
res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/templateversions/%s/presets", templateVersionID), nil)
if err != nil {
return nil, xerrors.Errorf("do request: %w", err)
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return nil, ReadBodyAsError(res)
}
var presets []Preset
return presets, json.NewDecoder(res.Body).Decode(&presets)
}