Fixed errcheck linter complaints
This commit is contained in:
parent
190a85fe08
commit
940e949a30
@ -14,7 +14,7 @@ steps:
|
|||||||
- pack
|
- pack
|
||||||
- go build -v
|
- go build -v
|
||||||
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.16.0
|
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.16.0
|
||||||
- golangci-lint run --disable errcheck
|
- golangci-lint run
|
||||||
- go test -v -coverprofile=coverage.txt .
|
- go test -v -coverprofile=coverage.txt .
|
||||||
# - go mod download
|
# - go mod download
|
||||||
# - make tools
|
# - make tools
|
||||||
|
@ -400,7 +400,7 @@ func (anime *Anime) RefreshEpisodes() error {
|
|||||||
shoboiEpisodes, err := anime.ShoboiEpisodes()
|
shoboiEpisodes, err := anime.ShoboiEpisodes()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
color.Red(err.Error())
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
episodes.Merge(shoboiEpisodes)
|
episodes.Merge(shoboiEpisodes)
|
||||||
@ -409,7 +409,7 @@ func (anime *Anime) RefreshEpisodes() error {
|
|||||||
twistEpisodes, err := anime.TwistEpisodes()
|
twistEpisodes, err := anime.TwistEpisodes()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
color.Red(err.Error())
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
episodes.Merge(twistEpisodes)
|
episodes.Merge(twistEpisodes)
|
||||||
@ -485,7 +485,6 @@ func (anime *Anime) RefreshEpisodes() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
episodes.Save()
|
episodes.Save()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,11 @@ func startJobs() {
|
|||||||
// Log paths
|
// Log paths
|
||||||
logsPath := path.Join(arn.Root, "logs")
|
logsPath := path.Join(arn.Root, "logs")
|
||||||
jobLogsPath := path.Join(arn.Root, "logs", "jobs")
|
jobLogsPath := path.Join(arn.Root, "logs", "jobs")
|
||||||
os.Mkdir(jobLogsPath, 0777)
|
err := os.Mkdir(jobLogsPath, 0777)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
// Scheduler log
|
// Scheduler log
|
||||||
mainLog := log.New()
|
mainLog := log.New()
|
||||||
|
@ -31,8 +31,17 @@ func main() {
|
|||||||
defer color.Green("Finished.")
|
defer color.Green("Finished.")
|
||||||
|
|
||||||
// Create directories in case they're missing
|
// Create directories in case they're missing
|
||||||
os.Mkdir(animeDirectory, 0777)
|
err := os.Mkdir(animeDirectory, 0777)
|
||||||
os.Mkdir(characterDirectory, 0777)
|
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.Mkdir(characterDirectory, 0777)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
// Called with arguments?
|
// Called with arguments?
|
||||||
if InvokeShellArgs() {
|
if InvokeShellArgs() {
|
||||||
@ -128,11 +137,15 @@ func queueAnime(anime *arn.Anime, malCrawler *crawler.Crawler) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
malCrawler.Queue(&crawler.Task{
|
err = malCrawler.Queue(&crawler.Task{
|
||||||
URL: url,
|
URL: url,
|
||||||
Destination: filePath,
|
Destination: filePath,
|
||||||
Raw: true,
|
Raw: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func queueCharacter(character *arn.Character, malCrawler *crawler.Crawler) {
|
func queueCharacter(character *arn.Character, malCrawler *crawler.Crawler) {
|
||||||
@ -146,9 +159,13 @@ func queueCharacter(character *arn.Character, malCrawler *crawler.Crawler) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
malCrawler.Queue(&crawler.Task{
|
err = malCrawler.Queue(&crawler.Task{
|
||||||
URL: url,
|
URL: url,
|
||||||
Destination: filePath,
|
Destination: filePath,
|
||||||
Raw: true,
|
Raw: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ func main() {
|
|||||||
func readFiles(root string, onFile func(string) error) {
|
func readFiles(root string, onFile func(string) error) {
|
||||||
count := 0
|
count := 0
|
||||||
|
|
||||||
filepath.Walk(root, func(name string, info os.FileInfo, err error) error {
|
err := filepath.Walk(root, func(name string, info os.FileInfo, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
color.Red(err.Error())
|
color.Red(err.Error())
|
||||||
return err
|
return err
|
||||||
@ -61,6 +61,10 @@ func readFiles(root string, onFile func(string) error) {
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
// Erase line
|
// Erase line
|
||||||
print("\r\033[2K")
|
print("\r\033[2K")
|
||||||
|
|
||||||
|
@ -30,7 +30,11 @@ func InvokeShellArgs() bool {
|
|||||||
panic("No MAL ID")
|
panic("No MAL ID")
|
||||||
}
|
}
|
||||||
|
|
||||||
readAnimeFile(path.Join(arn.Root, "jobs", "mal-download", "anime", anime.GetMapping("myanimelist/anime")+".html.gz"))
|
err = readAnimeFile(path.Join(arn.Root, "jobs", "mal-download", "anime", anime.GetMapping("myanimelist/anime")+".html.gz"))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
case "character":
|
case "character":
|
||||||
character, err := arn.GetCharacter(objectID)
|
character, err := arn.GetCharacter(objectID)
|
||||||
@ -40,7 +44,11 @@ func InvokeShellArgs() bool {
|
|||||||
panic("No MAL ID")
|
panic("No MAL ID")
|
||||||
}
|
}
|
||||||
|
|
||||||
readCharacterFile(path.Join(arn.Root, "jobs", "mal-download", "character", character.GetMapping("myanimelist/character")+".html.gz"))
|
err = readCharacterFile(path.Join(arn.Root, "jobs", "mal-download", "character", character.GetMapping("myanimelist/character")+".html.gz"))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
@ -46,7 +46,12 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Refresh
|
// Refresh
|
||||||
anime.RefreshEpisodes()
|
err := anime.RefreshEpisodes()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
color.Red(err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// Ok
|
// Ok
|
||||||
color.Green("Found %d episodes for anime %s (Kitsu: %s)", len(anime.Episodes().Items), anime.ID, kitsuID)
|
color.Green("Found %d episodes for anime %s (Kitsu: %s)", len(anime.Episodes().Items), anime.ID, kitsuID)
|
||||||
|
@ -35,7 +35,12 @@ func Start(ctx aero.Context) error {
|
|||||||
return ctx.Error(http.StatusBadRequest, "Job is currently running!")
|
return ctx.Error(http.StatusBadRequest, "Job is currently running!")
|
||||||
}
|
}
|
||||||
|
|
||||||
job.Start()
|
err := job.Start()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return ctx.Error(http.StatusInternalServerError, "Job could not be started!", err)
|
||||||
|
}
|
||||||
|
|
||||||
jobLogs = append(jobLogs, user.Nick+" started "+job.Name+" job ("+arn.DateTimeUTC()+").")
|
jobLogs = append(jobLogs, user.Nick+" started "+job.Name+" job ("+arn.DateTimeUTC()+").")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -45,14 +45,20 @@ func BuyItem(ctx aero.Context) error {
|
|||||||
return ctx.Error(http.StatusBadRequest, "Not enough gems. You need to charge up your balance before you can buy this item.")
|
return ctx.Error(http.StatusBadRequest, "Not enough gems. You need to charge up your balance before you can buy this item.")
|
||||||
}
|
}
|
||||||
|
|
||||||
user.Balance -= totalPrice
|
|
||||||
user.Save()
|
|
||||||
|
|
||||||
// Add item to user inventory
|
// Add item to user inventory
|
||||||
inventory := user.Inventory()
|
inventory := user.Inventory()
|
||||||
inventory.AddItem(itemID, uint(quantity))
|
err = inventory.AddItem(itemID, uint(quantity))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return ctx.Error(http.StatusBadRequest, err)
|
||||||
|
}
|
||||||
|
|
||||||
inventory.Save()
|
inventory.Save()
|
||||||
|
|
||||||
|
// Deduct balance
|
||||||
|
user.Balance -= totalPrice
|
||||||
|
user.Save()
|
||||||
|
|
||||||
// Save purchase
|
// Save purchase
|
||||||
purchase := arn.NewPurchase(user.ID, itemID, quantity, int(item.Price), "gem")
|
purchase := arn.NewPurchase(user.ID, itemID, quantity, int(item.Price), "gem")
|
||||||
purchase.Save()
|
purchase.Save()
|
||||||
|
@ -23,6 +23,5 @@ func Download(ctx aero.Context) error {
|
|||||||
return ctx.Error(http.StatusNotFound, "Track not found", err)
|
return ctx.Error(http.StatusNotFound, "Track not found", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
track.Download()
|
return track.Download()
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
|
||||||
|
"github.com/akyoto/color"
|
||||||
"github.com/animenotifier/notify.moe/arn"
|
"github.com/animenotifier/notify.moe/arn"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -33,17 +34,28 @@ func main() {
|
|||||||
// Single user
|
// Single user
|
||||||
user, err := arn.GetUserByNick(nick)
|
user, err := arn.GetUserByNick(nick)
|
||||||
arn.PanicOnError(err)
|
arn.PanicOnError(err)
|
||||||
addItemToUser(user)
|
err = addItemToUser(user)
|
||||||
|
arn.PanicOnError(err)
|
||||||
} else {
|
} else {
|
||||||
// All users
|
// All users
|
||||||
for user := range arn.StreamUsers() {
|
for user := range arn.StreamUsers() {
|
||||||
addItemToUser(user)
|
err = addItemToUser(user)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
color.Red(err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func addItemToUser(user *arn.User) {
|
func addItemToUser(user *arn.User) error {
|
||||||
inventory := user.Inventory()
|
inventory := user.Inventory()
|
||||||
inventory.AddItem(itemID, uint(quantity))
|
err := inventory.AddItem(itemID, uint(quantity))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
inventory.Save()
|
inventory.Save()
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,11 @@ func main() {
|
|||||||
|
|
||||||
for index, anime := range allAnime {
|
for index, anime := range allAnime {
|
||||||
fmt.Printf("%d / %d\n", index+1, len(allAnime))
|
fmt.Printf("%d / %d\n", index+1, len(allAnime))
|
||||||
work(anime)
|
err := work(anime)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
color.Red(err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Give file buffers some time, just to be safe
|
// Give file buffers some time, just to be safe
|
||||||
@ -63,16 +67,18 @@ func work(anime *arn.Anime) error {
|
|||||||
response, err := client.Get(kitsuOriginal).End()
|
response, err := client.Get(kitsuOriginal).End()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
color.Red("%s (%s)", err.Error(), kitsuOriginal)
|
return fmt.Errorf("%s (%s)", err.Error(), kitsuOriginal)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if response.StatusCode() != http.StatusOK {
|
if response.StatusCode() != http.StatusOK {
|
||||||
color.Red("Status %d (%s)", response.StatusCode(), kitsuOriginal)
|
return fmt.Errorf("Status %d (%s)", response.StatusCode(), kitsuOriginal)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
anime.SetImageBytes(response.Bytes())
|
err = anime.SetImageBytes(response.Bytes())
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Try to free up some memory
|
// Try to free up some memory
|
||||||
runtime.GC()
|
runtime.GC()
|
||||||
|
@ -64,7 +64,7 @@ func mkclean(file string) error {
|
|||||||
|
|
||||||
// Read files in a given directory and apply a function on them
|
// Read files in a given directory and apply a function on them
|
||||||
func readFiles(root string, onFile func(string) error) {
|
func readFiles(root string, onFile func(string) error) {
|
||||||
filepath.Walk(root, func(name string, info os.FileInfo, err error) error {
|
err := filepath.Walk(root, func(name string, info os.FileInfo, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
color.Red(err.Error())
|
color.Red(err.Error())
|
||||||
return err
|
return err
|
||||||
@ -87,4 +87,8 @@ func readFiles(root string, onFile func(string) error) {
|
|||||||
// Always continue traversing the directory
|
// Always continue traversing the directory
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
color.Red(err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,13 @@ func process(character *arn.Character) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
character.SetImageBytes(buffer.Bytes())
|
err = character.SetImageBytes(buffer.Bytes())
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
color.Red(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
character.Save()
|
character.Save()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,11 @@ func main() {
|
|||||||
user.ForceSetNick(user.Nick)
|
user.ForceSetNick(user.Nick)
|
||||||
|
|
||||||
if user.Email != "" {
|
if user.Email != "" {
|
||||||
user.SetEmail(user.Email)
|
err := user.SetEmail(user.Email)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
color.Red(err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if user.Accounts.Google.ID != "" {
|
if user.Accounts.Google.ID != "" {
|
||||||
|
Loading…
Reference in New Issue
Block a user