cleaned up errors in go code

This commit is contained in:
John O'Keefe 2024-12-15 00:19:48 -05:00
parent 23ec111c60
commit 5ee9c42352
6 changed files with 88 additions and 81 deletions

View File

@ -31,12 +31,15 @@ func AniListQuery(body interface{}, login bool) (json.RawMessage, string) {
defer res.Body.Close() defer res.Body.Close()
returnedBody, err := io.ReadAll(res.Body) returnedBody, err := io.ReadAll(res.Body)
if err != nil {
return nil, "Could not read the returned body."
}
return returnedBody, res.Status return returnedBody, res.Status
} }
func (a *App) GetAniListItem(aniId int, login bool) AniListGetSingleAnime { func (a *App) GetAniListItem(aniId int, login bool) AniListGetSingleAnime {
var user = a.GetAniListLoggedInUser() user := a.GetAniListLoggedInUser()
var neededVariables interface{} var neededVariables interface{}
@ -141,7 +144,7 @@ func (a *App) GetAniListItem(aniId int, login bool) AniListGetSingleAnime {
returnedBody, status := AniListQuery(body, login) returnedBody, status := AniListQuery(body, login)
var post AniListGetSingleAnime var post AniListGetSingleAnime
if status == "404 Not Found" && login == false { if status == "404 Not Found" && !login {
return post return post
} }
@ -154,7 +157,7 @@ func (a *App) GetAniListItem(aniId int, login bool) AniListGetSingleAnime {
log.Printf("Failed at unmarshal, %s\n", err) log.Printf("Failed at unmarshal, %s\n", err)
} }
if login == false { if !login {
post.Data.MediaList.UserID = user.Data.Viewer.ID post.Data.MediaList.UserID = user.Data.Viewer.ID
post.Data.MediaList.Status = "" post.Data.MediaList.Status = ""
post.Data.MediaList.StartedAt.Year = 0 post.Data.MediaList.StartedAt.Year = 0
@ -249,7 +252,7 @@ func (a *App) AniListSearch(query string) any {
} }
func (a *App) GetAniListUserWatchingList(page int, perPage int, sort string) AniListCurrentUserWatchList { func (a *App) GetAniListUserWatchingList(page int, perPage int, sort string) AniListCurrentUserWatchList {
var user = a.GetAniListLoggedInUser() user := a.GetAniListLoggedInUser()
type Variables struct { type Variables struct {
Page int `json:"page"` Page int `json:"page"`
PerPage int `json:"perPage"` PerPage int `json:"perPage"`

View File

@ -30,11 +30,11 @@ var aniCtxShutdown, aniCancel = context.WithCancel(context.Background())
func (a *App) CheckIfAniListLoggedIn() bool { func (a *App) CheckIfAniListLoggedIn() bool {
if (AniListJWT{} == aniListJwt) { if (AniListJWT{} == aniListJwt) {
tokenType, err := aniRing.Get("anilistTokenType") tokenType, tokenErr := aniRing.Get("anilistTokenType")
expiresIn, err := aniRing.Get("anilistTokenExpiresIn") expiresIn, expiresInErr := aniRing.Get("anilistTokenExpiresIn")
accessToken, err := aniRing.Get("anilistAccessToken") refreshToken, refreshTokenErr := aniRing.Get("anilistRefreshToken")
refreshToken, err := aniRing.Get("anilistRefreshToken") accessToken, accessTokenErr := aniRing.Get("anilistAccessToken")
if err != nil || len(accessToken.Data) == 0 { if (tokenErr != nil || expiresInErr != nil || refreshTokenErr != nil || accessTokenErr != nil) || len(accessToken.Data) == 0 {
return false return false
} else { } else {
aniListJwt.TokenType = string(tokenType.Data) aniListJwt.TokenType = string(tokenType.Data)
@ -50,11 +50,11 @@ func (a *App) CheckIfAniListLoggedIn() bool {
func (a *App) AniListLogin() { func (a *App) AniListLogin() {
if (AniListJWT{} == aniListJwt) { if (AniListJWT{} == aniListJwt) {
tokenType, err := aniRing.Get("anilistTokenType") tokenType, tokenErr := aniRing.Get("anilistTokenType")
expiresIn, err := aniRing.Get("anilistTokenExpiresIn") expiresIn, expiresInErr := aniRing.Get("anilistTokenExpiresIn")
accessToken, err := aniRing.Get("anilistAccessToken") refreshToken, refreshTokenErr := aniRing.Get("anilistRefreshToken")
refreshToken, err := aniRing.Get("anilistRefreshToken") accessToken, accessTokenErr := aniRing.Get("anilistAccessToken")
if err != nil || len(accessToken.Data) == 0 { if (tokenErr != nil || expiresInErr != nil || refreshTokenErr != nil || accessTokenErr != nil) || len(accessToken.Data) == 0 {
getAniListCodeUrl := "https://anilist.co/api/v2/oauth/authorize?client_id=" + Environment.ANILIST_APP_ID + "&redirect_uri=" + Environment.ANILIST_CALLBACK_URI + "&response_type=code" getAniListCodeUrl := "https://anilist.co/api/v2/oauth/authorize?client_id=" + Environment.ANILIST_APP_ID + "&redirect_uri=" + Environment.ANILIST_CALLBACK_URI + "&response_type=code"
runtime.BrowserOpenURL(*wailsContext, getAniListCodeUrl) runtime.BrowserOpenURL(*wailsContext, getAniListCodeUrl)
@ -160,6 +160,9 @@ func getAniListAuthorizationToken(content string) AniListJWT {
defer res.Body.Close() defer res.Body.Close()
returnedBody, err := io.ReadAll(res.Body) returnedBody, err := io.ReadAll(res.Body)
if err != nil {
log.Printf("Could not read returned body, %s\n.", err)
}
var post AniListJWT var post AniListJWT
err = json.Unmarshal(returnedBody, &post) err = json.Unmarshal(returnedBody, &post)
@ -204,13 +207,12 @@ func (a *App) GetAniListLoggedInUser() AniListUser {
func (a *App) LogoutAniList() string { func (a *App) LogoutAniList() string {
if (AniListJWT{} != aniListJwt) { if (AniListJWT{} != aniListJwt) {
err := aniRing.Remove("anilistTokenType") typeErr := aniRing.Remove("anilistTokenType")
err = aniRing.Remove("anilistTokenExpiresIn") expiresInErr := aniRing.Remove("anilistTokenExpiresIn")
err = aniRing.Remove("anilistAccessToken") accessTokenErr := aniRing.Remove("anilistAccessToken")
err = aniRing.Remove("anilistRefreshToken") refreshTokenErr := aniRing.Remove("anilistRefreshToken")
if typeErr != nil || expiresInErr != nil || accessTokenErr != nil || refreshTokenErr != nil {
if err != nil { fmt.Println("AniList Logout Failed")
fmt.Println("AniList Logout Failed", err)
} }
aniListJwt = AniListJWT{} aniListJwt = AniListJWT{}
} }

View File

@ -46,10 +46,10 @@ type MALWatchlist struct {
Id int `json:"id" ts_type:"id"` Id int `json:"id" ts_type:"id"`
Title string `json:"title" ts_type:"title"` Title string `json:"title" ts_type:"title"`
MainPicture struct { MainPicture struct {
Medium string `json:"medium" json:"medium"` Medium string `json:"medium" ts_type:"medium"`
Large string `json:"large" json:"large"` Large string `json:"large" ts_type:"large"`
} `json:"main_picture" json:"mainPicture"` } `json:"main_picture" ts_type:"mainPicture"`
} `json:"node" json:"node"` } `json:"node" ts_type:"node"`
ListStatus struct { ListStatus struct {
Status string `json:"status" ts_type:"status"` Status string `json:"status" ts_type:"status"`
Score int `json:"score" ts_type:"score"` Score int `json:"score" ts_type:"score"`
@ -59,7 +59,7 @@ type MALWatchlist struct {
StartDate string `json:"start_date" ts_type:"startDate"` StartDate string `json:"start_date" ts_type:"startDate"`
FinishDate string `json:"finish_date" ts_type:"finishDate"` FinishDate string `json:"finish_date" ts_type:"finishDate"`
} `json:"list_status" ts_type:"listStatus"` } `json:"list_status" ts_type:"listStatus"`
} `json:"data" json:"data"` } `json:"data" ts_type:"data"`
Paging struct { Paging struct {
Previous string `json:"previous" ts_type:"previous"` Previous string `json:"previous" ts_type:"previous"`
Next string `json:"next" ts_type:"next"` Next string `json:"next" ts_type:"next"`
@ -70,9 +70,9 @@ type MALAnime struct {
Id int `json:"id" ts_type:"id"` Id int `json:"id" ts_type:"id"`
Title string `json:"title" ts_type:"title"` Title string `json:"title" ts_type:"title"`
MainPicture struct { MainPicture struct {
Large string `json:"large" json:"large"` Large string `json:"large" ts_type:"large"`
Medium string `json:"medium" json:"medium"` Medium string `json:"medium" ts_type:"medium"`
} `json:"main_picture" json:"mainPicture"` } `json:"main_picture" ts_type:"mainPicture"`
AlternativeTitles struct { AlternativeTitles struct {
Synonyms []string `json:"synonyms" ts_type:"synonyms"` Synonyms []string `json:"synonyms" ts_type:"synonyms"`
En string `json:"en" ts_type:"en"` En string `json:"en" ts_type:"en"`

View File

@ -50,7 +50,7 @@ func base64URLEncode(str []byte) string {
func verifier() (*CodeVerifier, error) { func verifier() (*CodeVerifier, error) {
r := rand.New(rand.NewSource(time.Now().UnixNano())) r := rand.New(rand.NewSource(time.Now().UnixNano()))
b := make([]byte, length, length) b := make([]byte, length)
for i := 0; i < length; i++ { for i := 0; i < length; i++ {
b[i] = byte(r.Intn(255)) b[i] = byte(r.Intn(255))
} }
@ -70,17 +70,19 @@ func (v *CodeVerifier) CodeChallengeS256() string {
} }
func (a *App) CheckIfMyAnimeListLoggedIn() bool { func (a *App) CheckIfMyAnimeListLoggedIn() bool {
fmt.Println("check function reached")
if (MyAnimeListJWT{} == myAnimeListJwt) { if (MyAnimeListJWT{} == myAnimeListJwt) {
tokenType, err := myAnimeListRing.Get("MyAnimeListTokenType") tokenType, tokenErr := myAnimeListRing.Get("MyAnimeListTokenType")
expiresIn, err := myAnimeListRing.Get("MyAnimeListExpiresIn") expiresIn, expiresInErr := myAnimeListRing.Get("MyAnimeListExpiresIn")
accessToken, err := myAnimeListRing.Get("MyAnimeListAccessToken") refreshToken, refreshTokenErr := myAnimeListRing.Get("MyAnimeListAccessToken")
refreshToken, err := myAnimeListRing.Get("MyAnimeListRefreshToken") accessToken, accessTokenErr := myAnimeListRing.Get("MyAnimeListRefreshToken")
if err != nil || len(accessToken.Data) == 0 { if (tokenErr != nil || expiresInErr != nil || refreshTokenErr != nil || accessTokenErr != nil) || len(accessToken.Data) == 0 {
return false return false
} else { } else {
var expresInConvertErr error
myAnimeListJwt.TokenType = string(tokenType.Data) myAnimeListJwt.TokenType = string(tokenType.Data)
myAnimeListJwt.ExpiresIn, err = strconv.Atoi(string(expiresIn.Data)) myAnimeListJwt.ExpiresIn, expresInConvertErr = strconv.Atoi(string(expiresIn.Data))
if err != nil { if expresInConvertErr != nil {
fmt.Println("unable to convert string to int") fmt.Println("unable to convert string to int")
} }
myAnimeListJwt.AccessToken = string(accessToken.Data) myAnimeListJwt.AccessToken = string(accessToken.Data)
@ -93,12 +95,14 @@ func (a *App) CheckIfMyAnimeListLoggedIn() bool {
} }
func (a *App) MyAnimeListLogin() { func (a *App) MyAnimeListLogin() {
if a.CheckIfMyAnimeListLoggedIn() == false { fmt.Println("login function reached")
tokenType, err := myAnimeListRing.Get("MyAnimeListTokenType") if !a.CheckIfMyAnimeListLoggedIn() {
expiresIn, err := myAnimeListRing.Get("MyAnimeListExpiresIn") fmt.Println("check logged in function failed")
accessToken, err := myAnimeListRing.Get("MyAnimeListAccessToken") tokenType, tokenErr := myAnimeListRing.Get("MyAnimeListTokenType")
refreshToken, err := myAnimeListRing.Get("MyAnimeListRefreshToken") expiresIn, expiresInErr := myAnimeListRing.Get("MyAnimeListExpiresIn")
if err != nil || len(accessToken.Data) == 0 { refreshToken, refreshTokenErr := myAnimeListRing.Get("MyAnimeListAccessToken")
accessToken, accessTokenErr := myAnimeListRing.Get("MyAnimeListRefreshToken")
if (tokenErr != nil || expiresInErr != nil || refreshTokenErr != nil || accessTokenErr != nil) || len(accessToken.Data) == 0 {
verifier, _ := verifier() verifier, _ := verifier()
getMyAnimeListCodeUrl := "https://myanimelist.net/v1/oauth2/authorize?response_type=code&client_id=" + Environment.MAL_CLIENT_ID + "&redirect_uri=" + Environment.MAL_CALLBACK_URI + "&code_challenge=" + verifier.Value + "&code_challenge_method=plain" getMyAnimeListCodeUrl := "https://myanimelist.net/v1/oauth2/authorize?response_type=code&client_id=" + Environment.MAL_CLIENT_ID + "&redirect_uri=" + Environment.MAL_CALLBACK_URI + "&code_challenge=" + verifier.Value + "&code_challenge_method=plain"
runtime.BrowserOpenURL(*wailsContext, getMyAnimeListCodeUrl) runtime.BrowserOpenURL(*wailsContext, getMyAnimeListCodeUrl)
@ -107,9 +111,10 @@ func (a *App) MyAnimeListLogin() {
a.handleMyAnimeListCallback(serverDone, verifier) a.handleMyAnimeListCallback(serverDone, verifier)
serverDone.Wait() serverDone.Wait()
} else { } else {
var expresInConvertErr error
myAnimeListJwt.TokenType = string(tokenType.Data) myAnimeListJwt.TokenType = string(tokenType.Data)
myAnimeListJwt.ExpiresIn, err = strconv.Atoi(string(expiresIn.Data)) myAnimeListJwt.ExpiresIn, expresInConvertErr = strconv.Atoi(string(expiresIn.Data))
if err != nil { if expresInConvertErr != nil {
fmt.Println("unable to convert string to int in Login function") fmt.Println("unable to convert string to int in Login function")
} }
myAnimeListJwt.AccessToken = string(accessToken.Data) myAnimeListJwt.AccessToken = string(accessToken.Data)
@ -218,6 +223,9 @@ func getMyAnimeListAuthorizationToken(content string, verifier *CodeVerifier) My
defer res.Body.Close() defer res.Body.Close()
returnedBody, err := io.ReadAll(res.Body) returnedBody, err := io.ReadAll(res.Body)
if err != nil {
log.Printf("Could not read returned body, %s\n", err)
}
var post MyAnimeListJWT var post MyAnimeListJWT
err = json.Unmarshal(returnedBody, &post) err = json.Unmarshal(returnedBody, &post)
@ -265,6 +273,9 @@ func refreshMyAnimeListAuthorizationToken() {
defer res.Body.Close() defer res.Body.Close()
returnedBody, err := io.ReadAll(res.Body) returnedBody, err := io.ReadAll(res.Body)
if err != nil {
log.Printf("Could not read returned body, %s\n", err)
}
err = json.Unmarshal(returnedBody, &myAnimeListJwt) err = json.Unmarshal(returnedBody, &myAnimeListJwt)
if err != nil { if err != nil {
@ -291,12 +302,9 @@ func refreshMyAnimeListAuthorizationToken() {
Title: "MyAnimeList Authorization", Title: "MyAnimeList Authorization",
Message: "It is now safe to close your browser tab", Message: "It is now safe to close your browser tab",
}) })
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
return
} }
func (a *App) GetMyAnimeListLoggedInUser() MyAnimeListUser { func (a *App) GetMyAnimeListLoggedInUser() MyAnimeListUser {
@ -311,7 +319,6 @@ func (a *App) GetMyAnimeListLoggedInUser() MyAnimeListUser {
req.Header.Add("myAnimeList-api-key", Environment.MAL_CLIENT_ID) req.Header.Add("myAnimeList-api-key", Environment.MAL_CLIENT_ID)
response, err := client.Do(req) response, err := client.Do(req)
if err != nil { if err != nil {
log.Printf("Failed at request, %s\n", err) log.Printf("Failed at request, %s\n", err)
return MyAnimeListUser{} return MyAnimeListUser{}
@ -333,13 +340,12 @@ func (a *App) GetMyAnimeListLoggedInUser() MyAnimeListUser {
func (a *App) LogoutMyAnimeList() string { func (a *App) LogoutMyAnimeList() string {
if (MyAnimeListJWT{} != myAnimeListJwt) { if (MyAnimeListJWT{} != myAnimeListJwt) {
err := myAnimeListRing.Remove("MyAnimeListTokenType") typeErr := myAnimeListRing.Remove("MyAnimeListTokenType")
err = myAnimeListRing.Remove("MyAnimeListExpiresIn") expiresInErr := myAnimeListRing.Remove("MyAnimeListExpiresIn")
err = myAnimeListRing.Remove("MyAnimeListAccessToken") accessTokenErr := myAnimeListRing.Remove("MyAnimeListAccessToken")
err = myAnimeListRing.Remove("MyAnimeListRefreshToken") refreshTokenErr := myAnimeListRing.Remove("MyAnimeListRefreshToken")
if typeErr != nil || expiresInErr != nil || accessTokenErr != nil || refreshTokenErr != nil {
if err != nil { fmt.Println("MAL Logout Failed")
fmt.Println("MAL Logout Failed", err)
} }
myAnimeListJwt = MyAnimeListJWT{} myAnimeListJwt = MyAnimeListJWT{}
} }

View File

@ -31,7 +31,6 @@ func SimklHelper(method string, url string, body interface{}) json.RawMessage {
req.Header.Add("simkl-api-key", Environment.SIMKL_CLIENT_ID) req.Header.Add("simkl-api-key", Environment.SIMKL_CLIENT_ID)
resp, err := client.Do(req) resp, err := client.Do(req)
if err != nil { if err != nil {
fmt.Println("Errored when sending request to the server") fmt.Println("Errored when sending request to the server")
message, _ := json.Marshal(struct { message, _ := json.Marshal(struct {
@ -47,7 +46,6 @@ func SimklHelper(method string, url string, body interface{}) json.RawMessage {
respBody, _ := io.ReadAll(resp.Body) respBody, _ := io.ReadAll(resp.Body)
return respBody return respBody
} }
func (a *App) SimklGetUserWatchlist() SimklWatchListType { func (a *App) SimklGetUserWatchlist() SimklWatchListType {
@ -62,7 +60,6 @@ func (a *App) SimklGetUserWatchlist() SimklWatchListType {
} }
err := json.Unmarshal(respBody, &errCheck) err := json.Unmarshal(respBody, &errCheck)
if err != nil { if err != nil {
log.Printf("Failed at unmarshal, %s\n", err) log.Printf("Failed at unmarshal, %s\n", err)
} }
@ -85,7 +82,6 @@ func (a *App) SimklGetUserWatchlist() SimklWatchListType {
} }
func (a *App) SimklSyncEpisodes(anime SimklAnime, progress int) SimklAnime { func (a *App) SimklSyncEpisodes(anime SimklAnime, progress int) SimklAnime {
var episodes []Episode var episodes []Episode
var url string var url string
var shows []SimklPostShow var shows []SimklPostShow
@ -140,7 +136,7 @@ func (a *App) SimklSyncEpisodes(anime SimklAnime, progress int) SimklAnime {
func (a *App) SimklSyncRating(anime SimklAnime, rating int) SimklAnime { func (a *App) SimklSyncRating(anime SimklAnime, rating int) SimklAnime {
var url string var url string
var showWithRating = ShowWithRating{ showWithRating := ShowWithRating{
Title: anime.Show.Title, Title: anime.Show.Title,
Ids: Ids{ Ids: Ids{
Simkl: anime.Show.Ids.Simkl, Simkl: anime.Show.Ids.Simkl,
@ -150,7 +146,7 @@ func (a *App) SimklSyncRating(anime SimklAnime, rating int) SimklAnime {
Rating: rating, Rating: rating,
} }
var showWithoutRating = ShowWithoutRating{ showWithoutRating := ShowWithoutRating{
Title: anime.Show.Title, Title: anime.Show.Title,
Ids: Ids{ Ids: Ids{
Simkl: anime.Show.Ids.Simkl, Simkl: anime.Show.Ids.Simkl,
@ -197,7 +193,7 @@ func (a *App) SimklSyncRating(anime SimklAnime, rating int) SimklAnime {
func (a *App) SimklSyncStatus(anime SimklAnime, status string) SimklAnime { func (a *App) SimklSyncStatus(anime SimklAnime, status string) SimklAnime {
url := "https://api.simkl.com/sync/add-to-list" url := "https://api.simkl.com/sync/add-to-list"
var show = SimklShowStatus{ show := SimklShowStatus{
Title: anime.Show.Title, Title: anime.Show.Title,
Ids: Ids{ Ids: Ids{
Simkl: anime.Show.Ids.Simkl, Simkl: anime.Show.Ids.Simkl,
@ -300,7 +296,7 @@ func (a *App) SimklSyncRemove(anime SimklAnime) bool {
url := "https://api.simkl.com/sync/history/remove" url := "https://api.simkl.com/sync/history/remove"
var showArray []SimklShowStatus var showArray []SimklShowStatus
var singleShow = SimklShowStatus{ singleShow := SimklShowStatus{
Title: anime.Show.Title, Title: anime.Show.Title,
Ids: Ids{ Ids: Ids{
Simkl: anime.Show.Ids.Simkl, Simkl: anime.Show.Ids.Simkl,
@ -349,5 +345,4 @@ func WatchListUpdate(anime SimklAnime) {
if !updated { if !updated {
SimklWatchList.Anime = append(SimklWatchList.Anime, anime) SimklWatchList.Anime = append(SimklWatchList.Anime, anime)
} }
return
} }

View File

@ -28,10 +28,10 @@ var simklCtxShutdown, simklCancel = context.WithCancel(context.Background())
func (a *App) CheckIfSimklLoggedIn() bool { func (a *App) CheckIfSimklLoggedIn() bool {
if (SimklJWT{} == simklJwt) { if (SimklJWT{} == simklJwt) {
tokenType, err := simklRing.Get("SimklTokenType") tokenType, tokenTypeErr := simklRing.Get("SimklTokenType")
accessToken, err := simklRing.Get("SimklAccessToken") accessToken, accessTokenErr := simklRing.Get("SimklAccessToken")
scope, err := simklRing.Get("SimklScope") scope, scopeErr := simklRing.Get("SimklScope")
if err != nil || len(accessToken.Data) == 0 { if (tokenTypeErr != nil || accessTokenErr != nil || scopeErr != nil) || len(accessToken.Data) == 0 {
return false return false
} else { } else {
simklJwt.TokenType = string(tokenType.Data) simklJwt.TokenType = string(tokenType.Data)
@ -45,11 +45,11 @@ func (a *App) CheckIfSimklLoggedIn() bool {
} }
func (a *App) SimklLogin() { func (a *App) SimklLogin() {
if a.CheckIfSimklLoggedIn() == false { if !a.CheckIfSimklLoggedIn() {
tokenType, err := simklRing.Get("SimklTokenType") tokenType, tokenTypeErr := simklRing.Get("SimklTokenType")
accessToken, err := simklRing.Get("SimklAccessToken") accessToken, accessTokenErr := simklRing.Get("SimklAccessToken")
scope, err := simklRing.Get("SimklScope") scope, scopeErr := simklRing.Get("SimklScope")
if err != nil || len(accessToken.Data) == 0 { if (tokenTypeErr != nil || accessTokenErr != nil || scopeErr != nil) || len(accessToken.Data) == 0 {
getSimklCodeUrl := "https://simkl.com/oauth/authorize?response_type=code&client_id=" + Environment.SIMKL_CLIENT_ID + "&redirect_uri=" + Environment.SIMKL_CALLBACK_URI getSimklCodeUrl := "https://simkl.com/oauth/authorize?response_type=code&client_id=" + Environment.SIMKL_CLIENT_ID + "&redirect_uri=" + Environment.SIMKL_CALLBACK_URI
runtime.BrowserOpenURL(*wailsContext, getSimklCodeUrl) runtime.BrowserOpenURL(*wailsContext, getSimklCodeUrl)
@ -155,6 +155,9 @@ func getSimklAuthorizationToken(content string) SimklJWT {
defer res.Body.Close() defer res.Body.Close()
returnedBody, err := io.ReadAll(res.Body) returnedBody, err := io.ReadAll(res.Body)
if err != nil {
log.Printf("Could not read returned body, %s\n.", err)
}
var post SimklJWT var post SimklJWT
err = json.Unmarshal(returnedBody, &post) err = json.Unmarshal(returnedBody, &post)
@ -177,7 +180,6 @@ func (a *App) GetSimklLoggedInUser() SimklUser {
req.Header.Add("simkl-api-key", Environment.SIMKL_CLIENT_ID) req.Header.Add("simkl-api-key", Environment.SIMKL_CLIENT_ID)
response, err := client.Do(req) response, err := client.Do(req)
if err != nil { if err != nil {
log.Printf("Failed at request, %s\n", err) log.Printf("Failed at request, %s\n", err)
return SimklUser{} return SimklUser{}
@ -193,7 +195,6 @@ func (a *App) GetSimklLoggedInUser() SimklUser {
} }
err = json.Unmarshal(respBody, &errCheck) err = json.Unmarshal(respBody, &errCheck)
if err != nil { if err != nil {
log.Printf("Failed at unmarshal, %s\n", err) log.Printf("Failed at unmarshal, %s\n", err)
} }
@ -215,12 +216,12 @@ func (a *App) GetSimklLoggedInUser() SimklUser {
func (a *App) LogoutSimkl() string { func (a *App) LogoutSimkl() string {
if (SimklJWT{} != simklJwt) { if (SimklJWT{} != simklJwt) {
err := simklRing.Remove("SimklTokenType") tokenTypeErr := simklRing.Remove("SimklTokenType")
err = simklRing.Remove("SimklAccessToken") accessTokenErr := simklRing.Remove("SimklAccessToken")
err = simklRing.Remove("SimklScope") scopeErr := simklRing.Remove("SimklScope")
if err != nil { if tokenTypeErr != nil || accessTokenErr != nil || scopeErr != nil {
fmt.Println("Simkl Logout Failed", err) fmt.Println("Simkl Logout Failed")
} }
simklJwt = SimklJWT{} simklJwt = SimklJWT{}
} }