/
tag.go
49 lines (42 loc) · 836 Bytes
/
tag.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
44
45
46
47
48
49
package search
import (
"github.com/lucassabreu/clockify-cli/api"
"golang.org/x/sync/errgroup"
)
// GetTagsByName receives a list of id or names of tags and returns their ids
func GetTagsByName(
c api.Client,
workspace string,
tags []string,
) ([]string, error) {
if len(tags) == 0 {
return tags, nil
}
ts, err := c.GetTags(api.GetTagsParam{
Workspace: workspace,
PaginationParam: api.AllPages(),
})
if err != nil {
return tags, err
}
ns := make([]named, len(ts))
for i := 0; i < len(ns); i++ {
ns[i] = ts[i]
}
var g errgroup.Group
for i := 0; i < len(tags); i++ {
j := i
g.Go(func() error {
id, err := findByName(
tags[j],
"tag", func() ([]named, error) { return ns, nil },
)
if err != nil {
return err
}
tags[j] = id
return nil
})
}
return tags, g.Wait()
}