Skip to content

API consolidation: context-first, iter.Seq walkers, slog#53

Merged
epk merged 1 commit into
masterfrom
structural-modernize
Mar 12, 2026
Merged

API consolidation: context-first, iter.Seq walkers, slog#53
epk merged 1 commit into
masterfrom
structural-modernize

Conversation

@epk

@epk epk commented Mar 12, 2026

Copy link
Copy Markdown
Member

Summary

Breaking API change that removes ~32 redundant surface points and modernizes the codebase. Net -279 lines across 24 files.

Conn: remove non-Ctx wrappers, rename FooCtx → Foo

Every Conn method existed as both Foo() and FooCtx(ctx, ...). Delete the wrappers, rename FooCtx to Foo. All 22 public Conn methods now take context.Context as first parameter:

AddAuth, AddWatch, RemoveWatch, Children, ChildrenW, Get, GetW, Set, Create, CreateContainer, CreateTTL, CreateProtectedEphemeralSequential, Delete, Exists, ExistsW, GetACL, SetACL, Sync, Multi, MultiRead, IncrementalReconfig, Reconfig

Lock: same consolidation

  • Lock(ctx) / Unlock(ctx) / LockWithData(ctx, data) — removed LockCtx, UnlockCtx, LockWithDataCtx

Tree walkers: add iter.Seq, remove channel-based APIs

Add All(ctx) → (iter.Seq, func() error) for iterator-based traversal. Keep Walk(ctx, visitor) for error-aware callback traversal. Remove WalkChan, WalkChanCtx, and VisitEvent struct.

  • TreeWalker.All(ctx) → (iter.Seq2[string, *Stat], func() error)
  • TreeWalker.Walk(ctx, VisitorFunc) → error
  • BatchTreeWalker.All(ctx) → (iter.Seq[string], func() error)
  • BatchTreeWalker.Walk(ctx, BatchVisitorFunc) → error

Removed types: VisitorCtxFunc, BatchVisitorCtxFunc, VisitEvent

Removed deprecated APIs

  • ConnectWithDialer — use Connect(..., WithDialer(...))

Logger: log → log/slog

  • Conn.logger is now *slog.Logger (was custom Logger interface)
  • WithLogger accepts *slog.Logger
  • SetLogger accepts *slog.Logger
  • Removed Logger interface and DefaultLogger variable
  • Removed defaultLogger struct from structs.go
  • All logger.Printf calls → structured slog.Info/slog.Error
  • RefreshDNSHostProvider uses slog.Error directly
  • Test/example files: log.Printfslog.Info/slog.Error

Other cleanup

  • Version: replace LessThan/GreaterThan/Equal implementations with Compare using cmp.Compare
  • ring_buffer_test.go: use slices.Equal instead of custom slicesEqual helper
  • util.go: remove now-unused slicesEqual function
  • dnshostprovider.go: found := []string{}var found []string
  • server_help_test.go, server_java_test.go, conn.go: %v%w in error wrapping
  • All test/example call sites updated with context.Background() as first arg

Test plan

  • go build ./...
  • go vet ./...
  • go tool golangci-lint run
  • go fix -diff ./...
  • go test ./... (requires ZK test cluster)

🤖 Generated with Claude Code

@epk
epk force-pushed the structural-modernize branch from 08c8335 to 9d72ba1 Compare March 12, 2026 17:07
Base automatically changed from modernize-go to master March 12, 2026 17:21
@epk
epk force-pushed the structural-modernize branch from 044af52 to 0968d99 Compare March 12, 2026 18:01
@epk epk changed the title Structural modernization for Go 1.26 Modernize Go: context-first APIs, iter.Seq walkers, slog, Go 1.26 Mar 12, 2026
@epk
epk force-pushed the structural-modernize branch 2 times, most recently from e16ded8 to 2a8007b Compare March 12, 2026 18:26
@epk epk changed the title Modernize Go: context-first APIs, iter.Seq walkers, slog, Go 1.26 API consolidation: context-first, iter.Seq walkers, slog Mar 12, 2026
Comment thread _examples/cached_leaves_walker.go Outdated
package main

import (
"context"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just delete this file. The cached leaves walker was removed a while ago - this example should have been removed, too.

@jpfourny jpfourny left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot find anything wrong, other than these are API breaking changes. Mind you, it should be trivial to update downstream consumers.

Comprehensive modernization targeting Go 1.26. Breaking API change
that removes ~32 redundant API surface points.

Conn: remove all non-Ctx wrapper methods, rename FooCtx → Foo.
Every public Conn method now takes context.Context as first parameter.

Lock: remove Lock/LockCtx, Unlock/UnlockCtx redundancy. Lock(ctx),
Unlock(ctx), LockWithData(ctx, data) are the only forms.

Tree walkers: add iter.Seq-based All(ctx) alongside callback-based
Walk(ctx, visitor). Remove WalkChan, WalkChanCtx, VisitEvent.

Other: remove deprecated ConnectWithDialer, replace log with log/slog,
update GitHub Actions, remove tools/ module (linter via go tool),
adopt Go 1.26 features (range over func, sync.OnceFunc, etc).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@epk
epk force-pushed the structural-modernize branch from 2a8007b to 4b251ab Compare March 12, 2026 20:36
@epk

epk commented Mar 12, 2026

Copy link
Copy Markdown
Member Author

Tested with the CoreDNS MCS plugin, compiles and runs fine

@epk
epk merged commit 36f2a29 into master Mar 12, 2026
3 checks passed
@epk
epk deleted the structural-modernize branch March 12, 2026 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants