-
Notifications
You must be signed in to change notification settings - Fork 1
/
spec.go
43 lines (33 loc) · 965 Bytes
/
spec.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
package ranna
import (
"encoding/json"
"github.com/valyala/fasthttp"
)
// Specs represents a map of specs
type Specs map[string]*Spec
// Spec represents a language execution spec
type Spec struct {
Use string `json:"use"`
Image string `json:"image"`
Entrypoint string `json:"entrypoint"`
Filename string `json:"filename"`
}
// Specs requests the specified specs from the ranna instance
func (client *Client) Specs() (*Specs, error) {
request := fasthttp.AcquireRequest()
defer fasthttp.ReleaseRequest(request)
response := fasthttp.AcquireResponse()
defer fasthttp.ReleaseResponse(response)
request.SetRequestURI(client.instance + EndpointSpec)
if err := client.http.Do(request, response); err != nil {
return nil, err
}
if err := parseErrorFromResponse(response); err != nil {
return nil, err
}
specs := new(Specs)
if err := json.Unmarshal(response.Body(), specs); err != nil {
return nil, err
}
return specs, nil
}