Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update linting configuration #154

Merged
merged 2 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.git
.*
dist
examples
4 changes: 2 additions & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ jobs:
- uses: actions/setup-go@v2
with:
go-version: '1.21'
- uses: golangci/golangci-lint-action@v3.4.0
- uses: golangci/golangci-lint-action@v3.7.0
with:
version: v1.52.2
version: v1.55.2
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ COVERAGE_ARGS ?= -covermode=atomic -coverprofile=$(COVERAGE_PATH)
TEST_ARGS ?= -race

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

# Host and port to use when running locally via `make run` or `make watch`
HOST ?= 127.0.0.1
PORT ?= 8080


# =============================================================================
# build
Expand Down Expand Up @@ -45,7 +49,6 @@ test:
go test $(TEST_ARGS) ./...
.PHONY: test


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

Expand All @@ -70,7 +73,7 @@ lint:
# run locally
# =============================================================================
run: build
$(DIST_PATH)/go-httpbin -host 127.0.0.1 -port 8080
HOST=$(HOST) PORT=$(PORT) $(DIST_PATH)/go-httpbin
.PHONY: run

watch:
Expand Down
1 change: 1 addition & 0 deletions cmd/go-httpbin/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main implements the go-httpbin command line tool.
package main

import (
Expand Down
1 change: 1 addition & 0 deletions examples/custom-instrumentation/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main demonstrates how to instrument httpbin with custom metrics.
package main

import (
Expand Down
2 changes: 2 additions & 0 deletions httpbin/cmd/cmd.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Package cmd implements the go-httpbin command line interface as a testable
// package.
package cmd

import (
Expand Down
3 changes: 3 additions & 0 deletions httpbin/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Package httpbin provides a simple HTTP request and response testing server,
// modeled on the original httpbin.org Python project.
package httpbin
24 changes: 12 additions & 12 deletions httpbin/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

var nilValues = url.Values{}

func notImplementedHandler(w http.ResponseWriter, r *http.Request) {
func notImplementedHandler(w http.ResponseWriter, _ *http.Request) {
writeError(w, http.StatusNotImplemented, nil)
}

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

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

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

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

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

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

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

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

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

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

Expand Down Expand Up @@ -988,7 +988,7 @@ func doImage(w http.ResponseWriter, kind string) {
}

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

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

// UUID - responds with a generated UUID
func (h *HTTPBin) UUID(w http.ResponseWriter, r *http.Request) {
func (h *HTTPBin) UUID(w http.ResponseWriter, _ *http.Request) {
writeJSON(http.StatusOK, w, uuidResponse{
UUID: uuidv4(),
})
Expand Down Expand Up @@ -1085,7 +1085,7 @@ func (h *HTTPBin) DumpRequest(w http.ResponseWriter, r *http.Request) {
}

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

// Hostname - returns the hostname.
func (h *HTTPBin) Hostname(w http.ResponseWriter, r *http.Request) {
func (h *HTTPBin) Hostname(w http.ResponseWriter, _ *http.Request) {
writeJSON(http.StatusOK, w, hostnameResponse{
Hostname: h.hostname,
})
Expand Down
2 changes: 1 addition & 1 deletion httpbin/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func parseFiles(fileHeaders map[string][]*multipart.FileHeader) (map[string][]st
//
// Note: this function expects callers to limit the the maximum size of the
// request body. See, e.g., the limitRequestSize middleware.
func parseBody(w http.ResponseWriter, r *http.Request, resp *bodyResponse) error {
func parseBody(r *http.Request, resp *bodyResponse) error {
defer r.Body.Close()

// Always set resp.Data to the incoming request body, in case we don't know
Expand Down
2 changes: 2 additions & 0 deletions httpbin/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func WithObserver(o Observer) OptionFunc {
}
}

// WithExcludeHeaders sets the headers to exclude in outgoing responses, to
// prevent possible information leakage.
func WithExcludeHeaders(excludeHeaders string) OptionFunc {
return func(h *HTTPBin) {
h.setExcludeHeaders(excludeHeaders)
Expand Down
1 change: 1 addition & 0 deletions internal/testing/assert/assert.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package assert implements common assertions used in go-httbin's unit tests.
package assert

import (
Expand Down
2 changes: 2 additions & 0 deletions internal/testing/must/must.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Package must implements helper functions for testing to eliminate some error
// checking boilerplate.
package must

import (
Expand Down
Loading