Documentation
¶
Index ¶
- Variables
- type AIHandler
- func (h *AIHandler) HandleChatCompletion(w http.ResponseWriter, r *http.Request)
- func (h *AIHandler) HandleGenerateImage(w http.ResponseWriter, r *http.Request)
- func (h *AIHandler) HandleStreamChatCompletion(w http.ResponseWriter, r *http.Request)
- func (h *AIHandler) RegisterRoutes(mux *http.ServeMux)
- type AIService
- type ChatMessage
- type ChatRequest
- type ChatResponse
- type ChatStreamChunk
- type CreateUserRequest
- type ErrorResponse
- type ImageItem
- type ImageRequest
- type ImageResponse
- type ListUsersResponse
- type Logger
- type PaginationMeta
- type UpdateUserRequest
- type Usage
- type User
- type UserHandler
- func (h *UserHandler) Create(w http.ResponseWriter, r *http.Request)
- func (h *UserHandler) Delete(w http.ResponseWriter, r *http.Request)
- func (h *UserHandler) Get(w http.ResponseWriter, r *http.Request)
- func (h *UserHandler) List(w http.ResponseWriter, r *http.Request)
- func (h *UserHandler) RegisterRoutes(mux *http.ServeMux)
- func (h *UserHandler) Update(w http.ResponseWriter, r *http.Request)
- type UserResponse
- type UserService
Constants ¶
This section is empty.
Variables ¶
var ( ErrUserNotFound = errors.New("user not found") ErrUserAlreadyExists = errors.New("user already exists") )
Functions ¶
This section is empty.
Types ¶
type AIHandler ¶
type AIHandler struct {
// contains filtered or unexported fields
}
AIHandler manages HTTP requests for AI capabilities.
func NewAIHandler ¶
NewAIHandler initializes a new AIHandler with necessary dependencies.
func (*AIHandler) HandleChatCompletion ¶
func (h *AIHandler) HandleChatCompletion(w http.ResponseWriter, r *http.Request)
HandleChatCompletion processes a standard request-response chat interaction.
func (*AIHandler) HandleGenerateImage ¶
func (h *AIHandler) HandleGenerateImage(w http.ResponseWriter, r *http.Request)
HandleGenerateImage processes image generation requests.
func (*AIHandler) HandleStreamChatCompletion ¶
func (h *AIHandler) HandleStreamChatCompletion(w http.ResponseWriter, r *http.Request)
HandleStreamChatCompletion handles Server-Sent Events (SSE) for real-time chat streaming.
func (*AIHandler) RegisterRoutes ¶
RegisterRoutes attaches the handlers to a standard http.ServeMux. This follows Go 1.22+ routing patterns.
type AIService ¶
type AIService interface {
GenerateChatCompletion(ctx context.Context, req ChatRequest) (*ChatResponse, error)
StreamChatCompletion(ctx context.Context, req ChatRequest) (<-chan ChatStreamChunk, error)
GenerateImage(ctx context.Context, req ImageRequest) (*ImageResponse, error)
}
AIService defines the business logic for AI operations. In a full project, this would likely be imported from internal/service or internal/core/ports.
type ChatMessage ¶
type ChatRequest ¶
type ChatRequest struct {
Model string `json:"model"`
Messages []ChatMessage `json:"messages"`
Temperature float64 `json:"temperature,omitempty"`
MaxTokens int `json:"max_tokens,omitempty"`
}
type ChatResponse ¶
type ChatResponse struct {
ID string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
Message ChatMessage `json:"message"`
Usage Usage `json:"usage"`
}
type ChatStreamChunk ¶
type CreateUserRequest ¶
type CreateUserRequest struct {
Email string `json:"email" validate:"required,email"`
Name string `json:"name" validate:"required,min=2,max=100"`
Password string `json:"password" validate:"required,min=8"`
}
CreateUserRequest defines the payload for creating a user.
type ErrorResponse ¶
type ImageRequest ¶
type ImageResponse ¶
type ListUsersResponse ¶
type ListUsersResponse struct {
Data []UserResponse `json:"data"`
Meta PaginationMeta `json:"meta"`
}
ListUsersResponse defines the paginated response.
type Logger ¶
type Logger interface {
Info(msg string, args ...any)
Error(msg string, args ...any)
Debug(msg string, args ...any)
}
Logger defines a structured logger interface.
type PaginationMeta ¶
type UpdateUserRequest ¶
type UpdateUserRequest struct {
Email string `json:"email" validate:"omitempty,email"`
Name string `json:"name" validate:"omitempty,min=2,max=100"`
}
UpdateUserRequest defines the payload for updating a user.
type User ¶
type User struct {
ID string `json:"id"`
Email string `json:"email"`
Name string `json:"name"`
Password string `json:"-"` // Never return password
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
User represents the domain model for a user.
type UserHandler ¶
type UserHandler struct {
// contains filtered or unexported fields
}
UserHandler handles HTTP requests for user resources.
func NewUserHandler ¶
func NewUserHandler(service UserService, logger *slog.Logger) *UserHandler
NewUserHandler creates a new instance of UserHandler.
func (*UserHandler) Create ¶
func (h *UserHandler) Create(w http.ResponseWriter, r *http.Request)
Create handles the creation of a new user.
func (*UserHandler) Delete ¶
func (h *UserHandler) Delete(w http.ResponseWriter, r *http.Request)
Delete removes a user.
func (*UserHandler) Get ¶
func (h *UserHandler) Get(w http.ResponseWriter, r *http.Request)
Get retrieves a user by ID.
func (*UserHandler) List ¶
func (h *UserHandler) List(w http.ResponseWriter, r *http.Request)
List retrieves a paginated list of users.
func (*UserHandler) RegisterRoutes ¶
func (h *UserHandler) RegisterRoutes(mux *http.ServeMux)
RegisterRoutes registers the user endpoints on the provided mux. Uses Go 1.22+ routing patterns.
func (*UserHandler) Update ¶
func (h *UserHandler) Update(w http.ResponseWriter, r *http.Request)
Update modifies an existing user.
type UserResponse ¶
type UserResponse struct {
ID string `json:"id"`
Email string `json:"email"`
Name string `json:"name"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
UserResponse defines the public view of a user.
type UserService ¶
type UserService interface {
Create(ctx context.Context, user *User) error
GetByID(ctx context.Context, id string) (*User, error)
Update(ctx context.Context, user *User) error
Delete(ctx context.Context, id string) error
List(ctx context.Context, page, limit int) ([]User, int64, error)
}
UserService defines the business logic for user operations. This interface allows for dependency injection and easy mocking.