feat(contract): prepare for Go 1.27 generic methods on structs#20
Merged
Conversation
Rename all SPI interfaces to *Driver suffix (CacheDriver, DatabaseDriver, EventDriver, SessionDriver) and introduce wrapper structs that take the "good" names (Cache, Database, Events, Session). - CacheDriver/EventDriver operate on []byte; wrappers handle JSON - Session moved from interface to struct with NewSession/NewSessionFrom - Wrapper structs expose Driver() accessor (not embedding) - CacheCounter optional interface for atomic incr/decr - Regenerate mocks for new interface signatures - Update all framework implementations and tests BREAKING CHANGE: All contract interfaces renamed with Driver suffix. Session is now a struct (*contract.Session) instead of an interface. Cache/Events wrappers handle serialization, drivers use raw []byte. This prepares for Go 1.27 generic methods on structs.
da5a95a to
27f1e5f
Compare
The database tests required go-sqlite3 (CGo) which prevents building without CGO_ENABLED=1. Since database.SQL is a thin sqlx adapter, meaningful testing requires a real database. Remove the tests rather than mock the implementation under test. Coverage remains at 0% as documented in AGENTS.md.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Rename all SPI interfaces to
*Driversuffix and introduce wrapper structs that take the "good" names. Wrapper structs will gain generic methods once Go 1.27 lands, enabling type-safe serialization without manual type assertions.Changes
Contract Module
Cache→CacheDriver,Database→DatabaseDriver,Events→EventDriver,Session(interface removed) →SessionDriverCache,Database,Events— exposeDriver()accessor (not embedding)*contract.Session) withNewSession,NewSessionFrom,All()[]byte; wrappers handle JSON serializationFramework Module
*Driverinterfacesframework/cache: Memory and Redis implementCacheDriver+CacheCounterframework/event: All brokers (memory, redis, nats, amqp, mqtt) implementEventDriverframework/database: SQL implementsDatabaseDriverframework/session: Uses*contract.Sessionstruct,CacheDriverfor storageBreaking Changes
DriversuffixSessionis now a struct (*contract.Session) instead of an interfaceCache/Eventswrappers handle serialization; drivers use raw[]byteEventHandleris nowfunc(payload []byte)Design Decisions
Driver()accessor instead of embedding — avoids method collisions when generic methods landcontract/(not framework) — prevents circular deps withcontract/request*Drivernaming for SPIs — matches Go convention (not Handler/Store/Backend)Testing
All modules pass:
go test ./contract/... ./router/... ./problem/... ./framework/...