server

package
v0.0.0-...-8c7eee6 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleAPIList

func HandleAPIList(listFunc func() ([]map[string]interface{}, error)) http.HandlerFunc

HandleAPIList handles listing available APIs

func HandleHealth

func HandleHealth() http.HandlerFunc

HandleHealth handles the /health endpoint for health checks

func HandleReload

func HandleReload(reloadFunc func() ([]string, error)) http.HandlerFunc

HandleReload handles the /reload endpoint for reloading API specifications

func IsHTTPAddress

func IsHTTPAddress(s string) bool

IsHTTPAddress checks if a string looks like an HTTP address

func IsType

func IsType(err error, errType ErrorType) bool

IsType checks if the error is of a specific type

Types

type Config

type Config struct {
	DatabaseMode    bool
	HTTPMode        bool
	HTTPAddr        string
	DatabaseURL     string
	Port            int
	SpecFiles       []string
	RequiredEnvVars map[string]string
}

Config holds server configuration

func LoadConfig

func LoadConfig(args []string) (*Config, error)

LoadConfig loads configuration from environment variables and command line arguments

func (*Config) LogConfiguration

func (c *Config) LogConfiguration()

LogConfiguration logs the current configuration

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the configuration

type ErrorType

type ErrorType string

Error types for structured error handling

const (
	ErrorTypeValidation ErrorType = "validation"
	ErrorTypeDatabase   ErrorType = "database"
	ErrorTypeAuth       ErrorType = "authentication"
	ErrorTypeNetwork    ErrorType = "network"
	ErrorTypeInternal   ErrorType = "internal"
	ErrorTypeNotFound   ErrorType = "not_found"
	ErrorTypeConflict   ErrorType = "conflict"
)

func GetType

func GetType(err error) ErrorType

GetType returns the error type if it's a ServerError, otherwise returns ErrorTypeInternal

type HTTPContextFunc

type HTTPContextFunc func(context.Context, *http.Request, *openapi3.T, *models.OpenAPISpec) context.Context

HTTPContextFunc defines the function signature for HTTP context modification

func SecureAuthContextFunc

func SecureAuthContextFunc(authStateManager *auth.StateManager) HTTPContextFunc

SecureAuthContextFunc creates a secure, request-scoped authentication context without global state mutation

type ReloadResponse

type ReloadResponse struct {
	Success      bool     `json:"success"`
	ReloadedAPIs []string `json:"reloaded_apis,omitempty"`
	Error        string   `json:"error,omitempty"`
}

ReloadResponse represents the response from a reload operation

type ServerError

type ServerError struct {
	Type       ErrorType `json:"type"`
	Message    string    `json:"message"`
	Details    string    `json:"details,omitempty"`
	RequestID  string    `json:"request_id,omitempty"`
	Timestamp  int64     `json:"timestamp"`
	StackTrace string    `json:"stack_trace,omitempty"`
}

ServerError represents a structured error with context

func NewError

func NewError(errType ErrorType, message string, details string) *ServerError

NewError creates a new ServerError with context

func NewErrorWithContext

func NewErrorWithContext(ctx context.Context, errType ErrorType, message string, details string) *ServerError

NewErrorWithContext creates a new ServerError with request context

func Wrap

func Wrap(err error, errType ErrorType, message string) *ServerError

Wrap wraps a standard error as a ServerError

func WrapWithContext

func WrapWithContext(ctx context.Context, err error, errType ErrorType, message string) *ServerError

WrapWithContext wraps a standard error as a ServerError with context

func (*ServerError) Error

func (e *ServerError) Error() string

Error implements the error interface

func (*ServerError) LogError

func (e *ServerError) LogError()

LogError logs the error with appropriate level and context

func (*ServerError) WithStackTrace

func (e *ServerError) WithStackTrace() *ServerError

WithStackTrace adds stack trace information to the error

Jump to

Keyboard shortcuts

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