Skip to content

Commit f89fe8d

Browse files
committed
format code with golines
1 parent ebd11e2 commit f89fe8d

15 files changed

+262
-175
lines changed

.golangci.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ linters:
99
- durationcheck
1010
- errcheck
1111
- errorlint
12-
- exportloopref
1312
- gci
1413
- gofmt
1514
- gofumpt

.toolbox.mk

+20-4
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,41 @@ $(TB_LOCALBIN):
1010

1111
## Tool Binaries
1212
TB_GINKGO ?= $(TB_LOCALBIN)/ginkgo
13+
TB_GOFUMPT ?= $(TB_LOCALBIN)/gofumpt
1314
TB_GOLANGCI_LINT ?= $(TB_LOCALBIN)/golangci-lint
15+
TB_GOLINES ?= $(TB_LOCALBIN)/golines
1416
TB_GORELEASER ?= $(TB_LOCALBIN)/goreleaser
1517
TB_HELM_DOCS ?= $(TB_LOCALBIN)/helm-docs
1618
TB_MOCKGEN ?= $(TB_LOCALBIN)/mockgen
1719
TB_SEMVER ?= $(TB_LOCALBIN)/semver
1820

1921
## Tool Versions
20-
TB_GINKGO_VERSION ?= v2.20.2
21-
TB_GOLANGCI_LINT_VERSION ?= v1.61.0
22-
TB_GORELEASER_VERSION ?= v2.3.2
22+
TB_GINKGO_VERSION ?= v2.22.1
23+
TB_GOFUMPT_VERSION ?= v0.7.0
24+
TB_GOLANGCI_LINT_VERSION ?= v1.62.2
25+
TB_GOLINES_VERSION ?= v0.12.2
26+
TB_GORELEASER_VERSION ?= v2.5.0
2327
TB_HELM_DOCS_VERSION ?= v1.14.2
24-
TB_MOCKGEN_VERSION ?= v0.4.0
28+
TB_MOCKGEN_VERSION ?= v0.5.0
2529
TB_SEMVER_VERSION ?= v1.1.3
2630

