fix: make internals yaegi-interpretable for traefik plugin consumers

Swap atomic.Pointer[string] for a mutex-guarded string, atomic.Bool for the function-based sync/atomic int32 API, two range-over-int loops for classic index loops, and drop the init() that seeded the endpoint pointer. No public API or runtime behaviour change; go test, go vet, and golangci-lint all pass.

Rationale: the traefikoidc Traefik plugin vendors and interprets dependency source via Yaegi, which on several Traefik runtimes cannot interpret generic stdlib types or range-over-int. This keeps the package importable from that plugin without altering what it does.
This commit is contained in:
2026-05-30 12:35:42 +01:00
parent 1fb9f14efa
commit f06f5561d4
2 changed files with 36 additions and 23 deletions
+8 -9
View File
@@ -25,22 +25,21 @@ type pingPayload struct {
// each other. Tests share `disabled`, `endpoint`, and `inflight`.
func resetState(t *testing.T) {
t.Helper()
disabled.Store(false)
atomic.StoreInt32(&disabled, 0)
t.Cleanup(func() {
disabled.Store(false)
atomic.StoreInt32(&disabled, 0)
})
}
// setEndpoint atomically retargets the ingest URL for the duration of a test
// and restores it on cleanup. Safe even if Send goroutines outlive the test.
// setEndpoint retargets the ingest URL for the duration of a test and restores
// it on cleanup. Safe even if Send goroutines outlive the test (the setter is
// mutex-guarded).
func setEndpoint(t *testing.T, url string) {
t.Helper()
prev := *endpoint.Load()
s := url
endpoint.Store(&s)
prev := currentEndpoint()
setEndpointURL(url)
t.Cleanup(func() {
p := prev
endpoint.Store(&p)
setEndpointURL(prev)
})
}