server

package
v1.8.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 25, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BadRequest

func BadRequest(c *gin.Context, message string)

BadRequest sends a 400 Bad Request error

func Conflict

func Conflict(c *gin.Context, message string)

Conflict sends a 409 Conflict response

func Created

func Created(c *gin.Context, data interface{})

Created sends a 201 Created response

func Forbidden

func Forbidden(c *gin.Context, message string)

Forbidden sends a 403 Forbidden error

func InternalServerError

func InternalServerError(c *gin.Context, message string)

InternalServerError sends a 500 Internal Server Error

func NoContent

func NoContent(c *gin.Context)

NoContent sends a 204 No Content response

func NotFound

func NotFound(c *gin.Context, message string)

NotFound sends a 404 Not Found error

func NotImplemented

func NotImplemented(c *gin.Context, message string)

NotImplemented sends a 501 Not Implemented error

func ProviderError

func ProviderError(c *gin.Context, message string)

ProviderError sends a 502 Bad Gateway error for provider issues

func RateLimitError

func RateLimitError(c *gin.Context, message string)

RateLimitError sends a 429 Too Many Requests error

func RespondWithError

func RespondWithError(c *gin.Context, statusCode int, errorType ErrorType, message string)

RespondWithError sends a standardized error response

func RespondWithErrorCode

func RespondWithErrorCode(c *gin.Context, statusCode int, errorType ErrorType, message string, code string)

RespondWithErrorCode sends a standardized error response with error code

func ServiceUnavailable

func ServiceUnavailable(c *gin.Context, message string)

ServiceUnavailable sends a 503 Service Unavailable response

func Success

func Success(c *gin.Context, data interface{})

Success sends a successful JSON response

func Unauthorized

func Unauthorized(c *gin.Context, message string)

Unauthorized sends a 401 Unauthorized error

Types

type Content

type Content struct {
	Type string `json:"type"`
	Text string `json:"text"`
}

Content structure

type CreateProviderRequest

type CreateProviderRequest struct {
	Name       string   `json:"name" binding:"required"`
	APIBaseURL string   `json:"apiBaseUrl" binding:"required"`
	APIKey     string   `json:"apiKey" binding:"required"`
	Models     []string `json:"models"`
	Enabled    bool     `json:"enabled"`
}

Provider request/response structures

type ErrorDetail

type ErrorDetail struct {
	Message string    `json:"message"`
	Type    ErrorType `json:"type"`
	Code    string    `json:"code,omitempty"`
}

ErrorDetail contains error details

type ErrorResponse

type ErrorResponse struct {
	Error ErrorDetail `json:"error"`
}

ErrorResponse represents a standardized error response

type ErrorType

type ErrorType string

ErrorType represents the type of error

const (
	ErrorTypeInvalidRequest ErrorType = "invalid_request"
	ErrorTypeNotFound       ErrorType = "not_found"
	ErrorTypeAuthentication ErrorType = "authentication_error"
	ErrorTypePermission     ErrorType = "permission_error"
	ErrorTypeRateLimit      ErrorType = "rate_limit_error"
	ErrorTypeProviderError  ErrorType = "provider_error"
	ErrorTypeServerError    ErrorType = "server_error"
	ErrorTypeNotImplemented ErrorType = "not_implemented"
)

type Message

type Message struct {
	Role    string `json:"role" binding:"required"`
	Content string `json:"content" binding:"required"`
}

Message structure

type MessageRequest

type MessageRequest struct {
	Model     string    `json:"model" binding:"required"`
	Messages  []Message `json:"messages" binding:"required,min=1"`
	MaxTokens int       `json:"max_tokens,omitempty"`
	Stream    bool      `json:"stream,omitempty"`
	System    string    `json:"system,omitempty"`
}

Message request structure (Anthropic format)

type MessageResponse

type MessageResponse struct {
	ID      string    `json:"id"`
	Type    string    `json:"type"`
	Role    string    `json:"role"`
	Content []Content `json:"content"`
	Model   string    `json:"model"`
	Usage   Usage     `json:"usage,omitempty"`
}

Message response structure

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server represents the CCProxy HTTP server

func New

func New(cfg *config.Config) (*Server, error)

New creates a new server instance

func NewWithPath

func NewWithPath(cfg *config.Config, configPath string) (*Server, error)

NewWithPath creates a new server instance with a specific config path

func (*Server) GetPort

func (s *Server) GetPort() int

GetPort returns the port the server is configured to run on

func (*Server) GetRouter

func (s *Server) GetRouter() *gin.Engine

GetRouter returns the Gin router (mainly for testing)

func (*Server) Run

func (s *Server) Run() error

Run starts the server and blocks until shutdown

func (*Server) Shutdown

func (s *Server) Shutdown() error

Shutdown gracefully shuts down the server

type UpdateProviderRequest

type UpdateProviderRequest struct {
	Name       string   `json:"name"`
	APIBaseURL string   `json:"apiBaseUrl"`
	APIKey     string   `json:"apiKey"`
	Models     []string `json:"models"`
	Enabled    *bool    `json:"enabled"`
}

type Usage

type Usage struct {
	InputTokens  int `json:"input_tokens"`
	OutputTokens int `json:"output_tokens"`
}

Usage structure

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL