-
Notifications
You must be signed in to change notification settings - Fork 2
/
client.go
65 lines (54 loc) · 1.38 KB
/
client.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package awg
import (
"context"
"go.uber.org/zap"
"github.com/rydesun/awesome-github/exch/github"
"github.com/rydesun/awesome-github/lib/errcode"
)
type Client struct {
gc *github.Client
}
// New awg client.
func NewClient(client *github.Client) (*Client, error) {
return &Client{
gc: client,
}, nil
}
func (c *Client) GetUser() (*User, error) {
user, err := c.gc.GetUser()
if err != nil {
return nil, err
}
return &User{
Name: user.Data.Viewer.Login,
RateLimit: RateLimit{
Total: user.Data.Ratelimit.Limit,
Remaining: user.Data.Ratelimit.Remaining,
ResetAt: user.Data.Ratelimit.ResetAt,
},
}, nil
}
// Get Readme html page.
func (c *Client) GetHTMLReadme(id github.RepoID) (string, error) {
const funcIntent = "get readme html page"
const funcErrMsg = "failed to " + funcIntent
return c.gc.GetHTMLReadme(id)
}
// Fill struct repo with more info.
func (c *Client) Fill(ctx context.Context, repo *AwesomeRepo) error {
const funcIntent = "fill struct repo with more info"
const funcErrMsg = "failed to " + funcIntent
logger := getLogger()
defer logger.Sync()
id := repo.ID
idStr := repo.ID.String()
logger.Debug(funcIntent, zap.String("repo", idStr))
rawRepo, err := c.gc.GetRepo(ctx, id)
if err != nil {
logger.Error(funcErrMsg, zap.Error(err),
zap.String("repo", idStr))
return errcode.Wrap(err, funcErrMsg)
}
repo.Aggregate(rawRepo)
return nil
}