fix(lint): clean linter issues
All checks were successful
agola/nurse/Test and lint The run finished successfully
All checks were successful
agola/nurse/Test and lint The run finished successfully
This commit is contained in:
parent
c52912c5aa
commit
df6f6d55cb
9 changed files with 14 additions and 9 deletions
|
@ -52,7 +52,9 @@ func Identity[T any](in T) (T, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseUint(val string) (uint, 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 {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ const (
|
||||||
urlSchemeRegex = `^(?P<scheme>\w+)://((?P<username>[\w-.]+)(:(?P<password>.*))?@)?(\{(?P<hosts>(.+:\d{1,5})(,(.+:\d{1,5}))*)}|(?P<host>.+:\d{1,5}))(?P<path>/.*$)?`
|
urlSchemeRegex = `^(?P<scheme>\w+)://((?P<username>[\w-.]+)(:(?P<password>.*))?@)?(\{(?P<hosts>(.+:\d{1,5})(,(.+:\d{1,5}))*)}|(?P<host>.+:\d{1,5}))(?P<path>/.*$)?`
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//nolint:goconst
|
||||||
func (t ServerType) Scheme() string {
|
func (t ServerType) Scheme() string {
|
||||||
switch t {
|
switch t {
|
||||||
case ServerTypeRedis:
|
case ServerTypeRedis:
|
||||||
|
|
9
main.go
9
main.go
|
@ -5,6 +5,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"go.uber.org/zap/zapcore"
|
"go.uber.org/zap/zapcore"
|
||||||
|
@ -56,7 +57,13 @@ func main() {
|
||||||
logger.Fatal("Failed to prepare server mux", zap.Error(err))
|
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) {
|
if errors.Is(err, http.ErrServerClosed) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@ func Module() *check.Module {
|
||||||
return &GenericCheck{Method: http.MethodDelete}
|
return &GenericCheck{Method: http.MethodDelete}
|
||||||
})),
|
})),
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,6 @@ func (g *GenericCheck) SetClient(client *http.Client) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GenericCheck) Execute(ctx check.Context) error {
|
func (g *GenericCheck) Execute(ctx check.Context) error {
|
||||||
//TODO adopt
|
|
||||||
var body io.Reader
|
var body io.Reader
|
||||||
if len(g.Body) > 0 {
|
if len(g.Body) > 0 {
|
||||||
body = bytes.NewReader(g.Body)
|
body = bytes.NewReader(g.Body)
|
||||||
|
|
|
@ -14,7 +14,6 @@ func Module() *check.Module {
|
||||||
return new(GetCheck)
|
return new(GetCheck)
|
||||||
})),
|
})),
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ func Module() *check.Module {
|
||||||
return new(SelectCheck)
|
return new(SelectCheck)
|
||||||
})),
|
})),
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ func TestChecks_Execute(t *testing.T) {
|
||||||
srvName, srv = PrepareMariaDBContainer(t)
|
srvName, srv = PrepareMariaDBContainer(t)
|
||||||
case config.ServerTypePostgres:
|
case config.ServerTypePostgres:
|
||||||
srvName, srv = PreparePostgresContainer(t)
|
srvName, srv = PreparePostgresContainer(t)
|
||||||
case config.ServerTypeRedis:
|
case config.ServerTypeRedis, config.ServerTypeUnspecified:
|
||||||
fallthrough
|
fallthrough
|
||||||
default:
|
default:
|
||||||
t.Fatalf("unexpected server type: %s", st.Scheme())
|
t.Fatalf("unexpected server type: %s", st.Scheme())
|
||||||
|
|
|
@ -36,10 +36,9 @@ func DBForServer(srv *config.Server) (*sql.DB, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return sql.Open(srv.Type.Driver(), dsns[0])
|
return sql.Open(srv.Type.Driver(), dsns[0])
|
||||||
case config.ServerTypeRedis:
|
case config.ServerTypeRedis, config.ServerTypeUnspecified:
|
||||||
fallthrough
|
fallthrough
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unmatched server type for SQL DB: %s", srv.Type.Scheme())
|
return nil, fmt.Errorf("unmatched server type for SQL DB: %s", srv.Type.Scheme())
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue