Aufräumen

This commit is contained in:
daru
2022-04-15 10:17:25 +02:00
parent c8e0b0af2d
commit 25259653e7
2 changed files with 18 additions and 15 deletions

20
ober.go
View File

@@ -26,19 +26,13 @@ func RunWebserv() {
} }
func Start(ctx *fasthttp.RequestCtx) { func Start(ctx *fasthttp.RequestCtx) {
data, err := cache.Get(seasonApiJikan) season, err := GetSeasonCache()
if err != nil {
addErrorToCtx(ctx, err)
return
}
var seasonData SeasonJikan
err = json.Unmarshal(data, &seasonData)
if err != nil { if err != nil {
addErrorToCtx(ctx, err) addErrorToCtx(ctx, err)
return return
} }
WriteIndex(ctx, &seasonData) WriteIndex(ctx, season)
ctx.SetContentType("text/html; charset=utf-8") ctx.SetContentType("text/html; charset=utf-8")
ctx.SetStatusCode(fasthttp.StatusOK) ctx.SetStatusCode(fasthttp.StatusOK)
@@ -50,12 +44,6 @@ func Season(ctx *fasthttp.RequestCtx) {
addErrorToCtx(ctx, err) addErrorToCtx(ctx, err)
return return
} }
var seasonData SeasonJikan
err = json.Unmarshal(data, &seasonData)
if err != nil {
addErrorToCtx(ctx, err)
return
}
_, err = ctx.Write(data) _, err = ctx.Write(data)
if err != nil { if err != nil {
@@ -201,7 +189,9 @@ func WatchPost(ctx *fasthttp.RequestCtx) {
} }
for _, anime := range animes { for _, anime := range animes {
// TODO iterate animes // TODO check if anime is in season
// iterate sent animes
detail, _, err := GetAnimeDetailData(anime.Anime) detail, _, err := GetAnimeDetailData(anime.Anime)
if err != nil { if err != nil {
ctx.WriteString(err.Error()) ctx.WriteString(err.Error())

13
raser.go Normal file
View File

@@ -0,0 +1,13 @@
package main
import "encoding/json"
func GetSeasonCache() (*SeasonJikan, error) {
data, err := cache.Get(seasonApiJikan)
if err != nil {
return nil, err
}
var seasonData SeasonJikan
err = json.Unmarshal(data, &seasonData)
return &seasonData, err
}