The project uses Go generics (1.18+) extensively for type safety.
Related Documentation:
- Database Operations - Generic query builder patterns
- Stream Operations - Type-safe streaming
- Cache Operations - Generic cache operations
- HTTP Requests - Generic request/response parsing
// Type-safe queries
plugin, _ := db.GetOne[models.Plugin](...)
plugins, _ := db.GetAll[models.Plugin](...)
count, _ := db.GetCount[models.Plugin](...)
// Generic constraints for comparisons
type genericComparableConstraint interface {
int | int8 | int16 | int32 | int64 |
uint | uint8 | uint16 | uint32 | uint64 |
float32 | float64 | bool
}
func GreaterThan[T genericComparableConstraint](field string, value T)// Type-safe streaming
stream.NewStream[tool_entities.ToolResponseChunk](128)
stream.Stream[agent_entities.AgentStrategyResponseChunk]
// Consumer pattern
for stream.Next() {
data, err := stream.Read()
// data is correctly typed
}// Generic plugin invocation with request/response types
GenericInvokePlugin[RequestType, ResponseType](
session,
request,
bufferSize,
)
// Example usage
response, err := GenericInvokePlugin[
requests.RequestInvokeTool,
tool_entities.ToolResponseChunk,
](session, request, 128)// Type-safe cache operations
cache.Get[models.Plugin](key)
cache.GetMapField[node](mapKey, field)
cache.Subscribe[EventType](channel)
cache.AutoGetWithGetter[plugin_entities.PluginDeclaration](...)// Generic request/response handling
resp, err := http_requests.RequestAndParse[ResponseType](
client,
url,
method,
options...,
)
// Stream parsing
stream, err := http_requests.RequestAndParseStream[ChunkType](
client,
url,
method,
)// Base SSE handler with generics
baseSSEWithSession(
func(session *Session) (*stream.Stream[T], error) {
return plugin_daemon.InvokeTool(session, &r.Data)
},
accessType,
accessAction,
request,
context,
timeout,
)- Compile-time type safety - Catch type errors at build time
- Code reuse - Single implementation for multiple types
- Better IDE support - Auto-completion and type hints
- Reduced runtime errors - No type assertions needed
- Clear APIs - Types are explicit in function signatures