package biliapi import ( "io" "net/http" "net/url" "time" ) type Root struct { Code int `json:"code"` Message string `json:"message"` TTL int `json:"ttl"` Data interface{} `json:"data"` } type Jar struct { cookies []*http.Cookie } func (jar *Jar) SetCookies(u *url.URL, cookies []*http.Cookie) { jar.cookies = cookies } func (jar *Jar) Cookies(u *url.URL) []*http.Cookie { return jar.cookies } type BaseService struct { Client *http.Client Url string Headers map[string]string } func (srv *BaseService) DoRequest() ([]byte, error) { req, err := http.NewRequest("GET", srv.Url, nil) if err != nil { return nil, err } req.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/108.0.1462.46") if srv.Headers != nil { for k, v := range srv.Headers { req.Header.Add(k, v) } } if srv.Client == nil { srv.Client = &http.Client{ Timeout: 2 * time.Second, } } resp, err := srv.Client.Do(req) defer resp.Body.Close() if err != nil { return nil, err } body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } return body, nil }