2731
## Tool Installer
2832
.PHONY: tb.ginkgo
2933
tb.ginkgo: $(TB_GINKGO) ## Download ginkgo locally if necessary.
3034
$(TB_GINKGO): $(TB_LOCALBIN)
3135
test -s $(TB_LOCALBIN)/ginkgo || GOBIN=$(TB_LOCALBIN) go install github.com/onsi/ginkgo/v2/ginkgo@$(TB_GINKGO_VERSION)
36+
.PHONY: tb.gofumpt
37+
tb.gofumpt: $(TB_GOFUMPT) ## Download gofumpt locally if necessary.
38+
$(TB_GOFUMPT): $(TB_LOCALBIN)
39+
test -s $(TB_LOCALBIN)/gofumpt || GOBIN=$(TB_LOCALBIN) go install mvdan.cc/gofumpt@$(TB_GOFUMPT_VERSION)
3240
.PHONY: tb.golangci-lint
3341
tb.golangci-lint: $(TB_GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
3442
$(TB_GOLANGCI_LINT): $(TB_LOCALBIN)
3543
test -s $(TB_LOCALBIN)/golangci-lint || GOBIN=$(TB_LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(TB_GOLANGCI_LINT_VERSION)
44+
.PHONY: tb.golines
45+
tb.golines: $(TB_GOLINES) ## Download golines locally if necessary.
46+
$(TB_GOLINES): $(TB_LOCALBIN)
47+
test -s $(TB_LOCALBIN)/golines || GOBIN=$(TB_LOCALBIN) go install github.com/segmentio/golines@$(TB_GOLINES_VERSION)
3648
.PHONY: tb.goreleaser
3749
tb.goreleaser: $(TB_GORELEASER) ## Download goreleaser locally if necessary.
3850
$(TB_GORELEASER): $(TB_LOCALBIN)
@@ -55,7 +67,9 @@ $(TB_SEMVER): $(TB_LOCALBIN)
5567
tb.reset:
5668
@rm -f \
5769
$(TB_LOCALBIN)/ginkgo \
70+
$(TB_LOCALBIN)/gofumpt \
5871
$(TB_LOCALBIN)/golangci-lint \
72+
$(TB_LOCALBIN)/golines \
5973
$(TB_LOCALBIN)/goreleaser \
6074
$(TB_LOCALBIN)/helm-docs \
6175
$(TB_LOCALBIN)/mockgen \
@@ -66,7 +80,9 @@ tb.reset:
6680
tb.update: tb.reset
6781
toolbox makefile -f $(TB_LOCALDIR)/Makefile \
6882
github.com/onsi/ginkgo/v2/ginkgo \
83+
mvdan.cc/[email protected]/mvdan/gofumpt \
6984
github.com/golangci/golangci-lint/cmd/golangci-lint \
85+
github.com/segmentio/golines \
7086
github.com/goreleaser/goreleaser/v2 \
7187
github.com/norwoodj/helm-docs/cmd/helm-docs \
7288
go.uber.org/mock/[email protected]/uber-go/mock \

Makefile

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
# Include toolbox tasks
22
include ./.toolbox.mk
33

4-
# Run go fmt against code
5-
fmt: tb.golangci-lint
6-
$(TB_GOLANG_CI_LINT) run --fix
4+
lint: tb.golangci-lint
5+
$(TB_GOLANGCI_LINT) run --fix
76

87
# Run go mod tidy
98
tidy:
109
go mod tidy
1110

11+
fmt: tb.golines tb.gofumpt
12+
$(TB_GOLINES) --base-formatter="$(TB_GOFUMPT)" --max-len=120 --write-output .
13+
1214
# Run tests
1315
test: mocks tidy fmt helm-lint test-cover
1416
# Run coverage tests

main.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,12 @@ func main() {
6969
_ = setupRouter(coreClient, ssc, cfg, sealer).Run(fmt.Sprintf(":%d", cfg.Web.Port))
7070
}
7171

72-
func setupRouter(coreClient corev1.CoreV1Interface, ssClient ssClient.BitnamiV1alpha1Interface, cfg *config.Config, sealer seal.Sealer) *gin.Engine {
72+
func setupRouter(
73+
coreClient corev1.CoreV1Interface,
74+
ssClient ssClient.BitnamiV1alpha1Interface,
75+
cfg *config.Config,
76+
sealer seal.Sealer,
77+
) *gin.Engine {
7378
indexHTML, err := renderIndexHTML(cfg)
7479
if err != nil {
7580
log.Fatalf("Could not render the index html template: %s", err.Error())

main_test.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ var _ = Describe("Main", func() {
8787
req, _ := http.NewRequest("GET", "/api/secrets", nil)
8888
router.ServeHTTP(w, req)
8989
Ω(w.Code).Should(Equal(http.StatusOK))
90-
Ω(w.Body.String()).Should(Equal(fmt.Sprintf(`{"secrets":[{"namespace":"%s","name":"%s"}]}`, namespace, name)))
90+
Ω(
91+
w.Body.String(),
92+
).Should(Equal(fmt.Sprintf(`{"secrets":[{"namespace":"%s","name":"%s"}]}`, namespace, name)))
9193
})
9294

9395
It("list sealed secrets only for given namespaces", func() {
@@ -114,7 +116,9 @@ var _ = Describe("Main", func() {
114116
req, _ := http.NewRequest("GET", "/api/secrets", nil)
115117
router.ServeHTTP(w, req)
116118
Ω(w.Code).Should(Equal(http.StatusOK))
117-
Ω(w.Body.String()).Should(Equal(fmt.Sprintf(`{"secrets":[{"namespace":"%s","name":"%s"},{"namespace":"%s","name":"%s"}]}`, "a", name, "b", name)))
119+
Ω(
120+
w.Body.String(),
121+
).Should(Equal(fmt.Sprintf(`{"secrets":[{"namespace":"%s","name":"%s"},{"namespace":"%s","name":"%s"}]}`, "a", name, "b", name)))
118122
})
119123

120124
It("get secret from namespace by name", func() {

pkg/config/filter_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ var _ = Describe("Filter", func() {
9090
Ω(secretData["metadata"]).ShouldNot(HaveKey("resourceVersion"))
9191
Ω(secretData["metadata"]).ShouldNot(HaveKey("selfLink"))
9292
Ω(secretData["metadata"]).ShouldNot(HaveKey("uid"))
93-
Ω(SubMap(secretData, "metadata", "annotations")).ShouldNot(HaveKey("kubectl.kubernetes.io/last-applied-configuration"))
93+
Ω(
94+
SubMap(secretData, "metadata", "annotations"),
95+
).ShouldNot(HaveKey("kubectl.kubernetes.io/last-applied-configuration"))
9496
Ω(SubMap(secretData, "metadata", "annotations")).Should(HaveKey("foo"))
9597
})
9698
})

pkg/config/types.go

+52-14
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ func parse(f *flags) (*Config, error) {
2828
}
2929

3030
if *f.kubesealArgs != "" {
31-
log.Println("Argument 'kubeseal-arguments' is deprecated use (sealed-secrets-service-name, sealed-secrets-service-namespace or sealed-secrets-cert-url).")
31+
log.Println(
32+
"Argument 'kubeseal-arguments' is deprecated use (sealed-secrets-service-name, sealed-secrets-service-namespace or sealed-secrets-cert-url).",
33+
)
3234
}
3335
if *f.webExternalURL != "" {
3436
log.Println("Argument 'web-external-url' is deprecated use (web-context).")
@@ -145,18 +147,54 @@ type flags struct {
145147

146148
func newFlags() *flags {
147149
return &flags{
148-
disableLoadSecrets: flag.Bool("disable-load-secrets", false, "Disable the loading of existing secrets"),
149-
enableWebLogs: flag.Bool("enable-web-logs", false, "Enable web logs"),
150-
includeNamespaces: flag.String("include-namespaces", "", "Optional space separated list if namespaces to be included in the sealed secret search"),
151-
kubesealArgs: flag.String("kubeseal-arguments", "", "Deprecated use (sealed-secrets-service-name, sealed-secrets-service-namespace or sealed-secrets-cert-url)"),
152-
sealedSecretsServiceName: flag.String("sealed-secrets-service-name", "sealed-secrets", "Name of the sealed secrets service"),
153-
sealedSecretsServiceNamespace: flag.String("sealed-secrets-service-namespace", "sealed-secrets", "Namespace of the sealed secrets service"),
154-
sealedSecretsCertURL: flag.String("sealed-secrets-cert-url", "", "URL sealed secrets certificate (required if sealed secrets is not reachable with in cluster service)"),
155-
initialSecretFile: flag.String("initial-secret-file", "", "Define a file with the initial secret to be displayed. If empty, defaults are used."),
156-
webExternalURL: flag.String("web-external-url", "", "Deprecated use (web-context)"),
157-
webContext: flag.String("web-context", "/", "The context the application is running on. (for example, if it is served via a reverse proxy)"),
158-
printVersion: flag.Bool("version", false, "Print version information and exit"),
159-
port: flag.Int("port", 8080, "Define the port to run the application on. (default: 8080)"),
160-
config: flag.String("config", "", "Define the config file"),
150+
disableLoadSecrets: flag.Bool(
151+
"disable-load-secrets",
152+
false,
153+
"Disable the loading of existing secrets",
154+
),
155+
enableWebLogs: flag.Bool("enable-web-logs", false, "Enable web logs"),
156+
includeNamespaces: flag.String(
157+
"include-namespaces",
158+
"",
159+
"Optional space separated list if namespaces to be included in the sealed secret search",
160+
),
161+
kubesealArgs: flag.String(
162+
"kubeseal-arguments",
163+
"",
164+
"Deprecated use (sealed-secrets-service-name, sealed-secrets-service-namespace or sealed-secrets-cert-url)",
165+
),
166+
sealedSecretsServiceName: flag.String(
167+
"sealed-secrets-service-name",
168+
"sealed-secrets",
169+
"Name of the sealed secrets service",
170+
),
171+
sealedSecretsServiceNamespace: flag.String(
172+
"sealed-secrets-service-namespace",
173+
"sealed-secrets",
174+
"Namespace of the sealed secrets service",
175+
),
176+
sealedSecretsCertURL: flag.String(
177+
"sealed-secrets-cert-url",
178+
"",
179+
"URL sealed secrets certificate (required if sealed secrets is not reachable with in cluster service)",
180+
),
181+
initialSecretFile: flag.String(
182+
"initial-secret-file",
183+
"",
184+
"Define a file with the initial secret to be displayed. If empty, defaults are used.",
185+
),
186+
webExternalURL: flag.String("web-external-url", "", "Deprecated use (web-context)"),
187+
webContext: flag.String(
188+
"web-context",
189+
"/",
190+
"The context the application is running on. (for example, if it is served via a reverse proxy)",
191+
),
192+
printVersion: flag.Bool("version", false, "Print version information and exit"),
193+
port: flag.Int(
194+
"port",
195+
8080,
196+
"Define the port to run the application on. (default: 8080)",
197+
),
198+
config: flag.String("config", "", "Define the config file"),
161199
}
162200
}

pkg/handler/handler_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ var _ = Describe("Handler ", func() {
6565
h.Version(c)
6666

6767
Ω(recorder.Code).Should(Equal(http.StatusOK))
68-
Ω(recorder.Body.String()).Should(Equal(fmt.Sprintf(`{"build":"%v","version":"%v"}`, version.Build, version.Version)))
68+
Ω(
69+
recorder.Body.String(),
70+
).Should(Equal(fmt.Sprintf(`{"build":"%v","version":"%v"}`, version.Build, version.Version)))
6971
Ω(recorder.Header().Get("Content-Type")).Should(Equal("application/json; charset=utf-8"))
7072
})
7173
})

pkg/handler/kubeseal.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ func contextNegotiate(c *gin.Context, code int, config gin.Negotiate) {
5555
c.TOML(code, data)
5656

5757
default:
58-
c.AbortWithError(http.StatusNotAcceptable, errors.New("the accepted formats are not offered by the server")) //nolint: errcheck
58+
_ = c.AbortWithError(
59+
http.StatusNotAcceptable,
60+
errors.New("the accepted formats are not offered by the server"),
61+
)
5962
}
6063
}
6164

pkg/handler/raw_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ var _ = Describe("Handler ", func() {
5555
h.Raw(c)
5656

5757
Ω(recorder.Code).Should(Equal(http.StatusUnprocessableEntity))
58-
Ω(recorder.Body.String()).Should(Equal(`{"error":"invalid character 'o' in literal false (expecting 'a')"}`))
58+
Ω(
59+
recorder.Body.String(),
60+
).Should(Equal(`{"error":"invalid character 'o' in literal false (expecting 'a')"}`))
5961
Ω(recorder.Header().Get("Content-Type")).Should(Equal("application/json; charset=utf-8"))
6062
})
6163

pkg/handler/secrets.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ import (
2121
)
2222

2323
// BuildClients build the k82 clients
24-
func BuildClients(clientConfig clientcmd.ClientConfig, disableLoadSecrets bool) (corev1.CoreV1Interface, ssClient.BitnamiV1alpha1Interface, error) {
24+
func BuildClients(
25+
clientConfig clientcmd.ClientConfig,
26+
disableLoadSecrets bool,
27+
) (corev1.CoreV1Interface, ssClient.BitnamiV1alpha1Interface, error) {
2528
if disableLoadSecrets {
2629
return nil, nil, nil
2730
}
@@ -52,7 +55,11 @@ type SecretsHandler struct {
5255
}
5356

5457
// NewHandler creates a new secret handler.
55-
func NewHandler(coreClient corev1.CoreV1Interface, ssCl ssClient.BitnamiV1alpha1Interface, cfg *config.Config) *SecretsHandler {
58+
func NewHandler(
59+
coreClient corev1.CoreV1Interface,
60+
ssCl ssClient.BitnamiV1alpha1Interface,
61+
cfg *config.Config,
62+
) *SecretsHandler {
5663
inMap := make(map[string]bool)
5764
for _, n := range cfg.IncludeNamespaces {
5865
inMap[n] = true
@@ -209,5 +216,5 @@ func encodeSecret(secret *v1.Secret, outputFormat string) ([]byte, error) {
209216

210217
type Secret struct {
211218
Namespace string `json:"namespace" yaml:"namespace"`
212-
Name string `json:"name" yaml:"name"`
219+
Name string `json:"name" yaml:"name"`
213220
}

pkg/handler/validate_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ var _ = Describe("Handler ", func() {
7171
h.Validate(c)
7272

7373
Ω(recorder.Code).Should(Equal(http.StatusConflict))
74-
Ω(recorder.Body.String()).Should(Equal("validate can't be used with CertURL (http://sealed-secrets/v1/cert.pem)"))
74+
Ω(
75+
recorder.Body.String(),
76+
).Should(Equal("validate can't be used with CertURL (http://sealed-secrets/v1/cert.pem)"))
7577
Ω(recorder.Header().Get("Content-Type")).Should(Equal("text/plain"))
7678
})
7779
})

0 commit comments

Comments
 (0)