Split the client up into resource-specific files
This commit is contained in:
36
client/tag.go
Normal file
36
client/tag.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package client
|
||||
|
||||
import "fmt"
|
||||
|
||||
type Tag struct {
|
||||
GID string `json:"gid"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type tagsResponse struct {
|
||||
Data []*Tag `json:"data"`
|
||||
}
|
||||
|
||||
func (wc *WorkspaceClient) GetTags() ([]*Tag, error) {
|
||||
path := fmt.Sprintf("workspaces/%s/tags", wc.workspace.GID)
|
||||
resp := &tagsResponse{}
|
||||
err := wc.client.get(path, nil, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.Data, nil
|
||||
}
|
||||
|
||||
func (wc *WorkspaceClient) GetTagsByName() (map[string]*Tag, error) {
|
||||
tags, err := wc.GetTags()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tagsByName := map[string]*Tag{}
|
||||
for _, tag := range tags {
|
||||
tagsByName[tag.Name] = tag
|
||||
}
|
||||
|
||||
return tagsByName, err
|
||||
}
|
||||
Reference in New Issue
Block a user