diff --git a/internal/httpserver/handler.go b/internal/httpserver/handler.go index c0a5860..654e7a8 100644 --- a/internal/httpserver/handler.go +++ b/internal/httpserver/handler.go @@ -137,7 +137,7 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } // Process request type. Here we process only known requests types, - // by default request should go to specific application's handler. + // all other requests will produce HTTP 400 error. switch rInfo.RequestType { // ToDo: move to constants. case "apps_list": diff --git a/internal/httpserver/httpserver.go b/internal/httpserver/httpserver.go index a689aa5..a65319d 100644 --- a/internal/httpserver/httpserver.go +++ b/internal/httpserver/httpserver.go @@ -22,6 +22,8 @@ type HTTPServer struct { server *http.Server } +// NewHTTPServer creates HTTP server and executes preliminary initialization +// (HTTP server structure initialized but it doesn't start). func NewHTTPServer(ctx context.Context, cfg *configuration.Config, logger *logger.Logger) (*HTTPServer, chan struct{}) { h := &HTTPServer{ config: cfg, diff --git a/internal/logger/config.go b/internal/logger/config.go index 7091b6f..0bdd4d3 100644 --- a/internal/logger/config.go +++ b/internal/logger/config.go @@ -2,5 +2,6 @@ package logger // Config represents logging configuration. type Config struct { + // Debug is a flag that indicates that we should print out debug output. Debug bool `yaml:"debug"` } diff --git a/internal/models/request_info.go b/internal/models/request_info.go index 60f796a..aaf526d 100644 --- a/internal/models/request_info.go +++ b/internal/models/request_info.go @@ -2,8 +2,14 @@ package models // RequestInfo is a parsed request information to throw into application's handler. type RequestInfo struct { + // Application is a name of application. We should ask it's handler for metrics. Application string - Metric string + // Metric is a metric name with parameters (e.g. requests{path='/',code=200} will + // be "requests/path:\//code:200"). + Metric string + // Request type is a type of request. Currently known: "apps_list", "info", and "metrics". + // All other request types will produce HTTP 400 error. RequestType string - APIVersion int + // APIVersion is a version of API requested. + APIVersion int } diff --git a/internal/storage/memory/memory.go b/internal/storage/memory/memory.go index 742e453..cd2c814 100644 --- a/internal/storage/memory/memory.go +++ b/internal/storage/memory/memory.go @@ -9,16 +9,16 @@ import ( "go.dev.pztrn.name/metricator/internal/models" ) +// ErrMetricNotFound appears if requested metric wasn't found in storage. var ErrMetricNotFound = errors.New("metric not found") // Storage is an in-memory storage. type Storage struct { - ctx context.Context - doneChan chan struct{} - logger *logger.Logger - name string - + ctx context.Context + doneChan chan struct{} + logger *logger.Logger data map[string]models.Metric + name string dataMutex sync.RWMutex }