Skip to content

Commit

Permalink
feat: added slog as logger
Browse files Browse the repository at this point in the history
  • Loading branch information
keshon committed Feb 8, 2024
1 parent 280715e commit efe4ebf
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 61 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ tests.bat
/release
/release/*.db
/vendor
/dump
/dump
/logs/*
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ go 1.16
require (
github.com/beefsack/go-rate v0.0.0-20200827232406-6cde80facd47
github.com/fatih/color v1.12.0 // indirect
github.com/gookit/slog v0.5.5
github.com/hokaccha/go-prettyjson v0.0.0-20210113012101-fb4e108d2519
github.com/naoina/go-stringutil v0.1.0 // indirect
github.com/naoina/toml v0.1.1
github.com/pieterclaerhout/go-waitgroup v1.0.7
github.com/robfig/cron/v3 v3.0.1
golang.org/x/sys v0.0.0-20210910150752-751e447fb3d0 // indirect
gorm.io/driver/sqlite v1.1.4
gorm.io/gorm v1.21.15
)
61 changes: 61 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
github.com/beefsack/go-rate v0.0.0-20200827232406-6cde80facd47 h1:M57m0xQqZIhx7CEJgeLSvRFKEK1RjzRuIXiA3HfYU7g=
github.com/beefsack/go-rate v0.0.0-20200827232406-6cde80facd47/go.mod h1:6YNgTHLutezwnBvyneBbwvB8C82y3dcoOj5EQJIdGXA=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.12.0 h1:mRhaKNwANqRgUBGKmnI5ZxEk7QXmjQeCcuYFMX2bfcc=
github.com/fatih/color v1.12.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/gookit/color v1.5.4 h1:FZmqs7XOyGgCAxmWyPslpiok1k05wmY3SJTytgvYFs0=
github.com/gookit/color v1.5.4/go.mod h1:pZJOeOS8DM43rXbp4AZo1n9zCU2qjpcRko0b6/QJi9w=
github.com/gookit/goutil v0.6.15 h1:mMQ0ElojNZoyPD0eVROk5QXJPh2uKR4g06slgPDF5Jo=
github.com/gookit/goutil v0.6.15/go.mod h1:qdKdYEHQdEtyH+4fNdQNZfJHhI0jUZzHxQVAV3DaMDY=
github.com/gookit/gsr v0.1.0 h1:0gadWaYGU4phMs0bma38t+Do5OZowRMEVlHv31p0Zig=
github.com/gookit/gsr v0.1.0/go.mod h1:7wv4Y4WCnil8+DlDYHBjidzrEzfHhXEoFjEA0pPPWpI=
github.com/gookit/slog v0.5.5 h1:XoyK3NilKzuC/umvnqTQDHTOnpC8R6pvlr/ht9PyfgU=
github.com/gookit/slog v0.5.5/go.mod h1:RfIwzoaQ8wZbKdcqG7+3EzbkMqcp2TUn3mcaSZAw2EQ=
github.com/hokaccha/go-prettyjson v0.0.0-20210113012101-fb4e108d2519 h1:nqAlWFEdqI0ClbTDrhDvE/8LeQ4pftrqKUX9w5k0j3s=
github.com/hokaccha/go-prettyjson v0.0.0-20210113012101-fb4e108d2519/go.mod h1:pFlLw2CfqZiIBOx6BuCeRLCrfxBJipTY0nIOF/VbGcI=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
Expand All @@ -27,14 +37,65 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210910150752-751e447fb3d0 h1:xrCZDmdtoloIiooiA9q0OQb9r8HejIHYoHGhGCe1pGg=
golang.org/x/sys v0.0.0-20210910150752-751e447fb3d0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/sqlite v1.1.4 h1:PDzwYE+sI6De2+mxAneV9Xs11+ZyKV6oxD3wDGkaNvM=
gorm.io/driver/sqlite v1.1.4/go.mod h1:mJCeTFr7+crvS+TRnWc5Z3UvwxUN1BGBLMrf5LA9DYw=
gorm.io/gorm v1.20.7/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
Expand Down
3 changes: 2 additions & 1 deletion src/api/discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"io/ioutil"
"log"
"log/slog"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -132,7 +133,7 @@ func SendMessageBunch(conf config.Config, data []kitsu.MessagePayload, webHookUR

if conf.Log {
if len(resp) > 0 {
log.Printf("Discord error response: " + resp)
slog.Info("Discord error response: " + resp)
}
}
}
Expand Down
72 changes: 35 additions & 37 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"

"log"
"os"
"sort"
Expand All @@ -17,6 +18,8 @@ import (
"time"

"github.com/beefsack/go-rate"
"github.com/gookit/slog"
"github.com/gookit/slog/handler"

"github.com/pieterclaerhout/go-waitgroup"
"github.com/robfig/cron/v3"
Expand All @@ -29,44 +32,44 @@ func MakeKitsuResponse(conf config.Config) []kitsu.MessagePayload {

tasks := kitsu.GetTasks()
if conf.Log {
fmt.Println("Got tasks: " + strconv.Itoa(len(tasks.Each)))
slog.Info("Got tasks: " + strconv.Itoa(len(tasks.Each)))
}

taskStatuses := kitsu.GetTaskStatuses()
if conf.Log {
fmt.Println("Got taskStatuses: " + strconv.Itoa(len(taskStatuses.Each)))
slog.Info("Got taskStatuses: " + strconv.Itoa(len(taskStatuses.Each)))
}

entities := kitsu.GetEntities()
if conf.Log {
fmt.Println("Got entities: " + strconv.Itoa(len(entities.Each)))
slog.Info("Got entities: " + strconv.Itoa(len(entities.Each)))
}

enitityTypes := kitsu.GetEntityTypes()
if conf.Log {
fmt.Println("Got enitityTypes: " + strconv.Itoa(len(enitityTypes.Each)))
slog.Info("Got enitityTypes: " + strconv.Itoa(len(enitityTypes.Each)))
}

projects := kitsu.GetProjects()
if conf.Log {
fmt.Println("Got projects: " + strconv.Itoa(len(projects.Each)))
slog.Info("Got projects: " + strconv.Itoa(len(projects.Each)))
}

taskTypes := kitsu.GetTaskTypes()
if conf.Log {
fmt.Println("Got taskTypes: " + strconv.Itoa(len(taskTypes.Each)))
slog.Info("Got taskTypes: " + strconv.Itoa(len(taskTypes.Each)))
}

persons := kitsu.GetPersons()
if conf.Log {
fmt.Println("Got persons: " + strconv.Itoa(len(persons.Each)))
slog.Info("Got persons: " + strconv.Itoa(len(persons.Each)))
}

var comments kitsu.Comments
if conf.Kitsu.SkipComments == false {
comments = kitsu.GetComments()
if conf.Log {
fmt.Println("Got comments: " + strconv.Itoa(len(comments.Each)))
slog.Info("Got comments: " + strconv.Itoa(len(comments.Each)))
}
}

Expand All @@ -86,7 +89,7 @@ func MakeKitsuResponse(conf config.Config) []kitsu.MessagePayload {
layout := "2006-01-02T15:04:05"
taskDate, err := time.Parse(layout, tasks.Each[i].UpdatedAt)
if err != nil {
fmt.Println(err)
slog.Info(err)
}
daysCount := int(start.Sub(taskDate).Hours() / 24)

Expand Down Expand Up @@ -159,11 +162,11 @@ func MakeKitsuResponse(conf config.Config) []kitsu.MessagePayload {
layout := "2006-01-02T15:04:05"
a, err := time.Parse(layout, taskComments.Each[i].UpdatedAt)
if err != nil {
fmt.Println(err)
slog.Info(err)
}
b, err := time.Parse(layout, taskComments.Each[j].UpdatedAt)
if err != nil {
fmt.Println(err)
slog.Info(err)
}
return a.Unix() > b.Unix()
})
Expand Down Expand Up @@ -284,14 +287,6 @@ func FilterTasks(data []kitsu.MessagePayload, conf config.Config, db *gorm.DB) {

}

/*
prettyResp, _ := prettyjson.Marshal(tasksByProject)
fmt.Println("tasksByProject : ", string(prettyResp))
println("------------")
prettyResp, _ = prettyjson.Marshal(filtered)
fmt.Println("filtered : ", string(prettyResp))
*/

