Skip to content

Commit 3a43990

Browse files
authored
Merge pull request #30 from slok/check
Add checks to CI and fix the checker error on the code
2 parents 4b58ea1 + 962ca7f commit 3a43990

File tree

10 files changed

+61
-25
lines changed

10 files changed

+61
-25
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,35 @@
11
name: CI
2+
23
on: [push]
4+
35
jobs:
6+
check:
7+
name: Check
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/setup-go@v1
11+
with:
12+
go-version: 1.13
13+
- name: Get golangci
14+
run: |
15+
# Add go binaries to GOPATH.
16+
# FIX: https://github.com/actions/setup-go/issues/14
17+
export PATH=${PATH}:`go env GOPATH`/bin
18+
go get -u github.com/golangci/golangci-lint/...
19+
- uses: actions/checkout@v1
20+
- name: check
21+
run: |
22+
# Add go binaries to GOPATH.
23+
# FIX: https://github.com/actions/setup-go/issues/14
24+
export PATH=${PATH}:`go env GOPATH`/bin
25+
make check
26+
427
test:
528
name: Test
629
runs-on: ubuntu-latest
730
steps:
8-
- name: Set up Go
9-
uses: actions/setup-go@v1
31+
- uses: actions/checkout@v1
32+
- uses: actions/setup-go@v1
1033
with:
1134
go-version: 1.13
12-
id: go
13-
14-
- name: Check out code into the Go module directory
15-
uses: actions/checkout@v1
16-
17-
- name: Test
18-
run: make ci
35+
- run: make test

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
UNIT_TEST_CMD := go test `go list ./... | grep -v vendor` -race -v
33
INTEGRATION_TEST_CMD := go test `go list ./... | grep -v vendor` -race -v -tags='integration'
44
BENCHMARK_CMD := go test `go list ./... | grep -v vendor` -benchmem -bench=.
5+
CHECK_CMD = golangci-lint run -E goimports
56
DEPS_CMD := go mod tidy
67
MOCKS_CMD := go generate ./internal/mocks
78

@@ -11,18 +12,21 @@ default: test
1112
.PHONY: unit-test
1213
unit-test:
1314
$(UNIT_TEST_CMD)
15+
1416
.PHONY: integration-test
1517
integration-test:
1618
$(INTEGRATION_TEST_CMD)
19+
1720
.PHONY: test
1821
test: integration-test
1922

2023
.PHONY: benchmark
2124
benchmark:
2225
$(BENCHMARK_CMD)
2326

24-
.PHONY: ci
25-
ci: test
27+
.PHONY: check
28+
check:
29+
$(CHECK_CMD)
2630

2731
.PHONY: deps
2832
deps:

middleware/example_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,17 @@ func ExampleMiddleware_prometheusBackendMiddleware() {
2222
// Create our handler.
2323
myHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
2424
w.WriteHeader(http.StatusOK)
25-
w.Write([]byte("hello world!"))
25+
_, _ = w.Write([]byte("hello world!"))
2626
})
2727

2828
// Wrap our handler with the middleware.
2929
h := mdlw.Handler("", myHandler)
3030

3131
// Serve metrics from the default prometheus registry.
3232
log.Printf("serving metrics at: %s", ":8081")
33-
go http.ListenAndServe(":8081", promhttp.Handler())
33+
go func() {
34+
_ = http.ListenAndServe(":8081", promhttp.Handler())
35+
}()
3436

3537
// Serve our handler.
3638
log.Printf("listening at: %s", ":8080")

