Core Service: Unique ID generation service using Snowflake-like algorithm
- Multi-protocol support: memcached-compatible, HTTP API, gRPC
- Auto worker ID assignment: Redis-based distributed worker management
- Graceful shutdown: Context-based lifecycle management across all protocols
Key Components:
app.go- Main application logic and custom slog handlergenerator.go- Snowflake-like ID generation algorithmmemcache.go,http.go,grpc.go- Protocol implementationscmd/katsubushi/main.go- CLI entry point
make all- Generate gRPC code and build binarymake test- Run tests with race detectionmake packages- Cross-platform builds with GoReleasermake docker- Multi-architecture Docker buildsaquafor CLI tool managementbuffor Protocol Buffers generation
- Standalone execution (manual worker ID)
- Redis-coordinated auto worker ID assignment
- Docker/Kubernetes deployment
- Unix Domain Socket support
- Context management: Graceful shutdown across all servers
- Atomic operations:
sync/atomicfor statistics counters - Error handling: Custom error types for domain-specific errors
- Resource management:
deferfor cleanup - Test injection:
nowFuncvariable for time.Now substitution
- Custom slog.Handler maintains original log format:
2025-08-01T22:11:28.043+0900 INFO go-katsubushi/grpc.go:94 Message - Use
slog.SetDefault()to avoid data races, not global logger variables - Import
log/slogin all files and use slog functions directly - Debug logs added for all protocols (memcached, gRPC, HTTP API)
- Use individual file specification:
git add <file>notgit add -A - Always run
go fmt ./...before committing - Commit messages and code comments in English
- Run
go test -race ./...to detect data races - Protocol-specific test coverage (app_test.go, http_test.go, grpc_test.go, etc.)
- Worker ID uniqueness validation
- Build verification:
go build ./cmd/katsubushi/
- Core: gRPC, Protocol Buffers, gomemcache
- Infrastructure: fujiwara/raus (Redis auto-assignment)
- Development: buf, aqua, goreleaser