// Send to Discord per production URL (see Advanced settings)
if len(tasksByProject) > 0 {
for i := 0; i < len(tasksByProject); i++ {
Expand Down Expand Up @@ -321,15 +316,6 @@ func DiscordQueueSend(data []kitsu.MessagePayload, conf config.Config, webhookUR

payload = append(payload, data[i])

/*
if conf.Log {
log.Printf(strconv.Itoa(len(payload)))
log.Printf(strconv.Itoa(len(filtered)))
log.Printf(strconv.Itoa(conf.Discord.EmbedsPerRequests))
log.Printf("i " + strconv.Itoa(i))
}
*/

if (i+1)%conf.Discord.EmbedsPerRequests == 0 || (i+1)%len(data) == 0 {
if conf.Log {
log.Printf("Sending bunch of messages: " + strconv.Itoa(len(payload)))
Expand All @@ -346,6 +332,16 @@ func DiscordQueueSend(data []kitsu.MessagePayload, conf config.Config, webhookUR
}

func main() {
slog.Configure(func(logger *slog.SugaredLogger) {
f := logger.Formatter.(*slog.TextFormatter)
f.EnableColor = true
f.SetTemplate("[{{datetime}}] [{{level}}] [{{caller}}]\t{{message}} {{data}} {{extra}}\n")
f.ColorTheme = slog.ColorTheme
})

h1 := handler.MustFileHandler("./logs/all-levels.log", handler.WithLogLevels(slog.AllLevels))
slog.PushHandler(h1)

start := time.Now()

// Load config
Expand All @@ -361,17 +357,19 @@ func main() {
Logger: logger.Default.LogMode(logger.Silent),
})
if err != nil {
panic("failed to connect database")
slog.Fatal("failed to connect database")
os.Exit(0)
}
db.AutoMigrate(&model.Task{})

if conf.Log {
log.Printf("Connected to database in %s", time.Since(start))
slog.Info("Connected to database in %s", time.Since(start))

if _, err := os.Stat("./dump"); os.IsNotExist(err) {
err := os.Mkdir("./dump", os.ModeDir)
if err != nil {
panic("failed to create dir")
slog.Fatal("failed to create dir")
os.Exit(0)
}
}
}
Expand All @@ -385,42 +383,42 @@ func main() {
token := basicauth.AuthForJWTToken(conf.Kitsu.Hostname+"api/auth/login", conf.Kitsu.Email, conf.Kitsu.Password)
os.Setenv("KitsuJWTToken", token)
if conf.Log {
log.Printf("Connected to Kitsu in %s", time.Since(start))
slog.Info("Connected to Kitsu in %s", time.Since(start))
}

c.AddFunc("@every 1h", func() {
token := basicauth.AuthForJWTToken(conf.Kitsu.Hostname+"api/auth/login", conf.Kitsu.Email, conf.Kitsu.Password)
os.Setenv("KitsuJWTToken", token)
if conf.Log {
fmt.Println("Got new Kitsu token")
slog.Info("Got new Kitsu token")
}
})

// Request data from Kitsu
kitsuResponse := MakeKitsuResponse(conf)
if conf.Log {
DumpToFile(kitsuResponse, "kitsu_response")
log.Printf("Done MakeKitsuResponse in %s", time.Since(start))
slog.Info("Done MakeKitsuResponse in %s", time.Since(start))
}

// Prepare messages to Discord
FilterTasks(kitsuResponse, conf, db)
if conf.Log {
log.Printf("Done FilterTasks in %s", time.Since(start))
slog.Info("Done FilterTasks in %s", time.Since(start))
}

c.AddFunc("@every "+strconv.Itoa(conf.Kitsu.RequestInterval)+"m", func() {
// Request data from Kitsu
kitsuResponse := MakeKitsuResponse(conf)
if conf.Log {
DumpToFile(kitsuResponse, "kitsu_response")
log.Printf("Done MakeKitsuResponse in %s", time.Since(start))
slog.Info("Done MakeKitsuResponse in %s", time.Since(start))
}

// Filter tasks
FilterTasks(kitsuResponse, conf, db)
if conf.Log {
log.Printf("Done FilterTasks in %s", time.Since(start))
slog.Info("Done FilterTasks in %s", time.Since(start))
}
})

Expand Down
12 changes: 6 additions & 6 deletions src/utils/basicauth/basicauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (
"bytes"
"encoding/json"
"io/ioutil"
"log"
"net/http"

"github.com/gookit/slog"
)

// Basic authentication for JWT token
Expand All @@ -33,7 +34,7 @@ func AuthForJWTToken(url, email, password string) string {
// Create request
req, err := http.NewRequest(http.MethodPost, url, requestBody)
if err != nil {
log.Fatalln(err)
slog.Fatal(err)
}

// Set content type
Expand All @@ -42,14 +43,14 @@ func AuthForJWTToken(url, email, password string) string {
// Fetch Request
resp, err := client.Do(req)
if err != nil {
log.Fatalln(err)
slog.Fatal(err)
}
defer resp.Body.Close()

// Read Response Body
respBody, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatalln(err)
slog.Fatal(err)
}

// Display Results
Expand All @@ -62,8 +63,7 @@ func AuthForJWTToken(url, email, password string) string {
var jwt Response
err = json.Unmarshal(respBody, &jwt)
if err != nil {
log.Fatalln("Error! Check your Kitsu credentials in conf.toml")
//log.Fatalln(err)
slog.Fatal("Error! Check your Kitsu credentials in conf.toml")
}

return jwt.Token
Expand Down
Loading

0 comments on commit efe4ebf

Please sign in to comment.