[GH-ISSUE #359] Go Report Card findings: reduce cyclomatic complexity and fix typo #6836

Open
opened 2026-06-18 18:46:21 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @marcschaeferger on GitHub (May 15, 2026).
Original GitHub issue: https://github.com/fosrl/newt/issues/359

Originally assigned to: @marcschaeferger on GitHub.

Summary

Go Report Card currently reports no issues for gofmt, go vet, ineffassign, and license checks. However, there are several gocyclo warnings for functions with cyclomatic complexity above the recommended threshold of 15, plus one minor spelling issue.

https://goreportcard.com/report/github.com/fosrl/newt

Current status

Passing checks

  • gofmt: 100%
    • Code is formatted with gofmt -s
  • go vet: 100%
    • No suspicious constructs detected
  • ineffassign: 100%
    • No ineffectual assignments detected
  • license: 100%
    • LICENSE file exists

Issues to address

High cyclomatic complexity

Go Report Card warns for functions with cyclomatic complexity greater than 15.

File Line Function Complexity
websocket/client.go 218 (*Client).getToken() 19
websocket/client.go 336 (*Client).establishConnection() 17
wgnetstack/wgnetstack.go 786 (*WireGuardService).calculatePeerBandwidth() 17
proxy/manager.go 290 (*ProxyManager).handleUDPProxy() 17
main.go 128 main() 165
main.go 1261 validateTLSConfig() 17
util.go 232 startPingCheck() 25
docker/client.go 159 ListContainers() 25
wg/wg.go 601 (*WireGuardService).handleUpdatePeer() 19

The most important target is main() in main.go, which currently has a complexity of 165. This should probably be split into smaller functions for configuration loading, validation, dependency initialization, service startup, signal handling, and shutdown logic.

Idea

  • Refactor large functions into smaller, testable helper functions.
  • Prioritize main.go, especially main(), because it is by far the largest complexity outlier.
  • Avoid behavior changes during the refactor.
  • Add or adjust tests where possible to make sure the refactoring does not change runtime behavior.
  • Keep the public API and configuration behavior unchanged unless explicitly required.

Minor typo

misspell reports one typo:

File Line Current Suggested
wg/wg.go 329 exising existing

Acceptance criteria

  • Fix the typo in wg/wg.go.
  • Reduce cyclomatic complexity of the listed functions where reasonably possible.
  • At minimum, significantly reduce the complexity of main().
  • Keep existing behavior unchanged.
  • gofmt -s passes.
  • go vet passes.
  • ineffassign passes.
  • Go Report Card no longer reports avoidable gocyclo or misspell warnings.
Originally created by @marcschaeferger on GitHub (May 15, 2026). Original GitHub issue: https://github.com/fosrl/newt/issues/359 Originally assigned to: @marcschaeferger on GitHub. ### Summary Go Report Card currently reports no issues for `gofmt`, `go vet`, `ineffassign`, and license checks. However, there are several `gocyclo` warnings for functions with cyclomatic complexity above the recommended threshold of `15`, plus one minor spelling issue. https://goreportcard.com/report/github.com/fosrl/newt ### Current status #### Passing checks - `gofmt`: 100% - Code is formatted with `gofmt -s` - `go vet`: 100% - No suspicious constructs detected - `ineffassign`: 100% - No ineffectual assignments detected - `license`: 100% - LICENSE file exists ### Issues to address #### High cyclomatic complexity Go Report Card warns for functions with cyclomatic complexity greater than `15`. | File | Line | Function | Complexity | |---|---:|---|---:| | `websocket/client.go` | 218 | `(*Client).getToken()` | 19 | | `websocket/client.go` | 336 | `(*Client).establishConnection()` | 17 | | `wgnetstack/wgnetstack.go` | 786 | `(*WireGuardService).calculatePeerBandwidth()` | 17 | | `proxy/manager.go` | 290 | `(*ProxyManager).handleUDPProxy()` | 17 | | `main.go` | 128 | `main()` | 165 | | `main.go` | 1261 | `validateTLSConfig()` | 17 | | `util.go` | 232 | `startPingCheck()` | 25 | | `docker/client.go` | 159 | `ListContainers()` | 25 | | `wg/wg.go` | 601 | `(*WireGuardService).handleUpdatePeer()` | 19 | The most important target is `main()` in `main.go`, which currently has a complexity of `165`. This should probably be split into smaller functions for configuration loading, validation, dependency initialization, service startup, signal handling, and shutdown logic. ### Idea - Refactor large functions into smaller, testable helper functions. - Prioritize `main.go`, especially `main()`, because it is by far the largest complexity outlier. - Avoid behavior changes during the refactor. - Add or adjust tests where possible to make sure the refactoring does not change runtime behavior. - Keep the public API and configuration behavior unchanged unless explicitly required. ### Minor typo `misspell` reports one typo: | File | Line | Current | Suggested | |---|---:|---|---| | `wg/wg.go` | 329 | `exising` | `existing` | ### Acceptance criteria - [ ] Fix the typo in `wg/wg.go`. - [ ] Reduce cyclomatic complexity of the listed functions where reasonably possible. - [ ] At minimum, significantly reduce the complexity of `main()`. - [ ] Keep existing behavior unchanged. - [ ] `gofmt -s` passes. - [ ] `go vet` passes. - [ ] `ineffassign` passes. - [ ] Go Report Card no longer reports avoidable `gocyclo` or `misspell` warnings.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/newt#6836