Skip to content

Commit 8a02ea3

Browse files
committed
chore: replace golint with revive
1 parent 844a11a commit 8a02ea3

File tree

11 files changed

+34
-18
lines changed

11 files changed

+34
-18
lines changed

.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
.git
1+
.*
22
dist
3+
examples

Makefile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ COVERAGE_ARGS ?= -covermode=atomic -coverprofile=$(COVERAGE_PATH)
1212
TEST_ARGS ?= -race
1313

1414
# 3rd party tools
15-
GOLINT := go run golang.org/x/lint/golint@latest
15+
LINT := go run github.com/mgechev/revive@v1.3.4
1616
REFLEX := go run github.com/cespare/reflex@v0.3.1
1717
STATICCHECK := go run honnef.co/go/tools/cmd/staticcheck@2023.1.3
1818

19+
# Host and port to use when running locally via `make run` or `make watch`
20+
HOST ?= 127.0.0.1
21+
PORT ?= 8080
22+
1923

2024
# =============================================================================
2125
# build
@@ -45,7 +49,6 @@ test:
4549
go test $(TEST_ARGS) ./...
4650
.PHONY: test
4751

48-
4952
# Test command to run for continuous integration, which includes code coverage
5053
# based on codecov.io's documentation:
5154
# https://github.com/codecov/example-go/blob/b85638743b972bd0bd2af63421fe513c6f968930/README.md
@@ -61,7 +64,7 @@ testcover: testci
6164
lint:
6265
test -z "$$(gofmt -d -s -e .)" || (echo "Error: gofmt failed"; gofmt -d -s -e . ; exit 1)
6366
go vet ./...
64-
$(GOLINT) -set_exit_status ./...
67+
$(LINT) -set_exit_status ./...
6568
$(STATICCHECK) ./...
6669
.PHONY: lint
6770

@@ -70,7 +73,7 @@ lint:
7073
# run locally
7174
# =============================================================================
7275
run: build
73-
$(DIST_PATH)/go-httpbin -host 127.0.0.1 -port 8080
76+
HOST=$(HOST) PORT=$(PORT) $(DIST_PATH)/go-httpbin
7477
.PHONY: run
7578

7679
watch:

cmd/go-httpbin/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package main implements the go-httpbin command line tool.
12
package main
23

