-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.go
49 lines (38 loc) · 950 Bytes
/
client.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
package cicd
import (
"fmt"
"net/http"
"github.com/k8s-community/cicd/utils/rest"
)
const (
buildURL = "/api/v1/build"
)
// Client defines REST client
type Client struct {
client *rest.Client
}
// NewClient creates an instance of the Client
func NewClient(baseURL string) *Client {
return &Client{
client: rest.NewClient(nil, baseURL),
}
}
// Build runs CICD-build. Please, see an ExampleBuild.
func (c *Client) Build(request *BuildRequest) (*BuildResponse, error) {
req, err := c.client.NewRequest("POST", buildURL, request)
if err != nil {
return nil, err
}
var response = new(BuildResponse)
resp, err := c.client.Do(req, response)
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusCreated {
if response.Error != nil {
return nil, fmt.Errorf("Code %d, %s", response.Error.Code, response.Error.Message)
}
return nil, fmt.Errorf("Unknown error from CICD service.")
}
return response, nil
}