-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathget.go
More file actions
44 lines (33 loc) · 906 Bytes
/
get.go
File metadata and controls
44 lines (33 loc) · 906 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
41
42
43
44
package definition
import (
"context"
"encoding/json"
"errors"
"io"
"net/http"
"path"
"github.com/massdriver-cloud/mass/pkg/restclient"
)
func Get(c *restclient.MassdriverClient, definitionType string) (map[string]interface{}, error) {
var definition map[string]interface{}
endpoint := path.Join("artifact-definitions", definitionType)
req := restclient.NewRequest("GET", endpoint, nil)
ctx := context.Background()
resp, err := c.Do(&ctx, req)
if err != nil {
return definition, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return definition, errors.New("received non-200 response from Massdriver: " + resp.Status + " " + definitionType)
}
respBodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return definition, err
}
err = json.Unmarshal(respBodyBytes, &definition)
if err != nil {
return definition, err
}
return definition, nil
}