-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_languages.go
More file actions
45 lines (36 loc) · 743 Bytes
/
get_languages.go
File metadata and controls
45 lines (36 loc) · 743 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
45
package gowandbox
import (
"context"
"encoding/json"
"errors"
"io/ioutil"
"net/http"
)
/*
Returns a list of languages, maps to the `/list.json` endpoint
*/
func GetLanguages(ctx context.Context) ([]GWBLanguage, error) {
var result []GWBLanguage
client := http.DefaultClient
req, err := http.NewRequestWithContext(
ctx,
http.MethodGet,
WandBoxUrl+"list.json",
nil,
)
if err != nil {
return result, err
}
resp, err := client.Do(req)
if err != nil {
return result, err
}
if resp.StatusCode != http.StatusOK {
defer resp.Body.Close()
e, _ := ioutil.ReadAll(resp.Body)
return result, errors.New(string(e))
}
defer resp.Body.Close()
err = json.NewDecoder(resp.Body).Decode(&result)
return result, err
}