middleware/gin/example_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ func Example_ginMiddleware() {
3131

3232
// Serve metrics from the default prometheus registry.
3333
log.Printf("serving metrics at: %s", ":8081")
34-
go http.ListenAndServe(":8081", promhttp.Handler())
34+
go func() {
35+
_ = http.ListenAndServe(":8081", promhttp.Handler())
36+
}()
3537

3638
// Serve our handler.
3739
log.Printf("listening at: %s", ":8080")

middleware/gin/gin.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ func (w *ginResponseWriter) WriteHeader(statusCode int) {
4747
}
4848

4949
func (w *ginResponseWriter) Write(p []byte) (int, error) {
50-
w.middlewareRW.Write(p)
50+
b, err := w.middlewareRW.Write(p)
51+
if err != nil {
52+
return b, err
53+
}
5154
return w.ResponseWriter.Write(p)
5255
}

middleware/gorestful/example_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ func Example_gorestfulMiddleware() {
2929
// Add our handler,
3030
ws := &gorestful.WebService{}
3131
ws.Route(ws.GET("/").To(func(_ *gorestful.Request, resp *gorestful.Response) {
32-
resp.WriteEntity("Hello world")
32+
_ = resp.WriteEntity("Hello world")
3333
}))
3434
c.Add(ws)
3535

3636
// Serve metrics from the default prometheus registry.
3737
log.Printf("serving metrics at: %s", ":8081")
38-
go http.ListenAndServe(":8081", promhttp.Handler())
38+
go func() {
39+
_ = http.ListenAndServe(":8081", promhttp.Handler())
40+
}()
3941

4042
// Serve our handler.
4143
log.Printf("listening at: %s", ":8080")

middleware/gorestful/gorestful_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717

1818
func getTestHandler(statusCode int) gorestful.RouteFunction {
1919
return gorestful.RouteFunction(func(_ *gorestful.Request, resp *gorestful.Response) {
20-
resp.WriteHeaderAndEntity(statusCode, "Hello world")
20+
_ = resp.WriteHeaderAndEntity(statusCode, "Hello world")
2121
})
2222
}
2323

middleware/httprouter/example_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func Example_httprouterMiddlewareByHandler() {
2020
myHandler := func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
2121
id := p.ByName("id")
2222
w.WriteHeader(http.StatusOK)
23-
w.Write([]byte("hello world! " + id))
23+
_, _ = w.Write([]byte("hello world! " + id))
2424
}
2525

2626
// Create our router.
@@ -36,7 +36,9 @@ func Example_httprouterMiddlewareByHandler() {
3636

3737
// Serve metrics from the default prometheus registry.
3838
log.Printf("serving metrics at: %s", ":8081")
39-
go http.ListenAndServe(":8081", promhttp.Handler())
39+
go func() {
40+
_ = http.ListenAndServe(":8081", promhttp.Handler())
41+
}()
4042

4143
// Serve our handler.
4244
log.Printf("listening at: %s", ":8080")
@@ -52,7 +54,7 @@ func Example_httprouterMiddlewareOnRouter() {
5254
myHandler := func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
5355
id := p.ByName("id")
5456
w.WriteHeader(http.StatusOK)
55-
w.Write([]byte("hello world! " + id))
57+
_, _ = w.Write([]byte("hello world! " + id))
5658
}
5759

5860
// Create our router and add the middleware.
@@ -68,7 +70,9 @@ func Example_httprouterMiddlewareOnRouter() {
6870

6971
// Serve metrics from the default prometheus registry.
7072
log.Printf("serving metrics at: %s", ":8081")
71-
go http.ListenAndServe(":8081", promhttp.Handler())
73+
go func() {
74+
_ = http.ListenAndServe(":8081", promhttp.Handler())
75+
}()
7276

7377
// Wrap the router with the middleware.
7478
h := mdlw.Handler("", r)

middleware/middleware_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
func getFakeHandler(statusCode int, responseBody string) http.Handler {
1515
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1616
w.WriteHeader(statusCode)
17-
w.Write([]byte(responseBody))
17+
_, _ = w.Write([]byte(responseBody))
1818
})
1919
}
2020

middleware/negroni/example_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func Example_negroniMiddleware() {
1818
// Create our handler.
1919
myHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
2020
w.WriteHeader(http.StatusOK)
21-
w.Write([]byte("hello world!"))
21+
_, _ = w.Write([]byte("hello world!"))
2222
})
2323

2424
// Create our negroni instance.
@@ -36,7 +36,9 @@ func Example_negroniMiddleware() {
3636

3737
// Serve metrics from the default prometheus registry.
3838
log.Printf("serving metrics at: %s", ":8081")
39-
go http.ListenAndServe(":8081", promhttp.Handler())
39+
go func() {
40+
_ = http.ListenAndServe(":8081", promhttp.Handler())
41+
}()
4042

4143
// Serve our handler.
4244
log.Printf("listening at: %s", ":8080")

0 commit comments

Comments
 (0)