diff --git a/internal/server/data/resource.go b/internal/server/data/resource.go index d55fc72..cd99c3e 100644 --- a/internal/server/data/resource.go +++ b/internal/server/data/resource.go @@ -28,6 +28,7 @@ import ( "github.com/gorilla/mux" ) +// Constants for error reasons const ( ResourceItemNotFound = "Resource Item Not Found" NonIntegerValue = "Non Integer Value" diff --git a/internal/server/data/state.go b/internal/server/data/state.go index 94c4cfc..cb91e65 100644 --- a/internal/server/data/state.go +++ b/internal/server/data/state.go @@ -27,8 +27,10 @@ type safeHandlerMap struct { m *sync.RWMutex } +// Singleton containing all current handlers as a safeHandlerMap var Handlers = New() +// New creates a read-to-use safeHandlerMap func New() safeHandlerMap { return safeHandlerMap{ hs: make(map[string]*model.Handler), diff --git a/internal/server/srverrors/error.go b/internal/server/srverrors/error.go index 77c7083..4b303c5 100644 --- a/internal/server/srverrors/error.go +++ b/internal/server/srverrors/error.go @@ -5,10 +5,13 @@ import ( "net/http" ) +// A ServerErrMessage represents the reason why the error happened type ServerErrMessage struct { Reason string `json:"reason"` } +// WriteErrorResponse writes the error JSON body to the provided http.ResponseWriter, +// after setting the appropiate Content-Type header func WriteErrorResponse(statusCode int, reasonMsg string, res http.ResponseWriter) { respBody := ServerErrMessage{} respBody.Reason = reasonMsg diff --git a/internal/server/user/server.go b/internal/server/user/server.go index 15f0706..1139653 100644 --- a/internal/server/user/server.go +++ b/internal/server/user/server.go @@ -23,10 +23,12 @@ import ( "github.com/BBVA/kapow/internal/server/user/mux" ) +// Server is a singleton that stores the http.Server for the user package var Server = http.Server{ Handler: mux.New(), } +// Run finishes configuring Server and runs ListenAndServe on it func Run(bindAddr string) { Server = http.Server{ Addr: bindAddr, diff --git a/testutils/jaillover/main.go b/testutils/jaillover/main.go index 6810778..d4a2357 100644 --- a/testutils/jaillover/main.go +++ b/testutils/jaillover/main.go @@ -8,6 +8,8 @@ import ( "strings" ) +// An Output represents the execution context, +// meaning the command line and the environment type Output struct { Cmdline []string `json:"cmdline"` Env map[string]string `json:"env"`