Skip to content

Commit 7e3d5db

Browse files
committed
fix: more lint issues
1 parent 743c59d commit 7e3d5db

File tree

13 files changed

+95
-86
lines changed

13 files changed

+95
-86
lines changed

.golangci.json

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,37 @@
11
{
22
"version": "2",
33
"linters": {
4-
"default": "none",
5-
"enable": [
6-
"canonicalheader",
7-
"copyloopvar",
8-
"dupword",
9-
"errorlint",
10-
"exptostd",
11-
"fatcontext",
12-
"ginkgolinter",
13-
"gocritic",
14-
"godot",
15-
"goheader",
16-
"govet",
17-
"iface",
18-
"importas",
19-
"intrange",
20-
"mirror",
21-
"misspell",
22-
"nakedret",
23-
"nlreturn",
24-
"nolintlint",
25-
"perfsprint",
26-
"protogetter",
27-
"sloglint",
28-
"staticcheck",
29-
"tagalign",
30-
"testifylint",
31-
"usestdlibvars",
32-
"usetesting",
33-
"whitespace",
34-
"wsl_v5"
35-
],
4+
"default": "all",
365
"disable": [
37-
"revive"
38-
]
6+
"cyclop",
7+
"depguard",
8+
"err113",
9+
"exhaustruct",
10+
"forcetypeassert",
11+
"funlen",
12+
"gocognit",
13+
"interfacebloat",
14+
"ireturn",
15+
"lll",
16+
"mnd",
17+
"nestif",
18+
"nilnil",
19+
"noinlineerr",
20+
"nonamedreturns",
21+
"revive",
22+
"tagliatelle",
23+
"varnamelen",
24+
"wsl"
25+
],
26+
"settings": {
27+
"gosec": {
28+
"excludes": [
29+
"G115",
30+
"G204",
31+
"G404"
32+
]
33+
}
34+
}
3935
},
4036
"run": {
4137
"timeout": "1m"

api/handshake/requests.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,6 @@ type InitHandshakeRequest struct {
1313
Body node.InitHandshakeRequestBody
1414
}
1515

16-
// AccAddr returns the account address from the request body.
17-
func (r *InitHandshakeRequest) AccAddr() types.AccAddress {
18-
addr, err := r.Body.AccAddr()
19-
if err != nil {
20-
panic(fmt.Errorf("getting account addr from request body: %w", err))
21-
}
22-
23-
return addr
24-
}
25-
26-
// PeerRequest returns the peer request from request body.
27-
func (r *InitHandshakeRequest) PeerRequest() []byte {
28-
return r.Body.Data
29-
}
30-
3116
// NewInitHandshakeRequest parses, binds, and verifies the handshake request.
3217
func NewInitHandshakeRequest(c *gin.Context) (req *InitHandshakeRequest, err error) {
3318
req = &InitHandshakeRequest{}
@@ -44,3 +29,18 @@ func NewInitHandshakeRequest(c *gin.Context) (req *InitHandshakeRequest, err err
4429

4530
return req, nil
4631
}
32+
33+
// AccAddr returns the account address from the request body.
34+
func (r *InitHandshakeRequest) AccAddr() types.AccAddress {
35+
addr, err := r.Body.AccAddr()
36+
if err != nil {
37+
panic(fmt.Errorf("getting account addr from request body: %w", err))
38+
}
39+
40+
return addr
41+
}
42+
43+
// PeerRequest returns the peer request from request body.
44+
func (r *InitHandshakeRequest) PeerRequest() []byte {
45+
return r.Body.Data
46+
}

cmd/init.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ is set to overwrite the existing configuration.`,
4343
RunE: func(cmd *cobra.Command, args []string) error {
4444
// Create the home directory if it doesn't exist
4545
homeDir := viper.GetString("home")
46-
if err := os.MkdirAll(homeDir, 0755); err != nil {
46+
if err := os.MkdirAll(homeDir, 0700); err != nil {
4747
return fmt.Errorf("creating application directory %q: %w", homeDir, err)
4848
}
4949

@@ -100,6 +100,8 @@ is set to overwrite the existing configuration.`,
100100
service = wireguard.NewServer("wireguard", homeDir, cfg.Services[types.ServiceTypeWireGuard].(*wireguard.ServerConfig))
101101
case types.ServiceTypeOpenVPN:
102102
service = openvpn.NewServer("openvpn", homeDir, cfg.Services[types.ServiceTypeOpenVPN].(*openvpn.ServerConfig))
103+
case types.ServiceTypeUnspecified:
104+
return fmt.Errorf("unsupported service type %q", serviceType)
103105
default:
104106
return fmt.Errorf("unsupported service type %q", serviceType)
105107
}

cmd/start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ explicitly starts the node, and handles SIGINT/SIGTERM for graceful shutdown.`,
8282

8383
// Wait for all goroutines to finish
8484
if err := eg.Wait(); err != nil {
85-
return err
85+
return fmt.Errorf("waiting group: %w", err)
8686
}
8787

8888
return nil

config/config.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,18 @@ var fs embed.FS
1919
// Config represents the overall configuration structure.
2020
type Config struct {
2121
*config.Config `mapstructure:",squash"`
22-
HandshakeDNS *HandshakeDNSConfig `mapstructure:"handshake_dns"` // HandshakeDNS contains Handshake DNS configuration.
23-
Node *NodeConfig `mapstructure:"node"` // Node contains node-specific configuration.
24-
QoS *QoSConfig `mapstructure:"qos"` // QoS contains Quality of Service configuration.
22+
23+
HandshakeDNS *HandshakeDNSConfig `mapstructure:"handshake_dns"` // HandshakeDNS contains Handshake DNS configuration.
24+
Node *NodeConfig `mapstructure:"node"` // Node contains node-specific configuration.
25+
QoS *QoSConfig `mapstructure:"qos"` // QoS contains Quality of Service configuration.
2526

2627
Services map[types.ServiceType]types.ServiceConfig `mapstructure:"-"`
2728
}
2829

2930
// Validate validates the entire configuration.
3031
func (c *Config) Validate() error {
3132
if err := c.Config.Validate(); err != nil {
32-
return err
33+
return fmt.Errorf("validating base config: %w", err)
3334
}
3435

3536
if err := c.HandshakeDNS.Validate(); err != nil {

core/context.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,6 @@ func NewContext() *Context {
5151
}
5252
}
5353

54-
// checkSealed verifies if the context is sealed to prevent modification.
55-
func (c *Context) checkSealed() {
56-
if c.sealed {
57-
panic(errors.New("context is sealed"))
58-
}
59-
}
60-
6154
// Seal marks the context as sealed, preventing further modifications.
6255
func (c *Context) Seal() *Context {
6356
c.sealed = true
@@ -391,3 +384,10 @@ func (c *Context) WithService(service sentinelsdk.ServerService) *Context {
391384

392385
return c
393386
}
387+
388+
// checkSealed verifies if the context is sealed to prevent modification.
389+
func (c *Context) checkSealed() {
390+
if c.sealed {
391+
panic(errors.New("context is sealed"))
392+
}
393+
}

core/setup.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (c *Context) SetupGeoIPClient(_ *config.Config) error {
6868
}
6969

7070
// SetupAccAddr retrieves the account address for transactions and assigns it to the context.
71-
func (c *Context) SetupAccAddr(cfg *config.Config) error {
71+
func (c *Context) SetupAccAddr(ctx context.Context, cfg *config.Config) error {
7272
log.Info("Retrieving addr for key", "name", cfg.Tx.GetFromName())
7373

7474
addr, err := c.Client().KeyAddr(cfg.Tx.GetFromName())
@@ -78,7 +78,7 @@ func (c *Context) SetupAccAddr(cfg *config.Config) error {
7878

7979
log.Info("Querying account information", "addr", addr)
8080

81-
acc, err := c.Client().Account(context.TODO(), addr)
81+
acc, err := c.Client().Account(ctx, addr)
8282
if err != nil {
8383
return fmt.Errorf("querying account %q: %w", addr, err)
8484
}
@@ -110,6 +110,8 @@ func (c *Context) SetupService(ctx context.Context, cfg *config.Config) error {
110110
s = wireguard.NewServer("wireguard", c.HomeDir(), cfg.Services[types.ServiceTypeWireGuard].(*wireguard.ServerConfig))
111111
case types.ServiceTypeOpenVPN:
112112
s = openvpn.NewServer("openvpn", c.HomeDir(), cfg.Services[types.ServiceTypeOpenVPN].(*openvpn.ServerConfig))
113+
case types.ServiceTypeUnspecified:
114+
return fmt.Errorf("unsupported service type %q", st)
113115
default:
114116
return fmt.Errorf("unsupported service type %q", st)
115117
}
@@ -126,7 +128,7 @@ func (c *Context) SetupService(ctx context.Context, cfg *config.Config) error {
126128
}
127129

128130
if err := s.Setup(ctx); err != nil {
129-
return err
131+
return err //nolint:wrapcheck
130132
}
131133

132134
// Assign the service to the context
@@ -173,7 +175,7 @@ func (c *Context) Setup(ctx context.Context, cfg *config.Config) error {
173175

174176
log.Info("Setting up account addr")
175177

176-
if err := c.SetupAccAddr(cfg); err != nil {
178+
if err := c.SetupAccAddr(ctx, cfg); err != nil {
177179
return fmt.Errorf("setting up account addr: %w", err)
178180
}
179181

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/cosmos/cosmos-sdk v0.47.17
88
github.com/gin-contrib/cors v1.7.6
99
github.com/gin-gonic/gin v1.10.1
10-
github.com/sentinel-official/sentinel-go-sdk v1.0.0-rc.6.0.20250907043146-0b770c8bbbff
10+
github.com/sentinel-official/sentinel-go-sdk v1.0.0-rc.6.0.20250907161203-2047e5767938
1111
github.com/sentinel-official/sentinelhub/v12 v12.0.0-rc.11
1212
github.com/spf13/cobra v1.10.1
1313
github.com/spf13/pflag v1.0.10

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,8 @@ github.com/secure-io/siv-go v0.0.0-20180922214919-5ff40651e2c4 h1:zOjq+1/uLzn/Xo
512512
github.com/secure-io/siv-go v0.0.0-20180922214919-5ff40651e2c4/go.mod h1:aI+8yClBW+1uovkHw6HM01YXnYB8vohtB9C83wzx34E=
513513
github.com/seiflotfy/cuckoofilter v0.0.0-20220411075957-e3b120b3f5fb h1:XfLJSPIOUX+osiMraVgIrMR27uMXnRJWGm1+GL8/63U=
514514
github.com/seiflotfy/cuckoofilter v0.0.0-20220411075957-e3b120b3f5fb/go.mod h1:bR6DqgcAl1zTcOX8/pE2Qkj9XO00eCNqmKb7lXP8EAg=
515-
github.com/sentinel-official/sentinel-go-sdk v1.0.0-rc.6.0.20250907043146-0b770c8bbbff h1:pbaC4XanYAOA5zclDa2SfLDX0/jhnt4VwATC2yGT0ns=
516-
github.com/sentinel-official/sentinel-go-sdk v1.0.0-rc.6.0.20250907043146-0b770c8bbbff/go.mod h1:Gq0+WlluP3Kg495B4mqgrUVn30m0YBGV8Nyu01A5V34=
515+
github.com/sentinel-official/sentinel-go-sdk v1.0.0-rc.6.0.20250907161203-2047e5767938 h1:mhnValOZZyz1JHvV+PZP+1Un6TEKg/cIbfJXltOqEFM=
516+
github.com/sentinel-official/sentinel-go-sdk v1.0.0-rc.6.0.20250907161203-2047e5767938/go.mod h1:Gq0+WlluP3Kg495B4mqgrUVn30m0YBGV8Nyu01A5V34=
517517
github.com/sentinel-official/sentinelhub/v12 v12.0.0-rc.11 h1:B3ylnKZSLP9aDYnS2f98Gx/QTohPuD36tjl75kYJSMs=
518518
github.com/sentinel-official/sentinelhub/v12 v12.0.0-rc.11/go.mod h1:LXcOAEffAn4Pw58xhoYN9j8ZVuM02OCgPNTI6lkGG2E=
519519
github.com/shirou/gopsutil/v4 v4.25.8 h1:NnAsw9lN7587WHxjJA9ryDnqhJpFH6A+wagYWTOH970=

main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package main
22

33
import (
4+
"context"
5+
"os"
6+
47
"github.com/sentinel-official/sentinel-go-sdk/app"
58

69
"github.com/sentinel-official/sentinel-dvpnx/cmd"
710
)
811

912
func main() {
10-
app.Run(cmd.NewRootCmd)
13+
exitCode := app.Run(context.Background(), cmd.NewRootCmd)
14+
os.Exit(exitCode)
1115
}

0 commit comments

Comments
 (0)