summaryrefslogtreecommitdiff
path: root/bilibili/client.go
diff options
context:
space:
mode:
authorKeuin <[email protected]>2022-09-07 02:48:46 +0800
committerKeuin <[email protected]>2022-09-07 02:48:46 +0800
commit8e15d802865ed57db0018c15ea5559c8bd44c01f (patch)
tree48f4632a1ad044bd7f7f8da3ebe2bb03ab4ca6fe /bilibili/client.go
parent88234ca8fffc4e120adbe0d38071b625ad2f43c7 (diff)
First working version. Just a POC.
Diffstat (limited to 'bilibili/client.go')
-rw-r--r--bilibili/client.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/bilibili/client.go b/bilibili/client.go
new file mode 100644
index 0000000..fcea395
--- /dev/null
+++ b/bilibili/client.go
@@ -0,0 +1,45 @@
+/*
+This file defines the Bilibili client struct.
+This struct is a facade of all necessary Bilibili HTTP API wrappers.
+*/
+package bilibili
+
+import (
+ "context"
+ "log"
+ "net/http"
+ "os"
+)
+
+const (
+ // kUserAgent: the default user-agent header to use when communicating with bilibili.
+ kUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " +
+ "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"
+)
+
+type Bilibili struct {
+ userAgent string
+ http *http.Client
+ loggerCommon
+ ctx context.Context
+}
+
+func NewBilibiliWithContext(ctx context.Context) Bilibili {
+ logger := loggerCommon{
+ debug: log.New(os.Stderr, "DEBUG: ", log.Ldate|log.Ltime|log.Lshortfile),
+ info: log.New(os.Stderr, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile),
+ warn: log.New(os.Stderr, "WARNING: ", log.Ldate|log.Ltime|log.Lshortfile),
+ error: log.New(os.Stderr, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile),
+ }
+ return Bilibili{
+ loggerCommon: logger,
+ userAgent: kUserAgent,
+ http: http.DefaultClient,
+ ctx: ctx,
+ }
+}
+
+func NewBilibili() Bilibili {
+ ctx := context.Background()
+ return NewBilibiliWithContext(ctx)
+}