diff --git a/.golangci.yml b/.golangci.yml index 4f339287..4d72eb1f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -12,4 +12,5 @@ linters: - gochecknoinits - gocyclo - maligned - - stylecheck \ No newline at end of file + - stylecheck + - funlen \ No newline at end of file diff --git a/arn/ShopItem.go b/arn/ShopItem.go index 129710f4..4844db00 100644 --- a/arn/ShopItem.go +++ b/arn/ShopItem.go @@ -21,6 +21,7 @@ const ( // ShopItem is a purchasable item in the shop. type ShopItem struct { + ID string `json:"id" primary:"true"` Name string `json:"name"` Description string `json:"description"` Price uint `json:"price"` @@ -28,8 +29,11 @@ type ShopItem struct { Rarity string `json:"rarity"` Order int `json:"order"` Consumable bool `json:"consumable"` +} - hasID +// GetID returns the ID. +func (item *ShopItem) GetID() string { + return item.ID } // GetShopItem ... diff --git a/arn/User.go b/arn/User.go index 8a21525e..387c2de3 100644 --- a/arn/User.go +++ b/arn/User.go @@ -175,11 +175,11 @@ func (user *User) SendNotification(pushNotification *PushNotification) { expired := []*PushSubscription{} for _, sub := range subs.Items { - resp, err := sub.SendNotification(pushNotification) + response, err := sub.SendNotification(pushNotification) - if resp != nil && resp.StatusCode == http.StatusGone { + // It is possible to receive a non-nil response with an error, so check the status. + if response != nil && response.StatusCode == http.StatusGone { expired = append(expired, sub) - continue } // Print errors @@ -188,10 +188,13 @@ func (user *User) SendNotification(pushNotification *PushNotification) { continue } + // Response body must be closed if no error was returned + defer response.Body.Close() + // Print bad status codes - if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { - body, _ := ioutil.ReadAll(resp.Body) - fmt.Println(resp.StatusCode, string(body)) + if response.StatusCode != http.StatusOK && response.StatusCode != http.StatusCreated { + body, _ := ioutil.ReadAll(response.Body) + fmt.Println(response.StatusCode, string(body)) continue } diff --git a/pages/admin/webdev.go b/pages/admin/webdev.go index d1d61bbe..4eb58e32 100644 --- a/pages/admin/webdev.go +++ b/pages/admin/webdev.go @@ -1,7 +1,9 @@ package admin -import "github.com/aerogo/aero" -import "github.com/animenotifier/notify.moe/components" +import ( + "github.com/aerogo/aero" + "github.com/animenotifier/notify.moe/components" +) // WebDev ... func WebDev(ctx aero.Context) error { diff --git a/patches/anime-episodes-sort/anime-episodes-sort.go b/patches/anime-episodes-sort/anime-episodes-sort.go deleted file mode 100644 index 3a5cad59..00000000 --- a/patches/anime-episodes-sort/anime-episodes-sort.go +++ /dev/null @@ -1,12 +0,0 @@ -package main - -import "github.com/animenotifier/notify.moe/arn" - -func main() { - defer arn.Node.Close() - - for episodes := range arn.StreamAnimeEpisodes() { - episodes.Sort() - episodes.Save() - } -} diff --git a/patches/anime-episodes-upgrade/anime-episodes-upgrade.go b/patches/anime-episodes-upgrade/anime-episodes-upgrade.go deleted file mode 100644 index 7f9a6462..00000000 --- a/patches/anime-episodes-upgrade/anime-episodes-upgrade.go +++ /dev/null @@ -1,22 +0,0 @@ -package main - -import "github.com/animenotifier/notify.moe/arn" - -func main() { - defer arn.Node.Close() - - for episodes := range arn.StreamAnimeEpisodes() { - anime := episodes.Anime() - anime.EpisodeIDs = nil - - for _, episode := range episodes.Items { - episode.ID = arn.GenerateID("Episode") - episode.AnimeID = anime.ID - episode.Save() - - anime.EpisodeIDs = append(anime.EpisodeIDs, episode.ID) - } - - anime.Save() - } -} diff --git a/patches/fix-airing-dates/fix-airing-dates.go b/patches/fix-airing-dates/fix-airing-dates.go index cd616bd0..ffa54e96 100644 --- a/patches/fix-airing-dates/fix-airing-dates.go +++ b/patches/fix-airing-dates/fix-airing-dates.go @@ -15,8 +15,6 @@ func main() { futureThreshold := 8 * 7 * 24 * time.Hour for anime := range arn.StreamAnime() { - modified := false - // Try to find incorrect airing dates for _, episode := range anime.Episodes() { if episode.AiringDate.Start == "" { @@ -35,12 +33,7 @@ func main() { // Delete the wrong airing date episode.AiringDate.Start = "" episode.AiringDate.End = "" - - modified = true - } - - if modified { - anime.Episodes().Save() + episode.Save() } } } diff --git a/utils/UserStats.go b/utils/UserStats.go index 016a84d9..11a8b72e 100644 --- a/utils/UserStats.go +++ b/utils/UserStats.go @@ -1,7 +1,10 @@ package utils -import "time" -import "github.com/animenotifier/notify.moe/arn" +import ( + "time" + + "github.com/animenotifier/notify.moe/arn" +) // UserStats ... type UserStats struct {