core

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2025 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiResponse

type ApiResponse struct {
	Headers           map[string]string
	StatusCode        int    `json:"statusCode" xml:"statusCode"`
	InternalErrorCode int    ``
	Message           string `json:"message" xml:"message"`
	Data              []byte `json:"data,omitempty" xml:"data,omitempty"`
}

func NewApiResponse

func NewApiResponse() ApiResponse

func (*ApiResponse) AddHeader

func (r *ApiResponse) AddHeader(k, v string)

func (*ApiResponse) SendingReturn

func (r *ApiResponse) SendingReturn(w http.ResponseWriter, c *Ctx, err error)

func (*ApiResponse) SetData

func (r *ApiResponse) SetData(data []byte)

func (*ApiResponse) SetMessage

func (r *ApiResponse) SetMessage(msg string)

func (*ApiResponse) SetStatus

func (r *ApiResponse) SetStatus(code int)

type App

type App struct {
	Logger logger.Logger
	// contains filtered or unexported fields
}

TODO: Add Timeout handling (Middleware??) TODO: Add MaxConnection handling (Middleware??) TODO: Add RateLimit handling (Middleware??)

func NewApp

func NewApp(opts ...AppOption) App

func (App) DELETE

func (a App) DELETE(path string, handler Handler, opt ...RouteOption)

func (*App) GET

func (a *App) GET(path string, handler Handler, opt ...RouteOption)

func (*App) NewRouter

func (a *App) NewRouter(path string) *Router

func (App) OPTIONS

func (a App) OPTIONS(path string, handler Handler, opt ...RouteOption)

func (App) POST

func (a App) POST(path string, handler Handler, opt ...RouteOption)

func (App) PUT

func (a App) PUT(path string, handler Handler, opt ...RouteOption)

func (*App) Run

func (a *App) Run() error

func (*App) SetDefaultRoute

func (a *App) SetDefaultRoute(handler Handler)

func (*App) SetLogger

func (a *App) SetLogger(logger logger.Logger)

type AppConfig

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

func (AppConfig) GetListenAddress

func (c AppConfig) GetListenAddress() string

type AppOption

type AppOption func(*AppConfig)

func AppAddServer

func AppAddServer(url, description string) AppOption

func AppAddr

func AppAddr(host, port string) AppOption

func AppContact

func AppContact(name, email, url string) AppOption

func AppDescription

func AppDescription(description string) AppOption

func AppLicense

func AppLicense(name, url string) AppOption

func AppLogger

func AppLogger(logger logger.Logger) AppOption

func AppTitle

func AppTitle(title string) AppOption

func AppVersion

func AppVersion(version string) AppOption

type CORSConfig

type CORSConfig struct {
	// AllowOrigins is a list of origins a cross-domain request can be executed from.
	// If the special "*" value is present in the list, all origins will be allowed.
	// Default value is ["*"]
	AllowOrigins []string

	// AllowMethods is a list of methods the client is allowed to use with
	// cross-domain requests. Default value is simple methods (GET, POST, PUT, DELETE)
	AllowMethods []string

	// AllowHeaders is a list of non-simple headers the client is allowed to use with
	// cross-domain requests. Default value is []
	AllowHeaders []string

	// ExposeHeaders indicates which headers are safe to expose to the API of a CORS
	// API specification. Default value is []
	ExposeHeaders []string

	// AllowCredentials indicates whether the request can include user credentials like
	// cookies, HTTP authentication or client side SSL certificates. Default is false.
	AllowCredentials bool

	// MaxAge indicates how long (in seconds) the results of a preflight request
	// can be cached. Default is 0 which stands for no max age.
	MaxAge int
}

CORSConfig holds the configuration for CORS middleware

func DefaultCORSConfig

func DefaultCORSConfig() CORSConfig

DefaultCORSConfig returns a default CORS configuration

type Ctx

type Ctx struct {
	// TODO: Move to an Interface, prob to use HTML Responses as well
	Response ApiResponse
	Request  *http.Request

	ObjIn     any
	ObjInType reflect.Type

	ObjOut     any
	ObjOutType reflect.Type
	// contains filtered or unexported fields
}

func NewCtx

func NewCtx(w http.ResponseWriter, r *http.Request) *Ctx

func (*Ctx) Close

func (c *Ctx) Close()

func (*Ctx) IsClosed

func (c *Ctx) IsClosed() bool

type Endpoint

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

type ErrorResponse

type ErrorResponse struct {
	Error   string `json:"error" xml:"error" description:"Error message"`
	Code    int    `json:"code" xml:"code" description:"Error code"`
	Details string `json:"details,omitempty" xml:"details,omitempty" description:"Additional error details"`
}

type Handler

type Handler func(*Ctx) error

type Middleware

type Middleware func(Handler) Handler

func CORSMiddleware

func CORSMiddleware(config CORSConfig) Middleware

CORSMiddleware returns a middleware that handles CORS

func LogMiddleware

func LogMiddleware(logger logger.Logger) Middleware

func PanicMiddleware

func PanicMiddleware() Middleware

type RequestMethod

type RequestMethod int
const (
	METHOD_GET RequestMethod = iota
	METHOD_POST
	METHOD_PUT
	METHOD_PATCH
	METHOD_DELETE
	METHOD_HEAD
	METHOD_OPTIONS
	METHOD_TRACE
	METHOD_CONNECT
)

type Response

type Response any

type Route

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

type RouteOption

type RouteOption func(*RouteOptionConfig)

func WithObjIn

func WithObjIn(obj any) RouteOption

func WithObjOut

func WithObjOut(obj any) RouteOption

func WithOpenApiDeprecated

func WithOpenApiDeprecated() RouteOption

func WithOpenApiDisabled

func WithOpenApiDisabled() RouteOption

func WithOpenApiEnabled

func WithOpenApiEnabled(summary, description string) RouteOption

func WithOpenApiInfos

func WithOpenApiInfos(summary, description string) RouteOption

func WithOpenApiTags

func WithOpenApiTags(tags ...string) RouteOption

type RouteOptionConfig

type RouteOptionConfig struct {
	ObjIn  any
	ObjOut any
	// contains filtered or unexported fields
}

TODO: Add this to Router as well and set the Router values as default for Route

func NewRouteOptionConfig

func NewRouteOptionConfig(opts ...RouteOption) *RouteOptionConfig

type Router

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

func (*Router) DELETE

func (r *Router) DELETE(path string, handler Handler, opt ...RouteOption)

func (*Router) GET

func (r *Router) GET(path string, handler Handler, opt ...RouteOption)

func (Router) GetBasePath

func (r Router) GetBasePath() string

func (*Router) OPTIONS

func (r *Router) OPTIONS(path string, handler Handler, opt ...RouteOption)

func (*Router) POST

func (r *Router) POST(path string, handler Handler, opt ...RouteOption)

func (*Router) PUT

func (r *Router) PUT(path string, handler Handler, opt ...RouteOption)

Jump to

Keyboard shortcuts

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