🚧 Scaffold basic functionality
This commit is contained in:
parent
f511b9f240
commit
aa7dfb532f
7 changed files with 192 additions and 0 deletions
25
.gitignore
vendored
Normal file
25
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# If you prefer the allow list template instead of the deny list, see community template:
|
||||
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
|
||||
#
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
*.exe~
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
|
||||
# Test binary, built with `go test -c`
|
||||
*.test
|
||||
|
||||
# Dependency directories
|
||||
vendor/
|
||||
|
||||
# Go workspace file
|
||||
go.work
|
||||
go.work.sum
|
||||
|
||||
# env file
|
||||
.env
|
||||
|
||||
build/
|
||||
.task/
|
||||
39
.golangci.yaml
Normal file
39
.golangci.yaml
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
version: "2"
|
||||
|
||||
linters:
|
||||
enable:
|
||||
- errcheck
|
||||
- govet
|
||||
- ineffassign
|
||||
- staticcheck
|
||||
- unused
|
||||
- copyloopvar
|
||||
- dupl
|
||||
- err113
|
||||
- errname
|
||||
- exptostd
|
||||
- fatcontext
|
||||
- funlen
|
||||
- gocognit
|
||||
- goconst
|
||||
- gocritic
|
||||
- gocyclo
|
||||
- godot
|
||||
- godox
|
||||
- gosec
|
||||
- perfsprint
|
||||
- testifylint
|
||||
settings:
|
||||
testifylint:
|
||||
enable-all: true
|
||||
disable:
|
||||
- require-error
|
||||
gocognit:
|
||||
min-complexity: 16
|
||||
gocyclo:
|
||||
min-complexity: 15
|
||||
gocritic:
|
||||
enable-all: true
|
||||
settings:
|
||||
hugeParam:
|
||||
sizeThreshold: 255
|
||||
83
Taskfile.yml
Normal file
83
Taskfile.yml
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
# https://taskfile.dev
|
||||
|
||||
version: '3'
|
||||
|
||||
vars:
|
||||
GOBIN_ENV:
|
||||
sh: go env GOBIN
|
||||
GOPATH_ENV:
|
||||
sh: go env GOPATH
|
||||
BIN: '{{if .GOBIN_ENV}}{{.GOBIN_ENV}}{{else}}{{.GOPATH_ENV}}/bin{{end}}'
|
||||
|
||||
tasks:
|
||||
default:
|
||||
desc: fmt, vet, and build
|
||||
deps:
|
||||
- fmt
|
||||
- lint
|
||||
- build-all
|
||||
|
||||
fmt:
|
||||
desc: Format go files
|
||||
sources:
|
||||
- "**/*.go"
|
||||
cmds:
|
||||
- go fmt ./...
|
||||
|
||||
lint:
|
||||
desc: Statically analyze code
|
||||
sources:
|
||||
- '**/*.go'
|
||||
cmds:
|
||||
- golangci-lint run
|
||||
|
||||
test:
|
||||
desc: Run unit tests
|
||||
deps: [fmt]
|
||||
sources:
|
||||
- '**/*.go'
|
||||
generates:
|
||||
- build/cover.out
|
||||
cmds:
|
||||
- go test -race -cover -coverprofile build/cover.out ./...
|
||||
|
||||
|
||||
coverage-report:
|
||||
desc: Build coverage report
|
||||
deps: [test]
|
||||
sources:
|
||||
- build/cover.out
|
||||
generates:
|
||||
- build/cover.html
|
||||
cmds:
|
||||
- go tool cover -html=build/cover.out -o build/cover.html
|
||||
|
||||
serve-report:
|
||||
desc: Serve the coverage report
|
||||
deps: [coverage-report]
|
||||
cmds:
|
||||
- ip addr list | grep inet
|
||||
- php -S 0.0.0.0:3434 -t build
|
||||
|
||||
serve-docs:
|
||||
desc: Serve the current docs
|
||||
cmds:
|
||||
- godoc -http=0.0.0.0:3434 -play
|
||||
|
||||
cmd-build:
|
||||
internal: true
|
||||
cmds:
|
||||
- go build -o build/ ./cmd/{{.CMD}}
|
||||
|
||||
|
||||
build-all:
|
||||
desc: Builds all available commands
|
||||
sources:
|
||||
- "**/*.go"
|
||||
generates:
|
||||
- build/convids
|
||||
- build/cool-down
|
||||
cmds:
|
||||
- task: cmd-build
|
||||
vars:
|
||||
CMD: "*"
|
||||
13
handler.go
Normal file
13
handler.go
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
package ezhandler
|
||||
|
||||
import "net/http"
|
||||
|
||||
type Handler interface {
|
||||
ServeHTTP(w http.ResponseWriter, r *http.Request) error
|
||||
}
|
||||
|
||||
type HandlerFunc func(w http.ResponseWriter, r *http.Request) error
|
||||
|
||||
func (fn HandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request) error {
|
||||
return fn(w, r)
|
||||
}
|
||||
1
handler_test.go
Normal file
1
handler_test.go
Normal file
|
|
@ -0,0 +1 @@
|
|||
package ezhandler_test
|
||||
30
helper.go
Normal file
30
helper.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package ezhandler
|
||||
|
||||
import "net/http"
|
||||
|
||||
func NewHelper(errH ErrorHandler) *Helper {
|
||||
return &Helper{errH}
|
||||
}
|
||||
|
||||
// ErrorHandler writes an appropriate response to the [http.ResponseWriter] for the provided [error].
|
||||
// If the [error] is nil, it should be a no op.
|
||||
type ErrorHandler func(http.ResponseWriter, *http.Request, error)
|
||||
|
||||
// Helper provides methods to make easier, more idiomatic [http.Handler]s.
|
||||
type Helper struct{
|
||||
errHandler ErrorHandler
|
||||
}
|
||||
|
||||
// Handler returns an [http.Handler] for the provided [Handler].
|
||||
// If hnd returns an error, an appropriate error response is written using the ErrorHandler.
|
||||
func (help *Helper) Handler(hnd Handler) http.Handler {
|
||||
// TODO implement this
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
// Handler returns an [http.Handler] for the provided [HandlerFunc].
|
||||
// If hnd returns an error, an appropriate error response is written using the ErrorHandler.
|
||||
func (help *Helper) HandlerFunc(hnd HandlerFunc) http.Handler {
|
||||
// TODO implement this
|
||||
panic("unimplemented")
|
||||
}
|
||||
1
helper_test.go
Normal file
1
helper_test.go
Normal file
|
|
@ -0,0 +1 @@
|
|||
package ezhandler_test
|
||||
Loading…
Add table
Add a link
Reference in a new issue