chore: add linter.

This commit is contained in:
Fernandez Ludovic
2019-09-17 01:18:11 +02:00
parent c0fd58d016
commit affedf56a2
4 changed files with 63 additions and 8 deletions

39
.golangci.toml Normal file
View File

@ -0,0 +1,39 @@
[run]
deadline = "2m"
skip-files = []
[linters-settings]
[linters-settings.govet]
check-shadowing = true
[linters-settings.gocyclo]
min-complexity = 12.0
[linters-settings.maligned]
suggest-new = true
[linters-settings.goconst]
min-len = 3.0
min-occurrences = 3.0
[linters-settings.misspell]
locale = "US"
[linters]
enable-all = true
disable = [
"maligned",
"lll",
"gas",
"dupl",
"prealloc",
"gochecknoglobals",
"gochecknoinits",
]
[issues]
exclude-use-default = false
max-per-linter = 0
max-same-issues = 0
exclude = []

View File

@ -7,6 +7,10 @@ cache:
directories: directories:
- $GOPATH/pkg/mod - $GOPATH/pkg/mod
branches:
only:
- master
notifications: notifications:
email: email:
on_success: never on_success: never
@ -15,6 +19,11 @@ notifications:
env: env:
- GO111MODULE=on - GO111MODULE=on
before_install:
# Install linters and misspell
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin ${GOLANGCI_LINT_VERSION}
- golangci-lint --version
install: install:
- go mod tidy - go mod tidy
- git diff --exit-code go.mod - git diff --exit-code go.mod
@ -22,5 +31,5 @@ install:
- go mod download - go mod download
script: script:
- make build - make
- make image - make image

View File

@ -1,9 +1,15 @@
.PHONY: default build image .PHONY: default build image check
default: build default: check test build
test:
go test -v -cover ./...
build: build:
CGO_ENABLED=0 go build -a --installsuffix cgo --ldflags="-s" -o whoami CGO_ENABLED=0 go build -a --installsuffix cgo --ldflags="-s" -o whoami
image: image:
docker build -t containous/whoami . docker build -t containous/whoami .
check:
golangci-lint run

11
app.go
View File

@ -19,6 +19,7 @@ import (
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
) )
// Units
const ( const (
_ = iota _ = iota
KB int64 = 1 << (10 * iota) KB int64 = 1 << (10 * iota)
@ -110,13 +111,13 @@ func dataHandler(w http.ResponseWriter, r *http.Request) {
unit := queryParams.Get("unit") unit := queryParams.Get("unit")
switch strings.ToLower(unit) { switch strings.ToLower(unit) {
case "kb": case "kb":
size = size * KB size *= KB
case "mb": case "mb":
size = size * MB size *= MB
case "gb": case "gb":
size = size * GB size *= GB
case "tb": case "tb":
size = size * TB size *= TB
} }
attachment, err := strconv.ParseBool(queryParams.Get("attachment")) attachment, err := strconv.ParseBool(queryParams.Get("attachment"))
@ -248,7 +249,7 @@ func healthHandler(w http.ResponseWriter, req *http.Request) {
func fillContent(length int64) io.ReadSeeker { func fillContent(length int64) io.ReadSeeker {
charset := "-ABCDEFGHIJKLMNOPQRSTUVWXYZ" charset := "-ABCDEFGHIJKLMNOPQRSTUVWXYZ"
b := make([]byte, length, length) b := make([]byte, length)
for i := range b { for i := range b {
b[i] = charset[i%len(charset)] b[i] = charset[i%len(charset)]