-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbiliapi.go
66 lines (55 loc) · 1.17 KB
/
biliapi.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
66
package biliapi
import (
"log"
"net/http"
"os"
"github.com/reveever/biliapi/base"
"github.com/reveever/biliapi/interface/live"
"github.com/reveever/biliapi/interface/room"
"github.com/reveever/biliapi/interface/space"
"github.com/reveever/biliapi/interface/v2dm"
)
type BiliAPI struct {
Base *base.Base
Space *space.API
V2Dm *v2dm.API
Live *live.API
Room *room.API
}
func NewBiliApi(options ...func(*BiliAPI)) (*BiliAPI, error) {
base := new(base.Base)
biliAPI := &BiliAPI{
Base: base,
Space: space.NewAPI(base),
V2Dm: v2dm.NewAPI(base),
Live: live.NewAPI(base),
Room: room.NewAPI(base),
}
for _, o := range options {
o(biliAPI)
}
if err := base.Init(); err != nil {
return nil, err
}
return biliAPI, nil
}
func EnableDebugLogger() func(*BiliAPI) {
return func(b *BiliAPI) {
b.Base.Log = log.New(os.Stderr, "", log.LstdFlags)
}
}
func WithDebugLogger(l base.BaseLogger) func(*BiliAPI) {
return func(b *BiliAPI) {
b.Base.Log = l
}
}
func WithHttpClient(c *http.Client) func(*BiliAPI) {
return func(b *BiliAPI) {
b.Base.Client = c
}
}
func WithUserAgent(ua string) func(*BiliAPI) {
return func(b *BiliAPI) {
b.Base.UserAgent = ua
}
}