34
import (

examples/custom-instrumentation/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package main demonstrates how to instrument httpbin with custom metrics.
12
package main
23

34
import (

httpbin/cmd/cmd.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Package cmd implements the go-httpbin command line interface as a testable
2+
// package.
13
package cmd
24

35
import (

httpbin/doc.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Package httpbin provides a simple HTTP request and response testing server,
2+
// modeled on the original httpbin.org Python project.
3+
package httpbin

httpbin/handlers.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919

2020
var nilValues = url.Values{}
2121

22-
func notImplementedHandler(w http.ResponseWriter, r *http.Request) {
22+
func notImplementedHandler(w http.ResponseWriter, _ *http.Request) {
2323
writeError(w, http.StatusNotImplemented, nil)
2424
}
2525

@@ -34,12 +34,12 @@ func (h *HTTPBin) Index(w http.ResponseWriter, r *http.Request) {
3434
}
3535

3636
// FormsPost renders an HTML form that submits a request to the /post endpoint
37-
func (h *HTTPBin) FormsPost(w http.ResponseWriter, r *http.Request) {
37+
func (h *HTTPBin) FormsPost(w http.ResponseWriter, _ *http.Request) {
3838
writeHTML(w, mustStaticAsset("forms-post.html"), http.StatusOK)
3939
}
4040

4141
// UTF8 renders an HTML encoding stress test
42-
func (h *HTTPBin) UTF8(w http.ResponseWriter, r *http.Request) {
42+
func (h *HTTPBin) UTF8(w http.ResponseWriter, _ *http.Request) {
4343
writeHTML(w, mustStaticAsset("utf8.html"), http.StatusOK)
4444
}
4545

@@ -80,7 +80,7 @@ func (h *HTTPBin) RequestWithBody(w http.ResponseWriter, r *http.Request) {
8080
URL: getURL(r).String(),
8181
}
8282

83-
if err := parseBody(w, r, resp); err != nil {
83+
if err := parseBody(r, resp); err != nil {
8484
writeError(w, http.StatusBadRequest, fmt.Errorf("error parsing request body: %w", err))
8585
return
8686
}
@@ -718,20 +718,20 @@ func (h *HTTPBin) Range(w http.ResponseWriter, r *http.Request) {
718718
}
719719

720720
// HTML renders a basic HTML page
721-
func (h *HTTPBin) HTML(w http.ResponseWriter, r *http.Request) {
721+
func (h *HTTPBin) HTML(w http.ResponseWriter, _ *http.Request) {
722722
writeHTML(w, mustStaticAsset("moby.html"), http.StatusOK)
723723
}
724724

725725
// Robots renders a basic robots.txt file
726-
func (h *HTTPBin) Robots(w http.ResponseWriter, r *http.Request) {
726+
func (h *HTTPBin) Robots(w http.ResponseWriter, _ *http.Request) {
727727
robotsTxt := []byte(`User-agent: *
728728
Disallow: /deny
729729
`)
730730
writeResponse(w, http.StatusOK, textContentType, robotsTxt)
731731
}
732732

733733
// Deny renders a basic page that robots should never access
734-
func (h *HTTPBin) Deny(w http.ResponseWriter, r *http.Request) {
734+
func (h *HTTPBin) Deny(w http.ResponseWriter, _ *http.Request) {
735735
writeResponse(w, http.StatusOK, textContentType, []byte(`YOU SHOULDN'T BE HERE`))
736736
}
737737

@@ -926,7 +926,7 @@ func (h *HTTPBin) Links(w http.ResponseWriter, r *http.Request) {
926926
}
927927

928928
// doLinksPage renders a page with a series of N links
929-
func doLinksPage(w http.ResponseWriter, r *http.Request, n int, offset int) {
929+
func doLinksPage(w http.ResponseWriter, _ *http.Request, n int, offset int) {
930930
w.Header().Add("Content-Type", htmlContentType)
931931
w.WriteHeader(http.StatusOK)
932932

@@ -988,7 +988,7 @@ func doImage(w http.ResponseWriter, kind string) {
988988
}
989989

990990
// XML responds with an XML document
991-
func (h *HTTPBin) XML(w http.ResponseWriter, r *http.Request) {
991+
func (h *HTTPBin) XML(w http.ResponseWriter, _ *http.Request) {
992992
writeResponse(w, http.StatusOK, "application/xml", mustStaticAsset("sample.xml"))
993993
}
994994

@@ -1042,7 +1042,7 @@ func (h *HTTPBin) DigestAuth(w http.ResponseWriter, r *http.Request) {
10421042
}
10431043

10441044
// UUID - responds with a generated UUID
1045-
func (h *HTTPBin) UUID(w http.ResponseWriter, r *http.Request) {
1045+
func (h *HTTPBin) UUID(w http.ResponseWriter, _ *http.Request) {
10461046
writeJSON(http.StatusOK, w, uuidResponse{
10471047
UUID: uuidv4(),
10481048
})
@@ -1085,7 +1085,7 @@ func (h *HTTPBin) DumpRequest(w http.ResponseWriter, r *http.Request) {
10851085
}
10861086

10871087
// JSON - returns a sample json
1088-
func (h *HTTPBin) JSON(w http.ResponseWriter, r *http.Request) {
1088+
func (h *HTTPBin) JSON(w http.ResponseWriter, _ *http.Request) {
10891089
w.Header().Set("Content-Type", jsonContentType)
10901090
w.WriteHeader(http.StatusOK)
10911091
w.Write(mustStaticAsset("sample.json"))
@@ -1107,7 +1107,7 @@ func (h *HTTPBin) Bearer(w http.ResponseWriter, r *http.Request) {
11071107
}
11081108

11091109
// Hostname - returns the hostname.
1110-
func (h *HTTPBin) Hostname(w http.ResponseWriter, r *http.Request) {
1110+
func (h *HTTPBin) Hostname(w http.ResponseWriter, _ *http.Request) {
11111111
writeJSON(http.StatusOK, w, hostnameResponse{
11121112
Hostname: h.hostname,
11131113
})

httpbin/helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func parseFiles(fileHeaders map[string][]*multipart.FileHeader) (map[string][]st
160160
//
161161
// Note: this function expects callers to limit the the maximum size of the
162162
// request body. See, e.g., the limitRequestSize middleware.
163-
func parseBody(w http.ResponseWriter, r *http.Request, resp *bodyResponse) error {
163+
func parseBody(r *http.Request, resp *bodyResponse) error {
164164
defer r.Body.Close()
165165

166166
// Always set resp.Data to the incoming request body, in case we don't know

httpbin/options.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ func WithObserver(o Observer) OptionFunc {
4646
}
4747
}
4848

49+
// WithExcludeHeaders sets the headers to exclude in outgoing responses, to
50+
// prevent possible information leakage.
4951
func WithExcludeHeaders(excludeHeaders string) OptionFunc {
5052
return func(h *HTTPBin) {
5153
h.setExcludeHeaders(excludeHeaders)

internal/testing/assert/assert.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package assert implements common assertions used in go-httbin's unit tests.
12
package assert
23

34
import (

internal/testing/must/must.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Package must implements helper functions for testing to eliminate some error
2+
// checking boilerplate.
13
package must
24

35
import (

0 commit comments

Comments
 (0)