Documentation
¶
Index ¶
- Constants
- func Connect[T any](r *Router[T], path string, h HandlerFunc[T])
- func Delete[T any](r *Router[T], path string, h HandlerFunc[T])
- func Get[T any](r *Router[T], path string, h HandlerFunc[T])
- func Head[T any](r *Router[T], path string, h HandlerFunc[T])
- func Options[T any](r *Router[T], path string, h HandlerFunc[T])
- func Patch[T, B any](r *Router[T], path string, h HandlerWithBody[T, B])
- func Post[T, B any](r *Router[T], path string, h HandlerWithBody[T, B])
- func Put[T, B any](r *Router[T], path string, h HandlerWithBody[T, B])
- func Static[T any](r *Router[T], pathPrefix, rootFolder string)
- func Trace[T any](r *Router[T], path string, h HandlerFunc[T])
- type App
- type CacheStore
- type Config
- type Context
- func (c *Context[T]) Attachment(filepath, filename string)
- func (c *Context[T]) Bind(v any) error
- func (c *Context[T]) Cache() CacheStore
- func (c *Context[T]) ClearCookie(name string)
- func (c *Context[T]) Cookie(name string) (*http.Cookie, error)
- func (c *Context[T]) File(filepath string)
- func (c *Context[T]) GetBody() ([]byte, error)
- func (c *Context[T]) Hijack() (net.Conn, *bufio.ReadWriter, error)
- func (c *Context[T]) JSON(status int, data any) error
- func (c *Context[T]) Log() Logger
- func (c *Context[T]) Next()
- func (c *Context[T]) Param(key string) string
- func (c *Context[T]) Query(key string) string
- func (c *Context[T]) Render(status int, name string, data any) error
- func (c *Context[T]) Req() *http.Request
- func (c *Context[T]) Res() http.ResponseWriter
- func (c *Context[T]) Reset(w http.ResponseWriter, req *http.Request, handlers []HandlerFunc[T], ...)
- func (c *Context[T]) SSE() (*http.ResponseController, error)
- func (c *Context[T]) SaveFile(file *multipart.FileHeader, dst string) error
- func (c *Context[T]) SetCookie(cookie *http.Cookie)
- func (c *Context[T]) SetReq(req *http.Request)
- func (c *Context[T]) Start() time.Time
- func (c *Context[T]) String(status int, text string, args ...any) error
- func (c *Context[T]) XML(status int, data any) error
- type CronJob
- type CronManager
- type CustomContext
- type CustomErrorHandler
- type HandlerFunc
- func LoggerMiddleware[T any]() HandlerFunc[T]
- func RecoveryMiddleware[T any](customHandler CustomErrorHandler[T]) HandlerFunc[T]
- func WithCustomContext[T, L any](initialData L, handler func(c *CustomContext[T, L])) HandlerFunc[T]
- func WrapMiddleware[T any](mw func(http.Handler) http.Handler) HandlerFunc[T]
- type HandlerWithBody
- type JSONEngine
- type LogConfig
- type Logger
- type OtterStore
- type ResponseWriter
- type Router
- type TemplateEngine
- type XMLEngine
Constants ¶
const DefaultMaxBodySize = 2 << 20 // 2MB
DefaultMaxBodySize is the default maximum body size for incoming requests.
Variables ¶
This section is empty.
Functions ¶
func Connect ¶
func Connect[T any](r *Router[T], path string, h HandlerFunc[T])
Connect registers a handler for CONNECT requests at the specified path.
func Delete ¶
func Delete[T any](r *Router[T], path string, h HandlerFunc[T])
Delete registers a handler for DELETE requests at the specified path.
func Get ¶
func Get[T any](r *Router[T], path string, h HandlerFunc[T])
Get registers a handler for GET requests at the specified path.
func Head ¶
func Head[T any](r *Router[T], path string, h HandlerFunc[T])
Head registers a handler for HEAD requests at the specified path.
func Options ¶
func Options[T any](r *Router[T], path string, h HandlerFunc[T])
Options registers a handler for OPTIONS requests at the specified path.
func Patch ¶
func Patch[T, B any](r *Router[T], path string, h HandlerWithBody[T, B])
Patch registers a handler for PATCH requests at the specified path.
func Post ¶
func Post[T, B any](r *Router[T], path string, h HandlerWithBody[T, B])
Post registers a handler for POST requests at the specified path.
func Put ¶
func Put[T, B any](r *Router[T], path string, h HandlerWithBody[T, B])
Put registers a handler for PUT requests at the specified path.
Types ¶
type App ¶
type App[T any] struct { // contains filtered or unexported fields }
App represents the main Aether application instance.
type CacheStore ¶
type CacheStore interface {
Get(ctx context.Context, key string) (any, bool)
Set(ctx context.Context, key string, value any) error
Delete(ctx context.Context, key string) error
Clear(ctx context.Context) error
}
CacheStore defines the interface for caching operations.
type Config ¶
type Config[T any] struct { Port int Host string Timeout int ShutdownTimeout int MaxBodyBytes int64 JSON JSONEngine XML XMLEngine Template TemplateEngine Cache CacheStore Logger Logger Global T ErrorHandler CustomErrorHandler[T] }
Config holds Aether configuration options.
type Context ¶
type Context[T any] struct { Global T // contains filtered or unexported fields }
Context holds the request context for a handler.
func (*Context[T]) Attachment ¶
Attachment serves a file as an attachment with the specified filename.
func (*Context[T]) Bind ¶
Bind binds request body data to the specified struct based on content type.
func (*Context[T]) Cache ¶
func (c *Context[T]) Cache() CacheStore
Cache returns the cache store instance.
func (*Context[T]) ClearCookie ¶
ClearCookie removes a cookie by setting its max age to -1.
func (*Context[T]) Next ¶
func (c *Context[T]) Next()
Next executes the next handler in the middleware chain.
func (*Context[T]) Res ¶
func (c *Context[T]) Res() http.ResponseWriter
Res returns the current HTTP response writer.
func (*Context[T]) Reset ¶
func (c *Context[T]) Reset(w http.ResponseWriter, req *http.Request, handlers []HandlerFunc[T], json JSONEngine, xml XMLEngine, template TemplateEngine, cache CacheStore, log Logger, global T)
Reset initializes or resets the context with new values.
func (*Context[T]) SSE ¶
func (c *Context[T]) SSE() (*http.ResponseController, error)
SSE prepares the response for Server-Sent Events.
func (*Context[T]) SaveFile ¶
func (c *Context[T]) SaveFile(file *multipart.FileHeader, dst string) error
SaveFile saves an uploaded file to the specified destination.
type CronManager ¶
type CronManager struct {
// contains filtered or unexported fields
}
CronManager manages scheduled cron jobs.
func (*CronManager) Add ¶
func (c *CronManager) Add(name string, interval time.Duration, job CronJob)
Add registers a new cron job with the specified name and interval.
func (*CronManager) Start ¶
func (c *CronManager) Start()
Start begins execution of all registered cron jobs.
func (*CronManager) Stop ¶
func (c *CronManager) Stop()
Stop gracefully stops all running cron jobs.
type CustomContext ¶
CustomContext extends Context with custom user data.
type CustomErrorHandler ¶
CustomErrorHandler defines the function signature for custom error handling.
type HandlerFunc ¶
HandlerFunc is the function signature for HTTP handlers.
func LoggerMiddleware ¶
func LoggerMiddleware[T any]() HandlerFunc[T]
LoggerMiddleware logs HTTP requests with method, path, status, and duration.
func RecoveryMiddleware ¶
func RecoveryMiddleware[T any](customHandler CustomErrorHandler[T]) HandlerFunc[T]
RecoveryMiddleware recovers from panics and logs the error stack trace.
func WithCustomContext ¶
func WithCustomContext[T, L any](initialData L, handler func(c *CustomContext[T, L])) HandlerFunc[T]
WithCustomContext creates a handler with custom context data.
func WrapMiddleware ¶
WrapMiddleware adapts a standard net/http middleware into an Aether HandlerFunc.
type HandlerWithBody ¶
HandlerWithBody is the function signature for handlers that receive a request body.
type JSONEngine ¶
JSONEngine defines the interface for JSON encoding and decoding.
type Logger ¶
type Logger interface {
Debug(args ...any)
Debugf(format string, args ...any)
Info(args ...any)
Infof(format string, args ...any)
Warn(args ...any)
Warnf(format string, args ...any)
Error(args ...any)
Errorf(format string, args ...any)
Fatal(args ...any)
Fatalf(format string, args ...any)
Panic(args ...any)
Panicf(format string, args ...any)
Sync()
}
Logger defines the interface for logging operations.
type OtterStore ¶
type OtterStore struct {
// contains filtered or unexported fields
}
OtterStore is a cache store implementation using the Otter library.
func NewOtterStore ¶
func NewOtterStore(maxSize int) (*OtterStore, error)
NewOtterStore creates a new OtterStore with the specified maximum size.
func (*OtterStore) Clear ¶
func (o *OtterStore) Clear(_ context.Context) error
Clear removes all entries from the cache.
func (*OtterStore) Delete ¶
func (o *OtterStore) Delete(_ context.Context, key string) error
Delete removes a value from the cache by key.
type ResponseWriter ¶
type ResponseWriter interface {
http.ResponseWriter
Status() int
Size() int
Unwrap() http.ResponseWriter
}
ResponseWriter wraps http.ResponseWriter with status and size tracking.
type Router ¶
type Router[T any] struct { // contains filtered or unexported fields }
Router handles HTTP routing and middleware registration.
func NewRouter ¶
func NewRouter[T any](jsonEngine JSONEngine, xmlEngine XMLEngine, templateEngine TemplateEngine, cacheStore CacheStore, log Logger, global T, timeout int, maxBodyBytes int64) *Router[T]
NewRouter creates a new Router instance with the given configuration.
func (*Router[T]) ServeHTTP ¶
func (r *Router[T]) ServeHTTP(w http.ResponseWriter, req *http.Request)
func (*Router[T]) Use ¶
func (r *Router[T]) Use(middlewares ...HandlerFunc[T])
Use registers one or more middleware handlers.
type TemplateEngine ¶
TemplateEngine defines the interface for rendering templates.