From f5a87c6461364c17e64d089065b6719078ede199 Mon Sep 17 00:00:00 2001 From: s0s01qp Date: Wed, 21 Jul 2021 11:18:50 +0530 Subject: [PATCH] fixed lint issues --- controllers/gin/route.go | 2 ++ controllers/nethttp/route.go | 2 ++ controllers/nethttp/threaddump.go | 3 ++- core/httptrace.go | 5 +++++ core/info.go | 1 + models/config.go | 2 +- models/endpoints.go | 1 + models/httpTrace.go | 2 ++ models/memStats.go | 4 ++++ 9 files changed, 20 insertions(+), 2 deletions(-) diff --git a/controllers/gin/route.go b/controllers/gin/route.go index 895607a..9e6a985 100644 --- a/controllers/gin/route.go +++ b/controllers/gin/route.go @@ -7,6 +7,8 @@ import ( "github.com/sinhashubham95/go-actuator/models" ) +// ConfigureHandlers is used to add the respective handler functions for the configured actuator endpoints +// to the gin engine. func ConfigureHandlers(config *models.Config, router *gin.Engine) { actuator := router.Group(config.Prefix) for _, e := range config.Endpoints { diff --git a/controllers/nethttp/route.go b/controllers/nethttp/route.go index 252b321..787f2f2 100644 --- a/controllers/nethttp/route.go +++ b/controllers/nethttp/route.go @@ -8,6 +8,8 @@ import ( "github.com/sinhashubham95/go-actuator/models" ) +// ConfigureHandlers is used to add the respective handler functions for the configured actuator endpoints +// to the net http server mux. func ConfigureHandlers(config *models.Config, mux *http.ServeMux) { for _, e := range config.Endpoints { // now one by one add the handler of each endpoint diff --git a/controllers/nethttp/threaddump.go b/controllers/nethttp/threaddump.go index 0b1b765..3682d0e 100644 --- a/controllers/nethttp/threaddump.go +++ b/controllers/nethttp/threaddump.go @@ -7,7 +7,8 @@ import ( "github.com/sinhashubham95/go-actuator/core" ) -func HandleThreadDump(writer http.ResponseWriter, request *http.Request) { +// HandleThreadDump is the handler to get the thread dump +func HandleThreadDump(writer http.ResponseWriter, _ *http.Request) { body, err := core.GetThreadDump() if err != nil { // some error occurred diff --git a/core/httptrace.go b/core/httptrace.go index e2434fc..a5f293e 100644 --- a/core/httptrace.go +++ b/core/httptrace.go @@ -14,6 +14,8 @@ import ( var httpTraceResultsMu sync.Mutex var httpTraceResults []*models.HTTPTraceResult +// WrapFastHTTPHandler should be used to wrap the created handler function for fast HTTP based web servers, +// so that the requests to the same can be traced. func WrapFastHTTPHandler(handler fasthttp.RequestHandler) fasthttp.RequestHandler { return func(ctx *fasthttp.RequestCtx) { // for each new request create a result and trace the request @@ -38,6 +40,7 @@ func WrapFastHTTPHandler(handler fasthttp.RequestHandler) fasthttp.RequestHandle } } +// GINTracer is the middleware function to be used with the GIN engines for tracing the requests to it. func GINTracer() gin.HandlerFunc { return func(ctx *gin.Context) { // for each new request create a result and trace the request @@ -62,6 +65,8 @@ func GINTracer() gin.HandlerFunc { } } +// WrapNetHTTPHandler should be used to wrap the created handler function for net HTTP based web servers, +// so that the requests to the same can be traced. func WrapNetHTTPHandler(handler http.HandlerFunc) http.HandlerFunc { return func(writer http.ResponseWriter, request *http.Request) { // for each new request create a result and trace the request diff --git a/core/info.go b/core/info.go index 1c876a4..ab689ed 100644 --- a/core/info.go +++ b/core/info.go @@ -6,6 +6,7 @@ import ( "runtime" ) +// Set of linked build time variables for providing relevant information for the application var ( BuildStamp string GitCommitAuthor string diff --git a/models/config.go b/models/config.go index 25eb350..49cd4ab 100644 --- a/models/config.go +++ b/models/config.go @@ -26,7 +26,7 @@ func (config *Config) Validate() { } for _, endpoint := range config.Endpoints { if !IsValidEndpoint(endpoint) { - panic(errors.New(fmt.Sprintf("invalid endpoint %d provided", endpoint))) + panic(fmt.Errorf("invalid endpoint %d provided", endpoint)) } } } diff --git a/models/endpoints.go b/models/endpoints.go index abe2917..23af523 100644 --- a/models/endpoints.go +++ b/models/endpoints.go @@ -1,5 +1,6 @@ package models +// Endpoints enumeration const ( Env = iota HTTPTrace diff --git a/models/httpTrace.go b/models/httpTrace.go index 09de2a3..32b80b6 100644 --- a/models/httpTrace.go +++ b/models/httpTrace.go @@ -33,6 +33,8 @@ type HTTPStatusRecorder struct { StatusCode int } +// WriteHeader saves an HTTP response header with the provided +// status code. func (r *HTTPStatusRecorder) WriteHeader(statusCode int) { r.StatusCode = statusCode r.ResponseWriter.WriteHeader(statusCode) diff --git a/models/memStats.go b/models/memStats.go index 7339135..702cde7 100644 --- a/models/memStats.go +++ b/models/memStats.go @@ -1,5 +1,9 @@ package models +// BySizeElement reports per-size class allocation statistics. +// BySize[N] gives statistics for allocations of size S where +// BySize[N-1].Size < S ≤ BySize[N].Size. +// This does not report allocations larger than BySize[60].Size. type BySizeElement struct { // Size is the maximum byte size of an object in this // size class.