-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpermlinks.go
More file actions
50 lines (38 loc) · 896 Bytes
/
permlinks.go
File metadata and controls
50 lines (38 loc) · 896 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
46
47
48
49
50
package gowandbox
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
/*
Returns information about a program that was run, given the permlink.
Maps to the `/permlink/link` endpoint.
If the permlink is not found, and 500 error is returned.
*/
func GetPermLink(link string, ctx context.Context) (GWBPermLink, error) {
var result GWBPermLink
client := http.DefaultClient
req, err := http.NewRequestWithContext(
ctx,
http.MethodGet,
WandBoxUrl+"permlink/"+link,
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, fmt.Errorf("%v Error - %v", resp.StatusCode, string(e))
}
defer resp.Body.Close()
err = json.NewDecoder(resp.Body).Decode(&result)
return result, err
}