Documentation
¶
Index ¶
Constants ¶
const ( // ErrUserNotFound indicates that a requested user was not found. // Typically returned when a user ID doesn't exist in the system. ErrUserNotFound sentinelError = "user not found" // Typically returned for 401 Unauthorized HTTP responses. ErrUnauthorized sentinelError = "unauthorized" )
Predefined sentinel errors for common API error conditions. These errors provide type-safe, comparable error values that can be used with errors.Is() for error handling and flow control.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides a high-level interface for interacting with a user management API. It encapsulates the httpclient.API instance and provides domain-specific methods for common operations like creating, retrieving, and deleting users.
The client is designed to be safe for concurrent use by multiple goroutines, as the underlying httpclient.API is thread-safe and creates new request builders for each operation.
func New ¶
New creates a new Client instance configured to communicate with the API server at the specified URL. The client is configured with sensible defaults for common HTTP status codes and error handling patterns.
Default response handlers:
- 200 OK: Treated as success (no error)
- 401 Unauthorized: Returns ErrUnauthorized sentinel error
- 404 Not Found: Returns ErrUserNotFound sentinel error
The client uses http.DefaultClient as the underlying HTTP client, which provides reasonable defaults for most use cases. For production applications, consider configuring a custom HTTP client with appropriate timeouts, connection pooling, and other settings.
The returned client is safe for concurrent use by multiple goroutines.
func (*Client) CreateUser ¶
CreateUser creates a new user in the system with the specified username. It sends a POST request to the /users endpoint with a JSON body containing the user creation data and returns the newly assigned user ID.
func (*Client) DeleteUserByID ¶
DeleteUserByID removes a user from the system by their unique identifier. It sends a DELETE request to the /users/{userID} endpoint and relies on the default response handlers for error handling.
This method uses the Execute() convenience method instead of Do() because DELETE operations typically don't return response bodies that need parsing. The Execute() method applies all default response handlers and returns only the error result.
type User ¶
User represents a user entity in the system, containing the essential information needed for user management operations through the API.