Skip to content

Commit 01c840f

Browse files
committed
feat: reduce logger noise
1 parent 5b3aa70 commit 01c840f

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

config.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ import (
1111

1212
// Configuration structure
1313
type Config struct {
14-
CanPorts []string
15-
Port string
16-
AutoSetup bool // Auto setup CAN interfaces on startup
17-
Bitrate int // Default bitrate for CAN interfaces
18-
SamplePoint string // Default sample point
19-
RestartMs int // Default restart timeout
20-
SetupRetry int // Number of setup retry attempts
21-
SetupDelay time.Duration // Delay between setup retries
14+
CanPorts []string
15+
Port string
16+
AutoSetup bool // Auto setup CAN interfaces on startup
17+
Bitrate int // Default bitrate for CAN interfaces
18+
SamplePoint string // Default sample point
19+
RestartMs int // Default restart timeout
20+
SetupRetry int // Number of setup retry attempts
21+
SetupDelay time.Duration // Delay between setup retries
22+
EnableFinder bool // Enable service finder
23+
SetupFinderInterval time.Duration // Interval for service finder
2224
}
2325

2426
// ConfigProvider interface for dependency injection
@@ -115,6 +117,8 @@ func (cp *ConfigParser) ParseConfig() (*Config, error) {
115117
var restartMs int
116118
var setupRetry int
117119
var setupDelaySeconds int
120+
var setupFinderEnabled bool
121+
var setupFinderInterval int
118122

119123
flag.StringVar(&canPortsFlag, "can-ports", "", "Comma-separated list of CAN interfaces (e.g., can0,can1)")
120124
flag.StringVar(&serverPort, "port", "5260", "HTTP server port")
@@ -124,6 +128,8 @@ func (cp *ConfigParser) ParseConfig() (*Config, error) {
124128
flag.IntVar(&restartMs, "restart-ms", 100, "Default CAN restart timeout (ms)")
125129
flag.IntVar(&setupRetry, "setup-retry", 3, "Number of setup retry attempts")
126130
flag.IntVar(&setupDelaySeconds, "setup-delay", 2, "Delay between setup retries (seconds)")
131+
flag.BoolVar(&setupFinderEnabled, "enable-finder", true, "Enable service finder")
132+
flag.IntVar(&setupFinderInterval, "finder-interval", 5, "Interval for service finder in seconds")
127133
flag.Parse()
128134

129135
// Environment variables (override command line)
@@ -174,13 +180,22 @@ func (cp *ConfigParser) ParseConfig() (*Config, error) {
174180
if serverPort == "" {
175181
return nil, fmt.Errorf("server port cannot be empty")
176182
}
183+
184+
if setupFinderEnabled {
185+
if setupFinderInterval <= 0 {
186+
return nil, fmt.Errorf("finder interval must be positive, got %d", config.SetupFinderInterval)
187+
}
188+
}
189+
177190
config.Port = serverPort
178191
config.AutoSetup = autoSetup
179192
config.Bitrate = bitrate
180193
config.SamplePoint = samplePoint
181194
config.RestartMs = restartMs
182195
config.SetupRetry = setupRetry
183196
config.SetupDelay = time.Duration(setupDelaySeconds) * time.Second
197+
config.EnableFinder = setupFinderEnabled
198+
config.SetupFinderInterval = time.Duration(setupFinderInterval) * time.Second
184199

185200
return config, nil
186201
}

finder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type DeviceInfo struct {
1717
Version string `json:"version"`
1818
}
1919

20-
func NodeFinder() {
20+
func NodeFinder(interval time.Duration) {
2121
broadcastAddr := "255.255.255.255:9999"
2222

2323
conn, err := net.DialUDP("udp4", nil, resolveUDPAddr(broadcastAddr))
@@ -49,7 +49,7 @@ func NodeFinder() {
4949
log.Printf("📡 Broadcast successful: %s", string(data))
5050
}
5151

52-
time.Sleep(5 * time.Second)
52+
time.Sleep(interval * time.Second)
5353
}
5454
}
5555

main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,9 @@ func (s *Service) Start(ctx context.Context) error {
263263
}
264264

265265
// Start Node Finder in a separate goroutine
266-
go NodeFinder()
266+
if s.config.EnableFinder {
267+
go NodeFinder(s.config.SetupFinderInterval)
268+
}
267269

268270
// Start HTTP server in a goroutine
269271
go func() {

0 commit comments

Comments
 (0)