-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreview_envs.go
More file actions
46 lines (38 loc) · 1.38 KB
/
preview_envs.go
File metadata and controls
46 lines (38 loc) · 1.38 KB
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
package api
import (
"context"
"encoding/json"
"fmt"
"gopkg.in/nullstone-io/go-api-client.v0/response"
"gopkg.in/nullstone-io/go-api-client.v0/types"
"net/http"
)
// UpdatePreviewEnvInput
// when updating, we don't have to pass a name
// if you don't pass any fields, the api will simply make sure the preview environment is active
type UpdatePreviewEnvInput struct {
Name *string `json:"name,omitempty"`
}
type PreviewEnvs struct {
Client *Client
}
func (pe PreviewEnvs) envPath(stackId, envId int64) string {
return fmt.Sprintf("orgs/%s/stacks/%d/preview_envs/%d", pe.Client.Config.OrgName, stackId, envId)
}
// Get - GET /orgs/:orgName/stacks/:stack_id/preview_envs/:id
func (pe PreviewEnvs) Get(ctx context.Context, stackId, envId int64) (*types.Environment, error) {
res, err := pe.Client.Do(ctx, http.MethodGet, pe.envPath(stackId, envId), nil, nil, nil)
if err != nil {
return nil, err
}
return response.ReadJsonPtr[types.Environment](res)
}
// Update - PUT/PATCH /orgs/:orgName/stacks/:stack_id/preview_envs/:id
func (pe PreviewEnvs) Update(ctx context.Context, stackId, envId int64, env *UpdatePreviewEnvInput) (*types.Environment, error) {
rawPayload, _ := json.Marshal(env)
res, err := pe.Client.Do(ctx, http.MethodPut, pe.envPath(stackId, envId), nil, nil, json.RawMessage(rawPayload))
if err != nil {
return nil, err
}
return response.ReadJsonPtr[types.Environment](res)
}