diff --git a/config/flags.go b/config/flags.go index 0c62061..84b523f 100644 --- a/config/flags.go +++ b/config/flags.go @@ -52,7 +52,9 @@ func Identity[T any](in T) (T, error) { } func parseUint(val string) (uint, error) { - parsed, err := strconv.ParseUint(val, 10, 32) + const baseDecimal = 10 + const int32BitSize = 32 + parsed, err := strconv.ParseUint(val, baseDecimal, int32BitSize) if err != nil { return 0, err } diff --git a/config/server.go b/config/server.go index e0025f2..dad5753 100644 --- a/config/server.go +++ b/config/server.go @@ -24,6 +24,7 @@ const ( urlSchemeRegex = `^(?P\w+)://((?P[\w-.]+)(:(?P.*))?@)?(\{(?P(.+:\d{1,5})(,(.+:\d{1,5}))*)}|(?P.+:\d{1,5}))(?P/.*$)?` ) +//nolint:goconst func (t ServerType) Scheme() string { switch t { case ServerTypeRedis: diff --git a/main.go b/main.go index 2221edd..34fcd87 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "log" "net/http" "os" + "time" "go.uber.org/zap" "go.uber.org/zap/zapcore" @@ -56,7 +57,13 @@ func main() { logger.Fatal("Failed to prepare server mux", zap.Error(err)) } - if err := http.ListenAndServe(":8080", mux); err != nil { + srv := http.Server{ + Addr: ":8080", + Handler: mux, + ReadHeaderTimeout: 100 * time.Millisecond, + } + + if err := srv.ListenAndServe(); err != nil { if errors.Is(err, http.ErrServerClosed) { return } diff --git a/protocols/http/checks.go b/protocols/http/checks.go index aac6e68..2541aee 100644 --- a/protocols/http/checks.go +++ b/protocols/http/checks.go @@ -22,7 +22,6 @@ func Module() *check.Module { return &GenericCheck{Method: http.MethodDelete} })), ) - if err != nil { panic(err) } diff --git a/protocols/http/get.go b/protocols/http/get.go index f742f90..5fc8d32 100644 --- a/protocols/http/get.go +++ b/protocols/http/get.go @@ -37,7 +37,6 @@ func (g *GenericCheck) SetClient(client *http.Client) { } func (g *GenericCheck) Execute(ctx check.Context) error { - //TODO adopt var body io.Reader if len(g.Body) > 0 { body = bytes.NewReader(g.Body) diff --git a/protocols/redis/checks.go b/protocols/redis/checks.go index 6191c70..519ed28 100644 --- a/protocols/redis/checks.go +++ b/protocols/redis/checks.go @@ -14,7 +14,6 @@ func Module() *check.Module { return new(GetCheck) })), ) - if err != nil { panic(err) } diff --git a/protocols/sql/checks.go b/protocols/sql/checks.go index 943b430..c554667 100644 --- a/protocols/sql/checks.go +++ b/protocols/sql/checks.go @@ -9,7 +9,6 @@ func Module() *check.Module { return new(SelectCheck) })), ) - if err != nil { panic(err) } diff --git a/protocols/sql/checks_test.go b/protocols/sql/checks_test.go index fd712a4..4a77da7 100644 --- a/protocols/sql/checks_test.go +++ b/protocols/sql/checks_test.go @@ -63,7 +63,7 @@ func TestChecks_Execute(t *testing.T) { srvName, srv = PrepareMariaDBContainer(t) case config.ServerTypePostgres: srvName, srv = PreparePostgresContainer(t) - case config.ServerTypeRedis: + case config.ServerTypeRedis, config.ServerTypeUnspecified: fallthrough default: t.Fatalf("unexpected server type: %s", st.Scheme()) diff --git a/protocols/sql/db.go b/protocols/sql/db.go index eea34ef..60a797d 100644 --- a/protocols/sql/db.go +++ b/protocols/sql/db.go @@ -36,10 +36,9 @@ func DBForServer(srv *config.Server) (*sql.DB, error) { } return sql.Open(srv.Type.Driver(), dsns[0]) - case config.ServerTypeRedis: + case config.ServerTypeRedis, config.ServerTypeUnspecified: fallthrough default: return nil, fmt.Errorf("unmatched server type for SQL DB: %s", srv.Type.Scheme()) } - }