{"modulePath":"github.com/jocall3/cli","version":"v0.3.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package handler\n\n## Variables\n\n```go\nvar (\n\tErrUserNotFound      = errors.New(\"user not found\")\n\tErrUserAlreadyExists = errors.New(\"user already exists\")\n)\n```\n\n## Types\n\n```go\ntype AIHandler struct {\n\t// contains filtered or unexported fields\n}\n```\nAIHandler manages HTTP requests for AI capabilities.\n\n```go\nfunc NewAIHandler(service AIService, logger Logger) *AIHandler\n```\nNewAIHandler initializes a new AIHandler with necessary dependencies.\n\n```go\nfunc (h *AIHandler) HandleChatCompletion(w http.ResponseWriter, r *http.Request)\n```\nHandleChatCompletion processes a standard request-response chat interaction.\n\n```go\nfunc (h *AIHandler) HandleGenerateImage(w http.ResponseWriter, r *http.Request)\n```\nHandleGenerateImage processes image generation requests.\n\n```go\nfunc (h *AIHandler) HandleStreamChatCompletion(w http.ResponseWriter, r *http.Request)\n```\nHandleStreamChatCompletion handles Server-Sent Events (SSE) for real-time chat streaming.\n\n```go\nfunc (h *AIHandler) RegisterRoutes(mux *http.ServeMux)\n```\nRegisterRoutes attaches the handlers to a standard http.ServeMux. This follows Go 1.22+ routing patterns.\n\n```go\ntype AIService interface {\n\tGenerateChatCompletion(ctx context.Context, req ChatRequest) (*ChatResponse, error)\n\tStreamChatCompletion(ctx context.Context, req ChatRequest) (\u003c-chan ChatStreamChunk, error)\n\tGenerateImage(ctx context.Context, req ImageRequest) (*ImageResponse, error)\n}\n```\nAIService defines the business logic for AI operations. In a full project, this would likely be imported from internal/service or internal/core/ports.\n\n```go\ntype ChatMessage struct {\n\tRole    string `json:\"role\"`\n\tContent string `json:\"content\"`\n}\n```\n\n```go\ntype ChatRequest struct {\n\tModel       string        `json:\"model\"`\n\tMessages    []ChatMessage `json:\"messages\"`\n\tTemperature float64       `json:\"temperature,omitempty\"`\n\tMaxTokens   int           `json:\"max_tokens,omitempty\"`\n}\n```\n\n```go\ntype ChatResponse struct {\n\tID      string      `json:\"id\"`\n\tObject  string      `json:\"object\"`\n\tCreated int64       `json:\"created\"`\n\tMessage ChatMessage `json:\"message\"`\n\tUsage   Usage       `json:\"usage\"`\n}\n```\n\n```go\ntype ChatStreamChunk struct {\n\tID      string `json:\"id\"`\n\tContent string `json:\"content\"` // Delta content\n\tDone    bool   `json:\"done\"`\n\tError   error  `json:\"-\"` // Internal error passing\n}\n```\n\n```go\ntype CreateUserRequest struct {\n\tEmail    string `json:\"email\" validate:\"required,email\"`\n\tName     string `json:\"name\" validate:\"required,min=2,max=100\"`\n\tPassword string `json:\"password\" validate:\"required,min=8\"`\n}\n```\nCreateUserRequest defines the payload for creating a user.\n\n```go\ntype ErrorResponse struct {\n\tError string `json:\"error\"`\n\tCode  int    `json:\"code\"`\n}\n```\n\n```go\ntype ImageItem struct {\n\tURL     string `json:\"url,omitempty\"`\n\tB64JSON string `json:\"b64_json,omitempty\"`\n}\n```\n\n```go\ntype ImageRequest struct {\n\tPrompt string `json:\"prompt\"`\n\tSize   string `json:\"size,omitempty\"` // e.g., \"1024x1024\"\n\tN      int    `json:\"n,omitempty\"`\n}\n```\n\n```go\ntype ImageResponse struct {\n\tCreated int64       `json:\"created\"`\n\tData    []ImageItem `json:\"data\"`\n}\n```\n\n```go\ntype ListUsersResponse struct {\n\tData []UserResponse `json:\"data\"`\n\tMeta PaginationMeta `json:\"meta\"`\n}\n```\nListUsersResponse defines the paginated response.\n\n```go\ntype Logger interface {\n\tInfo(msg string, args ...any)\n\tError(msg string, args ...any)\n\tDebug(msg string, args ...any)\n}\n```\nLogger defines a structured logger interface.\n\n```go\ntype PaginationMeta struct {\n\tCurrentPage int   `json:\"current_page\"`\n\tPageSize    int   `json:\"page_size\"`\n\tTotalItems  int64 `json:\"total_items\"`\n\tTotalPages  int   `json:\"total_pages\"`\n}\n```\n\n```go\ntype UpdateUserRequest struct {\n\tEmail string `json:\"email\" validate:\"omitempty,email\"`\n\tName  string `json:\"name\" validate:\"omitempty,min=2,max=100\"`\n}\n```\nUpdateUserRequest defines the payload for updating a user.\n\n```go\ntype Usage struct {\n\tPromptTokens     int `json:\"prompt_tokens\"`\n\tCompletionTokens int `json:\"completion_tokens\"`\n\tTotalTokens      int `json:\"total_tokens\"`\n}\n```\n\n```go\ntype User struct {\n\tID        string    `json:\"id\"`\n\tEmail     string    `json:\"email\"`\n\tName      string    `json:\"name\"`\n\tPassword  string    `json:\"-\"` // Never return password\n\tCreatedAt time.Time `json:\"created_at\"`\n\tUpdatedAt time.Time `json:\"updated_at\"`\n}\n```\nUser represents the domain model for a user.\n\n```go\ntype UserHandler struct {\n\t// contains filtered or unexported fields\n}\n```\nUserHandler handles HTTP requests for user resources.\n\n```go\nfunc NewUserHandler(service UserService, logger *slog.Logger) *UserHandler\n```\nNewUserHandler creates a new instance of UserHandler.\n\n```go\nfunc (h *UserHandler) Create(w http.ResponseWriter, r *http.Request)\n```\nCreate handles the creation of a new user.\n\n```go\nfunc (h *UserHandler) Delete(w http.ResponseWriter, r *http.Request)\n```\nDelete removes a user.\n\n```go\nfunc (h *UserHandler) Get(w http.ResponseWriter, r *http.Request)\n```\nGet retrieves a user by ID.\n\n```go\nfunc (h *UserHandler) List(w http.ResponseWriter, r *http.Request)\n```\nList retrieves a paginated list of users.\n\n```go\nfunc (h *UserHandler) RegisterRoutes(mux *http.ServeMux)\n```\nRegisterRoutes registers the user endpoints on the provided mux. Uses Go 1.22+ routing patterns.\n\n```go\nfunc (h *UserHandler) Update(w http.ResponseWriter, r *http.Request)\n```\nUpdate modifies an existing user.\n\n```go\ntype UserResponse struct {\n\tID        string    `json:\"id\"`\n\tEmail     string    `json:\"email\"`\n\tName      string    `json:\"name\"`\n\tCreatedAt time.Time `json:\"created_at\"`\n\tUpdatedAt time.Time `json:\"updated_at\"`\n}\n```\nUserResponse defines the public view of a user.\n\n```go\ntype UserService interface {\n\tCreate(ctx context.Context, user *User) error\n\tGetByID(ctx context.Context, id string) (*User, error)\n\tUpdate(ctx context.Context, user *User) error\n\tDelete(ctx context.Context, id string) error\n\tList(ctx context.Context, page, limit int) ([]User, int64, error)\n}\n```\nUserService defines the business logic for user operations. This interface allows for dependency injection and easy mocking.\n\n","path":"github.com/jocall3/cli/internal/api/handler","name":"handler","synopsis":"","isRedistributable":true}
