Skip to content

Commit 3660f23

Browse files
committed
add makefile and linter and gofumpt tools
1 parent ccae952 commit 3660f23

File tree

8 files changed

+1305
-53
lines changed

8 files changed

+1305
-53
lines changed

.golangci.goheader.template

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright © {{ copyright-year }} Meroxa, Inc.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

.golangci.yml

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
run:
2+
timeout: 5m
3+
4+
linters-settings:
5+
nolintlint:
6+
allow-unused: false # report any unused nolint directives
7+
require-explanation: true # require an explanation for nolint directives
8+
require-specific: true # require nolint directives to mention the specific linter being suppressed
9+
goconst:
10+
ignore-tests: true
11+
goheader:
12+
template-path: '.golangci.goheader.template'
13+
values:
14+
regexp:
15+
copyright-year: 20[2-9]\d
16+
wrapcheck:
17+
ignoreSigs:
18+
- .Errorf(
19+
- errors.New(
20+
- errors.Unwrap(
21+
- errors.Join(
22+
- .Wrap(
23+
- .Wrapf(
24+
- .WithMessage(
25+
- .WithMessagef(
26+
- .WithStack(
27+
- (context.Context).Err()
28+
29+
issues:
30+
exclude-rules:
31+
- path: _test\.go
32+
linters:
33+
- dogsled
34+
- gosec
35+
- gocognit
36+
- errcheck
37+
- forcetypeassert
38+
- funlen
39+
- dupl
40+
- maintidx
41+
42+
linters:
43+
# please, do not use `enable-all`: it's deprecated and will be removed soon.
44+
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
45+
disable-all: true
46+
enable:
47+
- asasalint
48+
- asciicheck
49+
- bidichk
50+
- bodyclose
51+
- containedctx
52+
- contextcheck
53+
- copyloopvar
54+
- decorder
55+
# - depguard
56+
- dogsled
57+
- dupl
58+
- dupword
59+
- durationcheck
60+
# - err113
61+
- errcheck
62+
- errchkjson
63+
- errname
64+
- errorlint
65+
- exhaustive
66+
# - forbidigo
67+
- forcetypeassert
68+
- funlen
69+
- gci
70+
- ginkgolinter
71+
- gocheckcompilerdirectives
72+
- gochecknoinits
73+
- gocognit
74+
- goconst
75+
- gocritic
76+
- godot
77+
- gofmt
78+
- gofumpt
79+
- goheader
80+
- goimports
81+
- gomoddirectives
82+
- goprintffuncname
83+
- gosec
84+
- gosimple
85+
- gosmopolitan
86+
- govet
87+
- grouper
88+
- importas
89+
- ineffassign
90+
- interfacebloat
91+
# - ireturn # Doesn't have correct support for generic types https://github.com/butuzov/ireturn/issues/37
92+
- loggercheck
93+
- maintidx
94+
- makezero
95+
- mirror
96+
- misspell
97+
- musttag
98+
- nakedret
99+
- nestif
100+
- nilerr
101+
- nilnil
102+
- noctx
103+
- nolintlint
104+
- nosprintfhostport
105+
- prealloc
106+
- predeclared
107+
- promlinter
108+
- reassign
109+
- revive
110+
- rowserrcheck
111+
- sqlclosecheck
112+
- staticcheck
113+
- stylecheck
114+
- testableexamples
115+
- thelper
116+
- unconvert
117+
# - unparam
118+
- unused
119+
- usestdlibvars
120+
- usetesting
121+
- wastedassign
122+
- whitespace
123+
- wrapcheck
124+
- zerologlint

Makefile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.PHONY: test
2+
test:
3+
go test $(GOTEST_FLAGS) -race ./...
4+
5+
.PHONY: lint
6+
lint:
7+
go tool golangci-lint run
8+
9+
.PHONY: fmt
10+
fmt:
11+
go tool gofumpt -l -w .
12+
13+
.PHONY: install-tools
14+
install-tools:
15+
go mod tidy
16+
17+
.PHONY: generate
18+
generate:
19+
go generate ./...
20+

config/config.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ type ServiceConfig struct {
2828
DockerCompose string `yaml:"docker-compose"`
2929
}
3030

31-
type Infrastructure map[string]ServiceConfig
32-
type Tools map[string]ServiceConfig
31+
type (
32+
Infrastructure map[string]ServiceConfig
33+
Tools map[string]ServiceConfig
34+
)
3335

3436
type MetricsCollector struct {
3537
Collector string `yaml:"collector"`

dockerutil/down.go

+28-28
Original file line numberDiff line numberDiff line change
@@ -27,44 +27,44 @@ import (
2727
//
2828
// Returns error if the compose command fails.
2929
func ComposeDown(ctx context.Context, composeOpt ComposeOptions, downOpt DownOptions) error {
30-
cmd := downCmd(ctx, composeOpt, downOpt)
31-
return Exec(cmd)
30+
cmd := downCmd(ctx, composeOpt, downOpt)
31+
return Exec(cmd)
3232
}
3333

3434
// DownOptions represents the options for the down command.
3535
type DownOptions struct {
36-
DryRun *bool // --dry-run Execute command in dry run mode
37-
RemoveOrphans *bool // --remove-orphans Remove containers for services not defined in the Compose file
38-
Rmi *string // --rmi string Remove images used by services. "local" remove only images that don't have a custom tag ("local"|"all")
39-
Timeout *int // -t, --timeout int Specify a shutdown timeout in seconds
40-
Volumes *bool // -v, --volumes Remove named volumes declared in the "volumes" section
36+
DryRun *bool // --dry-run Execute command in dry run mode
37+
RemoveOrphans *bool // --remove-orphans Remove containers for services not defined in the Compose file
38+
Rmi *string // --rmi string Remove images used by services. "local" remove only images that don't have a custom tag ("local"|"all")
39+
Timeout *int // -t, --timeout int Specify a shutdown timeout in seconds
40+
Volumes *bool // -v, --volumes Remove named volumes declared in the "volumes" section
4141
}
4242

4343
func (opt DownOptions) flags() []string {
44-
var flags []string
45-
if opt.DryRun != nil && *opt.DryRun {
46-
flags = append(flags, "--dry-run")
47-
}
48-
if opt.RemoveOrphans != nil && *opt.RemoveOrphans {
49-
flags = append(flags, "--remove-orphans")
50-
}
51-
if opt.Rmi != nil {
52-
flags = append(flags, "--rmi", *opt.Rmi)
53-
}
54-
if opt.Timeout != nil {
55-
flags = append(flags, "-t", fmt.Sprintf("%d", *opt.Timeout))
56-
}
57-
if opt.Volumes != nil && *opt.Volumes {
58-
flags = append(flags, "-v")
59-
}
60-
return flags
44+
var flags []string
45+
if opt.DryRun != nil && *opt.DryRun {
46+
flags = append(flags, "--dry-run")
47+
}
48+
if opt.RemoveOrphans != nil && *opt.RemoveOrphans {
49+
flags = append(flags, "--remove-orphans")
50+
}
51+
if opt.Rmi != nil {
52+
flags = append(flags, "--rmi", *opt.Rmi)
53+
}
54+
if opt.Timeout != nil {
55+
flags = append(flags, "-t", fmt.Sprintf("%d", *opt.Timeout))
56+
}
57+
if opt.Volumes != nil && *opt.Volumes {
58+
flags = append(flags, "-v")
59+
}
60+
return flags
6161
}
6262

6363
func downCmd(ctx context.Context, composeOpt ComposeOptions, downOpt DownOptions) *exec.Cmd {
64-
cmd := composeCmd(ctx, composeOpt)
64+
cmd := composeCmd(ctx, composeOpt)
6565

66-
cmd.Args = append(cmd.Args, "down")
67-
cmd.Args = append(cmd.Args, downOpt.flags()...)
66+
cmd.Args = append(cmd.Args, "down")
67+
cmd.Args = append(cmd.Args, downOpt.flags()...)
6868

69-
return cmd
69+
return cmd
7070
}

0 commit comments

Comments
 (0)