This repository has been archived by the owner on May 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathaddon.go
112 lines (95 loc) · 3.33 KB
/
addon.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
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
102
103
104
105
106
107
108
109
110
111
112
// WARNING: This code is auto-generated from the Heroku Platform API JSON Schema
// by a Ruby script (gen/gen.rb). Changes should be made to the generation
// script rather than the generated files.
package heroku
import (
"time"
)
// Add-ons represent add-ons that have been provisioned for an app.
type Addon struct {
// config vars associated with this application
ConfigVars []string `json:"config_vars"`
// when add-on was updated
CreatedAt time.Time `json:"created_at"`
// unique identifier of add-on
Id string `json:"id"`
// name of the add-on unique within its app
Name string `json:"name"`
// identity of add-on plan
Plan struct {
Id string `json:"id"`
Name string `json:"name"`
} `json:"plan"`
// id of this add-on with its provider
ProviderId string `json:"provider_id"`
// when add-on was updated
UpdatedAt time.Time `json:"updated_at"`
}
// Create a new add-on.
//
// appIdentity is the unique identifier of the Addon's App. plan is the unique
// identifier of this plan or unique name of this plan. options is the struct of
// optional parameters for this action.
func (c *Client) AddonCreate(appIdentity string, plan string, options *AddonCreateOpts) (*Addon, error) {
params := struct {
Plan string `json:"plan"`
Config *map[string]string `json:"config,omitempty"`
}{
Plan: plan,
}
if options != nil {
params.Config = options.Config
}
var addonRes Addon
return &addonRes, c.Post(&addonRes, "/apps/"+appIdentity+"/addons", params)
}
// AddonCreateOpts holds the optional parameters for AddonCreate
type AddonCreateOpts struct {
// custom add-on provisioning options
Config *map[string]string `json:"config,omitempty"`
}
// Delete an existing add-on.
//
// appIdentity is the unique identifier of the Addon's App. addonIdentity is the
// unique identifier of the Addon.
func (c *Client) AddonDelete(appIdentity string, addonIdentity string) error {
return c.Delete("/apps/" + appIdentity + "/addons/" + addonIdentity)
}
// Info for an existing add-on.
//
// appIdentity is the unique identifier of the Addon's App. addonIdentity is the
// unique identifier of the Addon.
func (c *Client) AddonInfo(appIdentity string, addonIdentity string) (*Addon, error) {
var addon Addon
return &addon, c.Get(&addon, "/apps/"+appIdentity+"/addons/"+addonIdentity)
}
// List existing add-ons.
//
// appIdentity is the unique identifier of the Addon's App. lr is an optional
// ListRange that sets the Range options for the paginated list of results.
func (c *Client) AddonList(appIdentity string, lr *ListRange) ([]Addon, error) {
req, err := c.NewRequest("GET", "/apps/"+appIdentity+"/addons", nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var addonsRes []Addon
return addonsRes, c.DoReq(req, &addonsRes)
}
// Change add-on plan. Some add-ons may not support changing plans. In that
// case, an error will be returned.
//
// appIdentity is the unique identifier of the Addon's App. addonIdentity is the
// unique identifier of the Addon. plan is the unique identifier of this plan or
// unique name of this plan.
func (c *Client) AddonUpdate(appIdentity string, addonIdentity string, plan string) (*Addon, error) {
params := struct {
Plan string `json:"plan"`
}{
Plan: plan,
}
var addonRes Addon
return &addonRes, c.Patch(&addonRes, "/apps/"+appIdentity+"/addons/"+addonIdentity, params)
}