Compare commits

..

No commits in common. "3eec2b8d1d17fd77ee8fdbae2701d5591552a46a" and "3da597f4babfc595ad7d47e00eccff8e4b097d91" have entirely different histories.

5 changed files with 16 additions and 12 deletions

View File

@ -14,12 +14,12 @@ default: debug
commit: fmt lint commit: fmt lint
git commit -a git commit -a
# get goimports with:
# go get golang.org/x/tools/cmd/goimports
# get golangci-lint with: # get golangci-lint with:
# go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.31.0 # go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.31.0
# get gofumports with:
# go get mvdan.cc/gofumpt/gofumports
fmt: fmt:
gofumports -l -w . goimports -l -w .
golangci-lint run --fix golangci-lint run --fix
lint: lint:

View File

@ -6,11 +6,9 @@ import (
"git.eeqj.de/sneak/gohttpserver/httpserver" "git.eeqj.de/sneak/gohttpserver/httpserver"
) )
var ( var Appname string = "CHANGEME"
Appname string = "CHANGEME" var Version string
Version string var Buildarch string
Buildarch string
)
func main() { func main() {
os.Exit(httpserver.Run(Appname, Version, Buildarch)) os.Exit(httpserver.Run(Appname, Version, Buildarch))

View File

@ -122,11 +122,12 @@ func (s *server) serve() int {
go s.serveUntilShutdown() go s.serveUntilShutdown()
for range s.ctx.Done() { for range s.ctx.Done() {
// aforementioned clean shutdown upon main context //aforementioned clean shutdown upon main context
// cancellation //cancellation
} }
s.cleanShutdown() s.cleanShutdown()
return s.exitCode return s.exitCode
} }
func (s *server) cleanupForExit() { func (s *server) cleanupForExit() {
@ -170,7 +171,7 @@ func (s *server) configure() {
viper.AddConfigPath(fmt.Sprintf("/etc/%s", s.appname)) viper.AddConfigPath(fmt.Sprintf("/etc/%s", s.appname))
// call multiple times to add many search paths: // call multiple times to add many search paths:
viper.AddConfigPath(fmt.Sprintf("$HOME/.config/%s", s.appname)) viper.AddConfigPath(fmt.Sprintf("$HOME/.config/%s", s.appname))
// viper.SetEnvPrefix(strings.ToUpper(s.appname)) //viper.SetEnvPrefix(strings.ToUpper(s.appname))
viper.AutomaticEnv() viper.AutomaticEnv()
viper.SetDefault("DEBUG", "false") viper.SetDefault("DEBUG", "false")
@ -249,7 +250,7 @@ func (s *server) setupLogging() {
logger := zerolog.New(multi).With().Timestamp().Logger().With().Caller().Logger() logger := zerolog.New(multi).With().Timestamp().Logger().With().Caller().Logger()
s.log = &logger s.log = &logger
// log.Logger = logger //log.Logger = logger
if viper.GetBool("debug") { if viper.GetBool("debug") {
zerolog.SetGlobalLevel(zerolog.DebugLevel) zerolog.SetGlobalLevel(zerolog.DebugLevel)

View File

@ -66,9 +66,11 @@ func (s *server) LoggingMiddleware() func(http.Handler) http.Handler {
Int("status", lrw.statusCode). Int("status", lrw.statusCode).
Int("latency_ms", int(latency.Milliseconds())). Int("latency_ms", int(latency.Milliseconds())).
Send() Send()
}() }()
next.ServeHTTP(lrw, r) next.ServeHTTP(lrw, r)
}) })
} }
} }
@ -116,4 +118,5 @@ func (s *server) MetricsAuthMiddleware() func(http.Handler) http.Handler {
}, },
}, },
) )
} }

View File

@ -12,6 +12,7 @@ import (
) )
func (s *server) routes() { func (s *server) routes() {
s.router = chi.NewRouter() s.router = chi.NewRouter()
// the mux .Use() takes a http.Handler wrapper func, like most // the mux .Use() takes a http.Handler wrapper func, like most
@ -92,4 +93,5 @@ func (s *server) routes() {
r.Get("/metrics", http.HandlerFunc(promhttp.Handler().ServeHTTP)) r.Get("/metrics", http.HandlerFunc(promhttp.Handler().ServeHTTP))
}) })
} }
} }