Linting and comments.

This commit is contained in:
Stanislav Nikitin 2020-12-23 20:55:50 +05:00
parent 08d5f36c36
commit 115e5d5051
Signed by: pztrn
GPG Key ID: 1E944A0F0568B550
5 changed files with 17 additions and 8 deletions

View File

@ -137,7 +137,7 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
// Process request type. Here we process only known requests types, // 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 { switch rInfo.RequestType {
// ToDo: move to constants. // ToDo: move to constants.
case "apps_list": case "apps_list":

View File

@ -22,6 +22,8 @@ type HTTPServer struct {
server *http.Server 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{}) { func NewHTTPServer(ctx context.Context, cfg *configuration.Config, logger *logger.Logger) (*HTTPServer, chan struct{}) {
h := &HTTPServer{ h := &HTTPServer{
config: cfg, config: cfg,

View File

@ -2,5 +2,6 @@ package logger
// Config represents logging configuration. // Config represents logging configuration.
type Config struct { type Config struct {
// Debug is a flag that indicates that we should print out debug output.
Debug bool `yaml:"debug"` Debug bool `yaml:"debug"`
} }

View File

@ -2,8 +2,14 @@ package models
// RequestInfo is a parsed request information to throw into application's handler. // RequestInfo is a parsed request information to throw into application's handler.
type RequestInfo struct { type RequestInfo struct {
// Application is a name of application. We should ask it's handler for metrics.
Application string Application string
// Metric is a metric name with parameters (e.g. requests{path='/',code=200} will
// be "requests/path:\//code:200").
Metric string 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 RequestType string
// APIVersion is a version of API requested.
APIVersion int APIVersion int
} }

View File

@ -9,6 +9,7 @@ import (
"go.dev.pztrn.name/metricator/internal/models" "go.dev.pztrn.name/metricator/internal/models"
) )
// ErrMetricNotFound appears if requested metric wasn't found in storage.
var ErrMetricNotFound = errors.New("metric not found") var ErrMetricNotFound = errors.New("metric not found")
// Storage is an in-memory storage. // Storage is an in-memory storage.
@ -16,9 +17,8 @@ type Storage struct {
ctx context.Context ctx context.Context
doneChan chan struct{} doneChan chan struct{}
logger *logger.Logger logger *logger.Logger
name string
data map[string]models.Metric data map[string]models.Metric
name string
dataMutex sync.RWMutex dataMutex sync.RWMutex
} }