Skip to content
This repository has been archived by the owner on Sep 6, 2022. It is now read-only.

Commit

Permalink
reduce linters to golang-ci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
minio-trusted committed May 11, 2021
1 parent 2b44798 commit 2e79efa
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 77 deletions.
30 changes: 30 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
linters-settings:
golint:
min-confidence: 0

misspell:
locale: US

linters:
disable-all: true
enable:
- typecheck
- goimports
- misspell
- govet
- golint
- ineffassign
- gosimple
- deadcode
- structcheck
- gomodguard
- gofmt

issues:
exclude-use-default: false
exclude:
- should have a package comment
- error strings should not be capitalized or end with punctuation or a newline

service:
golangci-lint-version: 1.20.0 # use the fixed version to not introduce new linters unexpectedly
38 changes: 6 additions & 32 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ ifeq ($(GOOS),'darwin')
GOOSALT = 'mac'
endif


BUILD_LDFLAGS := '$(LDFLAGS)'

all: build
Expand All @@ -19,42 +18,17 @@ checks:

getdeps:
@mkdir -p ${GOPATH}/bin
@which golint 1>/dev/null || (echo "Installing golint" && go get -u golang.org/x/lint/golint)
@which staticcheck 1>/dev/null || (echo "Installing staticcheck" && wget --quiet -O ${GOPATH}/bin/staticcheck https://github.com/dominikh/go-tools/releases/download/2019.1/staticcheck_linux_amd64 && chmod +x ${GOPATH}/bin/staticcheck)
@which misspell 1>/dev/null || (echo "Installing misspell" && wget --quiet https://github.com/client9/misspell/releases/download/v0.3.4/misspell_0.3.4_${GOOSALT}_64bit.tar.gz && tar xf misspell_0.3.4_${GOOSALT}_64bit.tar.gz && mv misspell ${GOPATH}/bin/misspell && chmod +x ${GOPATH}/bin/misspell && rm -f misspell_0.3.4_${GOOSALT}_64bit.tar.gz)
@which golangci-lint 1>/dev/null || (echo "Installing golangci-lint" && curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v1.27.0)

crosscompile:
@(env bash $(PWD)/buildscripts/cross-compile.sh)

verifiers: getdeps vet fmt lint staticcheck spelling

vet:
@echo "Running $@"
@GO111MODULE=on go vet github.com/minio/minfs/...

fmt:
@echo "Running $@"
@GO111MODULE=on gofmt -d cmd/
@GO111MODULE=on gofmt -d fs/
@GO111MODULE=on gofmt -d meta/
verifiers: getdeps lint

lint:
@echo "Running $@"
@GO111MODULE=on ${GOPATH}/bin/golint -set_exit_status github.com/minio/minfs/cmd/...
@GO111MODULE=on ${GOPATH}/bin/golint -set_exit_status github.com/minio/minfs/fs/...
@GO111MODULE=on ${GOPATH}/bin/golint -set_exit_status github.com/minio/minfs/meta/...

staticcheck:
@echo "Running $@"
@GO111MODULE=on ${GOPATH}/bin/staticcheck github.com/minio/minfs/cmd/...
@GO111MODULE=on ${GOPATH}/bin/staticcheck github.com/minio/minfs/fs/...
@GO111MODULE=on ${GOPATH}/bin/staticcheck github.com/minio/minfs/meta/...

spelling:
@GO111MODULE=on ${GOPATH}/bin/misspell -locale US -error `find cmd/`
@GO111MODULE=on ${GOPATH}/bin/misspell -locale US -error `find fs/`
@GO111MODULE=on ${GOPATH}/bin/misspell -locale US -error `find meta/`
@GO111MODULE=on ${GOPATH}/bin/misspell -locale US -error `find docs/`
@echo "Running $@ check"
@GO111MODULE=on ${GOPATH}/bin/golangci-lint cache clean
@GO111MODULE=on ${GOPATH}/bin/golangci-lint run --build-tags kqueue --timeout=10m --config ./.golangci.yml

test: verifiers build
@echo "Running unit tests"
Expand All @@ -67,7 +41,7 @@ coverage: build
# Builds mc locally.
build: checks
@echo "Building minfs binary to './minfs'"
@GO111MODULE=on GO_FLAGS="" CGO_ENABLED=0 go build -tags kqueue --ldflags $(BUILD_LDFLAGS) -o $(PWD)/minfs
@GO111MODULE=on CGO_ENABLED=0 go build -tags kqueue --ldflags $(BUILD_LDFLAGS) -o $(PWD)/minfs

# Builds MinFS and installs it to $GOPATH/bin.
install: build
Expand Down
16 changes: 8 additions & 8 deletions buildscripts/gen-ldflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,24 @@ import (

func genLDFlags(version string) string {
ldflagsStr := "-s -w"
ldflagsStr += " -X github.com/minio/minio/cmd.Version=" + version
ldflagsStr += " -X github.com/minio/minio/cmd.ReleaseTag=" + releaseTag(version)
ldflagsStr += " -X github.com/minio/minio/cmd.CommitID=" + commitID()
ldflagsStr += " -X github.com/minio/minio/cmd.ShortCommitID=" + commitID()[:12]
ldflagsStr += " -X github.com/minio/minio/cmd.GOPATH=" + os.Getenv("GOPATH")
ldflagsStr += " -X github.com/minio/minio/cmd.GOROOT=" + os.Getenv("GOROOT")
ldflagsStr += " -X github.com/minio/minfs/cmd.Version=" + version
ldflagsStr += " -X github.com/minio/minfs/cmd.ReleaseTag=" + releaseTag(version)
ldflagsStr += " -X github.com/minio/minfs/cmd.CommitID=" + commitID()
ldflagsStr += " -X github.com/minio/minfs/cmd.ShortCommitID=" + commitID()[:12]
ldflagsStr += " -X github.com/minio/minfs/cmd.GOPATH=" + os.Getenv("GOPATH")
ldflagsStr += " -X github.com/minio/minfs/cmd.GOROOT=" + os.Getenv("GOROOT")
return ldflagsStr
}

// genReleaseTag prints release tag to the console for easy git tagging.
func releaseTag(version string) string {
relPrefix := "DEVELOPMENT"
if prefix := os.Getenv("MINIO_RELEASE"); prefix != "" {
if prefix := os.Getenv("MINFS_RELEASE"); prefix != "" {
relPrefix = prefix
}

relSuffix := ""
if hotfix := os.Getenv("MINIO_HOTFIX"); hotfix != "" {
if hotfix := os.Getenv("MINFS_HOTFIX"); hotfix != "" {
relSuffix = hotfix
}

Expand Down
63 changes: 28 additions & 35 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,40 +57,10 @@ FLAGS:
{{range .Flags}}{{.}}
{{end}}{{end}}
VERSION:
` + Version +
`{{ "\n"}}` +
`
COMMITID:
` + CommitID +
`{{ "\n"}}`

// Main is the actual run function
func Main(args []string) {
// Enable profiling supported modes are [cpu, mem, block].
/*
switch os.Getenv("MINFS_PROFILER") {
case "cpu":
defer profile.Start(profile.CPUProfile, profile.ProfilePath(mustGetProfileDir())).Stop()
case "mem":
defer profile.Start(profile.MemProfile, profile.ProfilePath(mustGetProfileDir())).Stop()
case "block":
defer profile.Start(profile.BlockProfile, profile.ProfilePath(mustGetProfileDir())).Stop()
}
*/

// Options:
// -- debug
// -- bucket
// -- target
// -- permissions
// -- uid / gid

// Set up app.
cli.HelpFlag = cli.BoolFlag{
Name: "help, h",
Usage: "show help",
}
` + Version + `{{ "\n"}}`

// NewApp initializes CLI framework for minfs.
func NewApp() *cli.App {
app := cli.NewApp()
app.HideHelpCommand = true
app.Name = "minfs"
Expand All @@ -101,8 +71,7 @@ func Main(args []string) {
app.Flags = append(minfsFlags, globalFlags...)
app.CustomAppHelpTemplate = minfsHelpTemplate
app.Before = func(c *cli.Context) error {
_, err := minfs.InitMinFSConfig()
if err != nil {
if _, err := minfs.InitMinFSConfig(); err != nil {
return fmt.Errorf("Unable to initialize minfs config %s", err)
}
if !c.Args().Present() {
Expand Down Expand Up @@ -163,6 +132,30 @@ func Main(args []string) {
return nil
}

return app
}

// Main is the actual run function
func Main(app *cli.App, args []string) {
// Enable profiling supported modes are [cpu, mem, block].
/*
switch os.Getenv("MINFS_PROFILER") {
case "cpu":
defer profile.Start(profile.CPUProfile, profile.ProfilePath(mustGetProfileDir())).Stop()
case "mem":
defer profile.Start(profile.MemProfile, profile.ProfilePath(mustGetProfileDir())).Stop()
case "block":
defer profile.Start(profile.BlockProfile, profile.ProfilePath(mustGetProfileDir())).Stop()
}
*/

// Options:
// -- debug
// -- bucket
// -- target
// -- permissions
// -- uid / gid

// Run the app - exit on error.
if err := app.Run(args); err != nil {
log.Fatalln(err)
Expand Down
1 change: 0 additions & 1 deletion fs/globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package minfs

// Package cmd contains all the global variables and constants.
const (
globalConfigDir = "/etc/minfs"
globalConfigFile = "/etc/minfs/config.json"
globalDBDir = "/etc/minfs/db"
globalLogFile = "/var/log/minfs.log"
Expand Down
11 changes: 10 additions & 1 deletion minfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ import (
)

func main() {
app := minfs.NewApp()
if len(os.Args) == 1 || (len(os.Args) == 2 && (os.Args[1] == "--help" || os.Args[1] == "--version" ||
os.Args[1] == "-h" || os.Args[1] == "-v")) {
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
return
}

dctx := &daemon.Context{
PidFileName: "/var/log/minfs.pid",
PidFilePerm: 0644,
Expand All @@ -44,5 +53,5 @@ func main() {
defer dctx.Release()

// daemon business logic starts here
minfs.Main(os.Args)
minfs.Main(app, os.Args)
}

0 comments on commit 2e79efa

Please sign in to comment.