Skip to content

Commit 5deca89

Browse files
committed
[lint] fix more issues
1 parent 923a83f commit 5deca89

File tree

18 files changed

+124
-250
lines changed

18 files changed

+124
-250
lines changed

internal/sms-gateway/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func Module() fx.Option {
5151
events.Module(),
5252
messages.Module(),
5353
health.Module(),
54-
webhooks.Module,
54+
webhooks.Module(),
5555
settings.Module(),
5656
devices.Module,
5757
metrics.Module,

internal/sms-gateway/handlers/messages/params.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package messages
22

33
import (
4-
"fmt"
4+
"errors"
55
"time"
66

77
"github.com/android-sms-gateway/server/internal/sms-gateway/modules/messages"
@@ -23,7 +23,7 @@ type thirdPartyGetQueryParams struct {
2323

2424
func (p *thirdPartyGetQueryParams) Validate() error {
2525
if p.StartDate != "" && p.EndDate != "" && p.StartDate > p.EndDate {
26-
return fmt.Errorf("`from` date must be before `to` date")
26+
return errors.New("`from` date must be before `to` date") //nolint:err113 // won't used directly
2727
}
2828

2929
return nil

internal/sms-gateway/modules/db/health.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@ func (h *health) StartedProbe(ctx context.Context) (healthmod.Checks, error) {
5757
return nil, nil
5858
}
5959

60-
var _ healthmod.HealthProvider = (*health)(nil)
60+
var _ healthmod.Provider = (*health)(nil)

internal/sms-gateway/modules/health/health.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
type health struct {
99
}
1010

11-
func NewHealth() *health {
11+
func newHealth() *health {
1212
return &health{}
1313
}
1414

@@ -18,48 +18,50 @@ func (h *health) Name() string {
1818
}
1919

2020
// LiveProbe implements HealthProvider.
21-
func (h *health) LiveProbe(ctx context.Context) (Checks, error) {
22-
const oneGiB uint64 = 1 << 30
21+
func (h *health) LiveProbe(_ context.Context) (Checks, error) {
22+
const oneMiB uint64 = 1 << 20
23+
const memoryThreshold uint64 = 128 * oneMiB
24+
const goroutineThreshold = 100
2325

2426
var m runtime.MemStats
2527
runtime.ReadMemStats(&m)
2628

2729
// Basic runtime health checks
2830
goroutineCheck := CheckDetail{
2931
Description: "Number of goroutines",
30-
ObservedValue: int(runtime.NumGoroutine()),
32+
ObservedValue: runtime.NumGoroutine(),
3133
ObservedUnit: "goroutines",
3234
Status: StatusPass,
3335
}
3436

3537
memoryCheck := CheckDetail{
3638
Description: "Memory usage",
37-
ObservedValue: int(m.Alloc / 1024 / 1024), // MiB
39+
ObservedValue: int(m.Alloc / oneMiB), //nolint:gosec // not a security issue
3840
ObservedUnit: "MiB",
3941
Status: StatusPass,
4042
}
4143

4244
// Check for potential memory issues
43-
if m.Alloc > oneGiB { // 1GB
45+
if m.Alloc > memoryThreshold {
4446
memoryCheck.Status = StatusWarn
4547
}
4648

4749
// Check for excessive goroutines
48-
if goroutineCheck.ObservedValue > 1000 {
50+
if goroutineCheck.ObservedValue > goroutineThreshold {
4951
goroutineCheck.Status = StatusWarn
5052
}
5153

5254
return Checks{"goroutines": goroutineCheck, "memory": memoryCheck}, nil
5355
}
5456

5557
// ReadyProbe implements HealthProvider.
56-
func (h *health) ReadyProbe(ctx context.Context) (Checks, error) {
57-
return nil, nil
58+
func (h *health) ReadyProbe(_ context.Context) (Checks, error) {
59+
return nil, nil //nolint:nilnil // empty result
5860
}
5961

6062
// StartedProbe implements HealthProvider.
61-
func (h *health) StartedProbe(ctx context.Context) (Checks, error) {
62-
return nil, nil
63+
func (h *health) StartedProbe(_ context.Context) (Checks, error) {
64+
return nil, nil //nolint:nilnil // empty result
6365
}
6466

65-
var _ HealthProvider = (*health)(nil)
67+
var _ Provider = (*health)(nil)

internal/sms-gateway/modules/health/module.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func Module() fx.Option {
1212
return log.Named("health")
1313
}),
1414
fx.Provide(
15-
AsHealthProvider(NewHealth),
15+
AsHealthProvider(newHealth),
1616
fx.Private,
1717
),
1818
fx.Provide(
@@ -24,7 +24,7 @@ func Module() fx.Option {
2424
func AsHealthProvider(f any) any {
2525
return fx.Annotate(
2626
f,
27-
fx.As(new(HealthProvider)),
27+
fx.As(new(Provider)),
2828
fx.ResultTags(`group:"health-providers"`),
2929
)
3030
}

internal/sms-gateway/modules/health/service.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import (
1010
type ServiceParams struct {
1111
fx.In
1212

13-
HealthProviders []HealthProvider `group:"health-providers"`
13+
HealthProviders []Provider `group:"health-providers"`
1414

1515
Logger *zap.Logger
1616
}
1717

1818
type Service struct {
19-
healthProviders []HealthProvider
19+
healthProviders []Provider
2020

2121
logger *zap.Logger
2222
}
@@ -31,7 +31,7 @@ func NewService(params ServiceParams) *Service {
3131

3232
func (s *Service) checkProvider(
3333
ctx context.Context,
34-
probe func(context.Context, HealthProvider) (Checks, error),
34+
probe func(context.Context, Provider) (Checks, error),
3535
) CheckResult {
3636
check := CheckResult{
3737
Checks: map[string]CheckDetail{},
@@ -69,19 +69,19 @@ func (s *Service) checkProvider(
6969
}
7070

7171
func (s *Service) CheckReadiness(ctx context.Context) CheckResult {
72-
return s.checkProvider(ctx, func(ctx context.Context, p HealthProvider) (Checks, error) {
72+
return s.checkProvider(ctx, func(ctx context.Context, p Provider) (Checks, error) {
7373
return p.ReadyProbe(ctx)
7474
})
7575
}
7676

7777
func (s *Service) CheckLiveness(ctx context.Context) CheckResult {
78-
return s.checkProvider(ctx, func(ctx context.Context, p HealthProvider) (Checks, error) {
78+
return s.checkProvider(ctx, func(ctx context.Context, p Provider) (Checks, error) {
7979
return p.LiveProbe(ctx)
8080
})
8181
}
8282

8383
func (s *Service) CheckStartup(ctx context.Context) CheckResult {
84-
return s.checkProvider(ctx, func(ctx context.Context, p HealthProvider) (Checks, error) {
84+
return s.checkProvider(ctx, func(ctx context.Context, p Provider) (Checks, error) {
8585
return p.StartedProbe(ctx)
8686
})
8787
}

internal/sms-gateway/modules/health/types.go

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,13 @@ const (
1717
levelFail statusLevel = 2
1818
)
1919

20-
var statusLevels = map[statusLevel]Status{
21-
levelPass: StatusPass,
22-
levelWarn: StatusWarn,
23-
levelFail: StatusFail,
24-
}
25-
26-
// Health status of the application.
20+
// CheckResult represents the result of a set of health checks.
2721
type CheckResult struct {
2822
// A map of check names to their respective details.
29-
Checks Checks
23+
Checks Checks `json:"checks"`
3024
}
3125

32-
// Overall status of the application.
26+
// Status returns the overall status of the application.
3327
// It can be one of the following values: "pass", "warn", or "fail".
3428
func (c CheckResult) Status() Status {
3529
// Determine overall status
@@ -44,10 +38,19 @@ func (c CheckResult) Status() Status {
4438
}
4539
}
4640

47-
return statusLevels[level]
41+
switch level {
42+
case levelPass:
43+
return StatusPass
44+
case levelWarn:
45+
return StatusWarn
46+
case levelFail:
47+
return StatusFail
48+
}
49+
50+
return StatusFail
4851
}
4952

50-
// Details of a health check.
53+
// CheckDetail of a health check.
5154
type CheckDetail struct {
5255
// A human-readable description of the check.
5356
Description string
@@ -60,10 +63,10 @@ type CheckDetail struct {
6063
Status Status
6164
}
6265

63-
// Map of check names to their respective details.
66+
// Checks is a map of check names to their respective details.
6467
type Checks map[string]CheckDetail
6568

66-
type HealthProvider interface {
69+
type Provider interface {
6770
Name() string
6871

6972
StartedProbe(ctx context.Context) (Checks, error)

internal/sms-gateway/modules/messages/service_test.go

Lines changed: 0 additions & 158 deletions
This file was deleted.

0 commit comments

Comments
 (0)