Compare commits
No commits in common. "main" and "v1.4.2" have entirely different histories.
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +0,0 @@
|
|||||||
api_test.go
|
|
8
api.go
8
api.go
@ -49,10 +49,6 @@ func request[T any](api *Api, query string, vars map[string]interface{}, respObj
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode != 200 {
|
|
||||||
return handleError(resp)
|
|
||||||
}
|
|
||||||
|
|
||||||
//data, _ := ioutil.ReadAll(resp.Body)
|
//data, _ := ioutil.ReadAll(resp.Body)
|
||||||
//fmt.Println(string(data))
|
//fmt.Println(string(data))
|
||||||
|
|
||||||
@ -94,10 +90,6 @@ func requestPaged[R any](api *Api, ctx context.Context, query string, vars map[s
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.Data.Page == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, value := range resp.Data.Page.Data() {
|
for _, value := range resp.Data.Page.Data() {
|
||||||
value := value
|
value := value
|
||||||
select {
|
select {
|
||||||
|
32
api_error.go
32
api_error.go
@ -1,32 +0,0 @@
|
|||||||
package anilist
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
|
||||||
"net/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
type apiError struct {
|
|
||||||
Message string `json:"message"`
|
|
||||||
Status int `json:"status"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type apiErrResp struct {
|
|
||||||
Errors []apiError `json:"errors"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleError(resp *http.Response) error {
|
|
||||||
respObj := &apiErrResp{}
|
|
||||||
|
|
||||||
dec := json.NewDecoder(resp.Body)
|
|
||||||
err := dec.Decode(respObj)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(respObj.Errors) == 0 {
|
|
||||||
return errors.New("unknown API error")
|
|
||||||
}
|
|
||||||
|
|
||||||
return errors.New(respObj.Errors[0].Message)
|
|
||||||
}
|
|
4
types.go
4
types.go
@ -184,7 +184,7 @@ type MediaListID int
|
|||||||
type MediaList struct {
|
type MediaList struct {
|
||||||
ID MediaListID `json:"id"`
|
ID MediaListID `json:"id"`
|
||||||
UserID int `json:"userId"`
|
UserID int `json:"userId"`
|
||||||
MediaID MediaID `json:"mediaId"`
|
MediaID int `json:"mediaId"`
|
||||||
Status MediaListStatus `json:"status"`
|
Status MediaListStatus `json:"status"`
|
||||||
Score float64 `json:"score"`
|
Score float64 `json:"score"`
|
||||||
Progress int `json:"progress"`
|
Progress int `json:"progress"`
|
||||||
@ -217,7 +217,7 @@ type AiringScheduleID int
|
|||||||
|
|
||||||
type AiringSchedule struct {
|
type AiringSchedule struct {
|
||||||
ID AiringScheduleID `json:"id"`
|
ID AiringScheduleID `json:"id"`
|
||||||
MediaID MediaID `json:"mediaId"`
|
MediaID int `json:"mediaId"`
|
||||||
AiringAt UnixTime `json:"airingAt"`
|
AiringAt UnixTime `json:"airingAt"`
|
||||||
TimeUntilAiring Seconds `json:"timeUntilAiring"`
|
TimeUntilAiring Seconds `json:"timeUntilAiring"`
|
||||||
Episode int `json:"episode"`
|
Episode int `json:"episode"`
|
||||||
|
2
utils.go
2
utils.go
@ -18,7 +18,7 @@ func addValue2InterfaceMap[K, T comparable](m map[K]interface{}, key K, value T)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func addSlice2InterfaceMap[K, T comparable](m map[K]interface{}, key K, value []T) {
|
func addSlice2InterfaceMap[K, T comparable](m map[K]interface{}, key K, value []T) {
|
||||||
if len(value) > 0 {
|
if value != nil && len(value) > 0 {
|
||||||
m[key] = value
|
m[key] = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user