diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..4b8d496 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,24 @@ + + +run: + timeout: 10m + skip-dirs: + - vendor$ + tests: true + skip-dirs-use-default: false +linters: + enable-all: false + enable: + - errcheck + - gosimple + - govet + - gofmt + - goimports + - ineffassign + - typecheck + - stylecheck + - unused + - misspell + - whitespace + disable: + - deadcode diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index db8e94a..854dc40 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,3 +21,12 @@ repos: hooks: - id: hadolint args: ["--config", ".github/config/.hadolint.yaml"] + - repo: local + hooks: + - id: go-setup + name: Go Setup + language: system + entry: make + args: ["setup"] + types: ["go"] + pass_filenames: false diff --git a/Dockerfile b/Dockerfile index 0ea2143..1d6fa02 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.19.1-alpine3.15 as builder +FROM golang:1.19.1-alpine3.16 as builder WORKDIR /app COPY go.mod go.sum ./ RUN go mod download diff --git a/Makefile b/Makefile index bc21561..c4bee25 100644 --- a/Makefile +++ b/Makefile @@ -82,6 +82,7 @@ help: setup: @echo "==> Setup..." $(GO) mod download + $(GO) mod tidy $(GO) generate -v ./... @echo "" diff --git a/commands/completion.go b/commands/completion.go index f498ca5..fff9a44 100644 --- a/commands/completion.go +++ b/commands/completion.go @@ -22,7 +22,7 @@ var completionCmd = &cobra.Command{ return nil }, RunE: func(cmd *cobra.Command, args []string) error { - var shellType string = args[0] + shellType := args[0] out, rootCmd := os.Stdout, cmd.Parent() switch shellType { case "bash": diff --git a/go.sum b/go.sum index d3218dd..9985039 100644 --- a/go.sum +++ b/go.sum @@ -8,8 +8,8 @@ github.com/MarvinJWendt/testza v0.2.8/go.mod h1:nwIcjmr0Zz+Rcwfh3/4UhBp7ePKVhuBE github.com/MarvinJWendt/testza v0.2.10/go.mod h1:pd+VWsoGUiFtq+hRKSU1Bktnn+DMCSrDrXDpX2bG66k= github.com/MarvinJWendt/testza v0.2.12/go.mod h1:JOIegYyV7rX+7VZ9r77L/eH6CfJHHzXjB69adAhzZkI= github.com/MarvinJWendt/testza v0.3.0/go.mod h1:eFcL4I0idjtIx8P9C6KkAuLgATNKpX4/2oUqKc6bF2c= -github.com/MarvinJWendt/testza v0.4.2 h1:Vbw9GkSB5erJI2BPnBL9SVGV9myE+XmUSFahBGUhW2Q= github.com/MarvinJWendt/testza v0.4.2/go.mod h1:mSdhXiKH8sg/gQehJ63bINcCKp7RtYewEjXsvsVUPbE= +github.com/MarvinJWendt/testza v0.4.3 h1:u2XaM4IqGp9dsdUmML8/Z791fu4yjQYzOiufOtJwTII= github.com/alecthomas/chroma v0.10.0 h1:7XDcGkCQopCNKjZHfYrNLraA+M7e0fMiJ/Mfikbfjek= github.com/alecthomas/chroma v0.10.0/go.mod h1:jtJATyUxlIORhUOFNA9NZDWGAQ8wpxQQqNSB4rjA/1s= github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= @@ -54,7 +54,6 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQHCoQ= -github.com/gookit/color v1.5.0 h1:1Opow3+BWDwqor78DcJkJCIwnkviFi+rrOANki9BUFw= github.com/gookit/color v1.5.0/go.mod h1:43aQb+Zerm/BWh2GnrgOQm7ffz7tvQXEKV6BFMl7wAo= github.com/gookit/color v1.5.2 h1:uLnfXcaFjlrDnQDT+NCBcfhrXqYTx/rcCa6xn01Y8yI= github.com/gookit/color v1.5.2/go.mod h1:w8h4bGiHeeBpvQVePTutdbERIUf3oJE5lZ8HM0UgXyg= @@ -71,8 +70,8 @@ github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALr github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.0.10/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c= -github.com/klauspost/cpuid/v2 v2.0.12 h1:p9dKCg8i4gmOxtv35DvrYoWqYzQrvEVdjQ762Y0OqZE= github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c= +github.com/klauspost/cpuid/v2 v2.1.0 h1:eyi1Ad2aNJMW95zcSbmGg7Cg6cq3ADwLpMAP96d8rF0= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= @@ -127,8 +126,6 @@ github.com/pterm/pterm v0.12.31/go.mod h1:32ZAWZVXD7ZfG0s8qqHXePte42kdz8ECtRyEej github.com/pterm/pterm v0.12.33/go.mod h1:x+h2uL+n7CP/rel9+bImHD5lF3nM9vJj80k9ybiiTTE= github.com/pterm/pterm v0.12.36/go.mod h1:NjiL09hFhT/vWjQHSj1athJpx6H8cjpHXNAK5bUw8T8= github.com/pterm/pterm v0.12.40/go.mod h1:ffwPLwlbXxP+rxT0GsgDTzS3y3rmpAO1NMjUkGTYf8s= -github.com/pterm/pterm v0.12.46 h1:7W//n3UldGXI2s+IFRV9GucNsbqex3MG/sibNm/62ag= -github.com/pterm/pterm v0.12.46/go.mod h1:hJgLlBafm45w/Hr0dKXxY//POD7CgowhePaG1sdPNBg= github.com/pterm/pterm v0.12.47 h1:vYTGddJqOldexC5TzlN4UT3HC4gw9eBaYJrVcqe1UJA= github.com/pterm/pterm v0.12.47/go.mod h1:D4OBoWNqAfXkm5QLTjIgjNiMXPHemLJHnIreGUsWzWg= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= @@ -148,9 +145,9 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= @@ -218,6 +215,6 @@ gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/cli/asset.go b/internal/cli/asset.go index 2f2bfc9..d375271 100644 --- a/internal/cli/asset.go +++ b/internal/cli/asset.go @@ -3,7 +3,7 @@ package cli import ( "bytes" "fmt" - "io/ioutil" + "io" "net/http" "github.com/ci-monk/loli/internal/consts" @@ -34,7 +34,7 @@ func (a *Asset) download() (*bytes.Reader, error) { log.Fatalf("Bad status code - %d", resp.StatusCode) } - content, err := ioutil.ReadAll(resp.Body) + content, err := io.ReadAll(resp.Body) if err != nil { log.Errorf("%s", err) return nil, err diff --git a/internal/cli/cli.go b/internal/cli/cli.go index caaefcc..519217d 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -1,3 +1,4 @@ +//nolint:staticcheck // SA1019 ignore this! package cli import ( diff --git a/internal/debug/debug.go b/internal/debug/debug.go index bac7198..746786a 100644 --- a/internal/debug/debug.go +++ b/internal/debug/debug.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "net/http" "net/http/httputil" "os" @@ -33,7 +32,7 @@ func DumpRequest(req *http.Request) { var bodyCopy bytes.Buffer body := io.TeeReader(req.Body, &bodyCopy) - req.Body = ioutil.NopCloser(body) + req.Body = io.NopCloser(body) dump, err := httputil.DumpRequest(req, req.ContentLength > 0) if err != nil { @@ -45,7 +44,7 @@ func DumpRequest(req *http.Request) { Println("========================= END DumpRequest =========================") Println("") - req.Body = ioutil.NopCloser(&bodyCopy) + req.Body = io.NopCloser(&bodyCopy) } // DumpResponse dumps out the provided http.Response @@ -56,7 +55,7 @@ func DumpResponse(res *http.Response) { var bodyCopy bytes.Buffer body := io.TeeReader(res.Body, &bodyCopy) - res.Body = ioutil.NopCloser(body) + res.Body = io.NopCloser(body) dump, err := httputil.DumpResponse(res, res.ContentLength > 0) if err != nil { @@ -68,5 +67,5 @@ func DumpResponse(res *http.Response) { Println("========================= END DumpResponse =========================") Println("") - res.Body = ioutil.NopCloser(body) + res.Body = io.NopCloser(body) } diff --git a/internal/trace/search_file.go b/internal/trace/search_file.go index a5bc5a0..2c3b9c3 100644 --- a/internal/trace/search_file.go +++ b/internal/trace/search_file.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "mime/multipart" "net/http" "os" @@ -28,8 +27,8 @@ func SearchAnimeByFile(animeFile string, pretty bool) { searchURL := consts.TraceMoeSearchAnimeByFile log.Infoln(searchURL) - termenv.HideCursor() - defer termenv.ShowCursor() + termenv.DefaultOutput().HideCursor() + defer termenv.DefaultOutput().ShowCursor() s := spinner.New(spinner.CharSets[39], 100*time.Millisecond) s.Prefix = "🌊 Searching for the anime from an image: " @@ -72,13 +71,16 @@ func SearchAnimeByFile(animeFile string, pretty bool) { log.Fatalf("Bad status code - %d", resp.StatusCode) } - content, err := ioutil.ReadAll(resp.Body) + content, err := io.ReadAll(resp.Body) if err != nil { log.Fatalln(err) } var animeResp types.Response - json.Unmarshal(content, &animeResp) + err = json.Unmarshal(content, &animeResp) + if err != nil { + log.Fatalln(err) + } s.Stop() diff --git a/internal/trace/search_link.go b/internal/trace/search_link.go index 780a3ab..41e4db1 100644 --- a/internal/trace/search_link.go +++ b/internal/trace/search_link.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "os" @@ -34,8 +34,8 @@ func SearchAnimeByLink(animeLink string, pretty bool) { log.Error("Invalid url") } - termenv.HideCursor() - defer termenv.ShowCursor() + termenv.DefaultOutput().HideCursor() + defer termenv.DefaultOutput().ShowCursor() s := spinner.New(spinner.CharSets[39], 100*time.Millisecond) s.Prefix = "🌊 Searching for the anime from a link: " @@ -60,13 +60,16 @@ func SearchAnimeByLink(animeLink string, pretty bool) { log.Fatalf("Bad status code - %d", resp.StatusCode) } - content, err := ioutil.ReadAll(resp.Body) + content, err := io.ReadAll(resp.Body) if err != nil { log.Fatalln(err) } var animeResp types.Response - json.Unmarshal(content, &animeResp) + err = json.Unmarshal(content, &animeResp) + if err != nil { + log.Fatalln(err) + } s.Stop() diff --git a/internal/trace/search_usage.go b/internal/trace/search_usage.go index 09be98d..0c43c5e 100644 --- a/internal/trace/search_usage.go +++ b/internal/trace/search_usage.go @@ -3,7 +3,7 @@ package trace import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "os" "strconv" @@ -30,13 +30,16 @@ func SearchUsage(pretty bool) { log.Fatalf("Bad status code - %d", resp.StatusCode) } - content, err := ioutil.ReadAll(resp.Body) + content, err := io.ReadAll(resp.Body) if err != nil { log.Fatalln(err) } var usageResp types.UsageTraceMoe - json.Unmarshal(content, &usageResp) + err = json.Unmarshal(content, &usageResp) + if err != nil { + log.Fatalln(err) + } if pretty { versionTable := table.NewWriter() diff --git a/internal/trace/signals.go b/internal/trace/signals.go index b255027..5520515 100644 --- a/internal/trace/signals.go +++ b/internal/trace/signals.go @@ -20,6 +20,6 @@ func catchInterrupt(s *spinner.Spinner) { s.Stop() } - termenv.ShowCursor() + termenv.DefaultOutput().ShowCursor() os.Exit(0) }