Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: add fmt, lint, vulncheck to improve code readability and security #21

Merged
merged 1 commit into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.goreleaser.yaml
.idea/
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,22 @@ migrate-up-docker:
build:
go build -o gpodder2go main.go
.PHONY: build

# https://github.com/mvdan/gofumpt
# https://pkg.go.dev/golang.org/x/tools/cmd/goimports
fmt:
go mod tidy
gofumpt -l -w .
goimports -w .
.PHONY: fmt

# https://golangci-lint.run/
lint:
go vet ./...
golangci-lint run --disable errcheck --enable sqlclosecheck --enable misspell --enable gofmt --enable goimports
.PHONY: lint

# https://go.dev/blog/vuln
vulncheck:
govulncheck ./...
.PHONY: vulncheck
2 changes: 0 additions & 2 deletions cmd/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"github.com/spf13/cobra"
)

var apiAddr string

func init() {
rootCmd.AddCommand(accountsCmd)
}
Expand Down
6 changes: 2 additions & 4 deletions cmd/accounts_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package cmd
import (
"log"

"github.com/oxtyped/gpodder2go/pkg/data"
"github.com/spf13/cobra"

"github.com/oxtyped/gpodder2go/pkg/data"
)

var password, email, name string
Expand All @@ -17,7 +18,6 @@ func init() {
accountsCreateCmd.MarkFlagRequired("password")
accountsCreateCmd.MarkFlagRequired("email")
accountsCreateCmd.MarkFlagRequired("name")

}

var accountsCreateCmd = &cobra.Command{
Expand All @@ -35,7 +35,5 @@ var accountsCreateCmd = &cobra.Command{
}

log.Printf("😍 User %s created!", username)
return

},
}
1 change: 0 additions & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ var initCmd = &cobra.Command{
Use: "init",
Short: "Setup the necessary environments",
Run: func(cmd *cobra.Command, args []string) {

// create sqlite file
// run migration file
db, err := sql.Open("sqlite", database)
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ var rootCmd = &cobra.Command{

func init() {
rootCmd.PersistentFlags().StringVarP(&database, "database", "d", "g2g.db", "filename of sqlite3 database to use")

}

func Execute() error {
return rootCmd.Execute()
}
13 changes: 7 additions & 6 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@ import (

"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"

"github.com/oxtyped/gpodder2go/pkg/apis"
"github.com/oxtyped/gpodder2go/pkg/data"
"github.com/oxtyped/gpodder2go/pkg/store"

m2 "github.com/oxtyped/gpodder2go/pkg/middleware"
"github.com/spf13/cobra"

m2 "github.com/oxtyped/gpodder2go/pkg/middleware"
)

var addr string
var noAuth bool
var (
addr string
noAuth bool
)

func init() {
serveCmd.Flags().StringVarP(&addr, "addr", "b", "localhost:3005", "ip:port for server to be binded to")
Expand All @@ -29,7 +33,6 @@ var serveCmd = &cobra.Command{
Use: "serve",
Short: "Start gpodder2go server",
Run: func(cmd *cobra.Command, args []string) {

verifierSecretKey := os.Getenv("VERIFIER_SECRET_KEY")

if verifierSecretKey == "" {
Expand Down Expand Up @@ -82,7 +85,6 @@ var serveCmd = &cobra.Command{

r.Get("/", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
return
})
})

Expand All @@ -91,6 +93,5 @@ var serveCmd = &cobra.Command{
if err != nil {
log.Fatal(err)
}

},
}
40 changes: 38 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/oxtyped/gpodder2go

go 1.16
go 1.22

require (
github.com/augurysys/timestamp v0.2.0
Expand All @@ -11,6 +11,42 @@ require (
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.4.0
golang.org/x/text v0.3.8 // indirect
modernc.org/sqlite v1.26.0
)

require (
github.com/PuerkitoBio/goquery v1.5.1 // indirect
github.com/andybalholm/cascadia v1.1.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mmcdole/gofeed v1.1.3 // indirect
github.com/mmcdole/goxpp v0.0.0-20181012175147-0068e33feabf // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.mongodb.org/mongo-driver v1.8.2 // indirect
go.uber.org/atomic v1.7.0 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/net v0.13.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/tools v0.6.0 // indirect
lukechampine.com/uint128 v1.2.0 // indirect
modernc.org/cc/v3 v3.40.0 // indirect
modernc.org/ccgo/v3 v3.16.13 // indirect
modernc.org/libc v1.24.1 // indirect
modernc.org/mathutil v1.5.0 // indirect
modernc.org/memory v1.6.0 // indirect
modernc.org/opt v0.1.3 // indirect
modernc.org/strutil v1.1.3 // indirect
modernc.org/token v1.0.1 // indirect
)
Loading