package logic import ( "io" "net/http" "strings" ) func GetAnilistAccessToken() (string, error) { if strings.HasPrefix(AnilistAccessToken, "ey") { return AnilistAccessToken, nil } if StoragePath == "" { return "", ErrAnilistTokenNotObtainable.New() } else if StorageUser == "" || StoragePass == "" { return "", ErrInvalidStorageParams.New() } req, err := http.NewRequest("GET", StoragePath, nil) if err != nil { return "", ErrStorageRequestFailed.Wrap(err) } req.SetBasicAuth(StorageUser, StoragePass) resp, err := http.DefaultClient.Do(req) if err != nil { return "", ErrStorageRequestFailed.Wrap(err) } defer resp.Body.Close() data, err := io.ReadAll(resp.Body) if err != nil { return "", ErrStorageRequestFailed.Wrap(err) } return strings.TrimSpace(string(data)), nil }