~/labs/resultx
resultx
A generic Result pattern with metadata, pagination and error handling.
A lightweight, zero-dependency Go module for creating standardized API responses, with built-in support for pagination, metadata and type-safe generics.
Install
go get github.com/oshturhq/resultxFeatures
- A type-safe Result[T] wrapper for any data type
- One consistent JSON structure for success and error responses
- Safe by default: internal error text is never sent to the client unless you opt in
- Built-in pagination with page calculation, navigation flags and overflow-safe offset and limit checks
- Messages and metadata attached through a single family of With options
- Zero dependencies: standard library only
Example
user := User{ID: 1, Name: "John Doe", Email: "[email protected]"}
result := resultx.Ok(user, resultx.WithMessage("User retrieved successfully"))
// Error response - nothing is derived from an error, so nothing leaks
errResult := resultx.Fail[User](resultx.WithCode("USER_NOT_FOUND"))