-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtokens.go
More file actions
36 lines (29 loc) · 795 Bytes
/
tokens.go
File metadata and controls
36 lines (29 loc) · 795 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
// Package tokens provides methods for managing tokens.
package tokens
import (
"encoding/json"
"fmt"
drycc "github.com/drycc/controller-sdk-go"
"github.com/drycc/controller-sdk-go/api"
)
// List tokens.
func List(c *drycc.Client, results int) ([]api.Token, int, error) {
body, count, reqErr := c.LimitedRequest("/v2/tokens/", results)
if reqErr != nil && !drycc.IsErrAPIMismatch(reqErr) {
return []api.Token{}, -1, reqErr
}
var tokens []api.Token
if err := json.Unmarshal([]byte(body), &tokens); err != nil {
return []api.Token{}, -1, err
}
return tokens, count, reqErr
}
// Delete a token
func Delete(c *drycc.Client, id string) error {
u := fmt.Sprintf("/v2/tokens/%s/", id)
res, err := c.Request("DELETE", u, nil)
if err == nil {
res.Body.Close()
}
return err
}