package goanilist import ( "encoding/json" "strconv" ) type APIError interface { Get() *FlexibleError } type FlexibleError struct { RawError *json.RawMessage `json:"error"` Error string ErrorMessage string `json:"error_message"` } type complexError struct { Error string `json:"error"` ErrorDescription string `json:"error_description"` Status int `json:"status"` Messages []string `json:"messages"` } func (e *FlexibleError) ParseRawError() { if e.RawError == nil { return } ce := complexError{} err := json.Unmarshal(*e.RawError, &ce) if err == nil { if ce.Error != "" { e.Error = ce.Error e.ErrorMessage = ce.ErrorDescription } else { e.Error = strconv.Itoa(ce.Status) e.ErrorMessage = "" for k, v := range ce.Messages { if k > 0 { e.ErrorMessage += "\n" } e.ErrorMessage += v } } } else { e.Error = string(*e.RawError) } } func (e *FlexibleError) Get() *FlexibleError { return e } type AccessTokenResult struct { FlexibleError AccessToken string `json:"access_token"` TokenType string `json:"token_type"` Expires int64 `json:"expires"` ExpiresIn int `json:"expires_in"` RefreshToken string `json:"refresh_token"` } type UserResult struct { FlexibleError ID int `json:"id"` DisplayName string `json:"display_name"` } type FavouritesResult struct { FlexibleError Characters CharacterResultCollection `json:"character"` } type CharacterResultCollection []CharacterResult func (c CharacterResultCollection) Len() int { return len(c) } func (c CharacterResultCollection) Less(i, j int) bool { return c[i].Order < c[j].Order } func (c CharacterResultCollection) Swap(i, j int) { c[i], c[j] = c[j], c[i] } type CharacterResult struct { FlexibleError ID int `json:"id"` GivenName string `json:"name_first"` FamilyName string `json:"name_last"` JapaneseName string `json:"name_japanese"` AlternativeName string `json:"name_alt"` Info string `json:"info"` Role string `json:"role"` ImageURL string `json:"image_url_lge"` ThumbURL string `json:"image_url_med"` Order int `json:"order"` } type CharacterPageResult struct { FlexibleError CharacterResult Anime []AnimeResult `json:"anime"` Manga []MangaResult `json:"manga"` } type SeriesResult struct { FlexibleError ID int `json:"id"` SeriesType string `json:"series_type"` Type string `json:"type"` TitleRomaji string `json:"title_romaji"` TitleEnglish string `json:"title_english"` TitleJapanese string `json:"title_japanese"` Synonyms []string `json:"synonyms"` Description string `json:"description"` StartDate int64 `json:"start_date_fuzzy"` EndDate int64 `json:"end_date_fuzzy"` Season int `json:"season"` Genres []string `json:"genres"` Adult bool `json:"adult"` AverageScore float32 `json:"average_score"` Popularity int `json:"popularity"` Favourite bool `json:"favourite"` ImageURL string `json:"image_url_lge"` ThumbSmallURL string `json:"image_url_sml"` ThumbBigURL string `json:"image_url_med"` BannerURL string `json:"image_url_banner"` UpdatedAt int64 `json:"updated_at"` } type AnimeResult struct { FlexibleError SeriesResult TotalEpisodes int `json:"total_episodes"` EpisodeDuration int `json:"duration"` AiringStatus string `json:"airing_status"` YoutubeID string `json:"youtube_id"` Hashtag string `json:"hashtag"` Source string `json:"source"` } type MangaResult struct { FlexibleError SeriesResult TotalChapters int `json:"total_chapters"` TotalVolumes int `json:"total_volumes"` PublishingStatus string `json:"publishing_status"` }