Skip to content

Commit

Permalink
feat: add golangci setup and others
Browse files Browse the repository at this point in the history
  • Loading branch information
lpsm-dev committed Oct 4, 2022
1 parent befebda commit f7af46f
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 30 deletions.
24 changes: 24 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ help:
setup:
@echo "==> Setup..."
$(GO) mod download
$(GO) mod tidy
$(GO) generate -v ./...
@echo ""

Expand Down
2 changes: 1 addition & 1 deletion commands/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
11 changes: 4 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand All @@ -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=
Expand Down Expand Up @@ -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=
Expand All @@ -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=
Expand Down Expand Up @@ -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=
4 changes: 2 additions & 2 deletions internal/cli/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cli
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net/http"

"github.com/ci-monk/loli/internal/consts"
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:staticcheck // SA1019 ignore this!
package cli

import (
Expand Down
9 changes: 4 additions & 5 deletions internal/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httputil"
"os"
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -68,5 +67,5 @@ func DumpResponse(res *http.Response) {
Println("========================= END DumpResponse =========================")
Println("")

res.Body = ioutil.NopCloser(body)
res.Body = io.NopCloser(body)
}
12 changes: 7 additions & 5 deletions internal/trace/search_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"os"
Expand All @@ -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: "
Expand Down Expand Up @@ -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()

Expand Down
13 changes: 8 additions & 5 deletions internal/trace/search_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -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: "
Expand All @@ -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()

Expand Down
9 changes: 6 additions & 3 deletions internal/trace/search_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package trace
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"strconv"
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion internal/trace/signals.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ func catchInterrupt(s *spinner.Spinner) {
s.Stop()
}

termenv.ShowCursor()
termenv.DefaultOutput().ShowCursor()
os.Exit(0)
}

0 comments on commit f7af46f

Please sign in to comment.