Documentation
¶
Overview ¶
Package elgon is a performance-oriented, API-first web framework for Go.
Elgon is built on top of the standard net/http package and focuses on delivering production-ready features with minimal overhead. It provides a clean and explicit API for building scalable backend services.
Features:
- Fast and flexible HTTP router (static, param, wildcard routes) - Composable middleware pipeline - Typed request context (Ctx) - Centralized error handling - Built-in observability (metrics & tracing interfaces) - OpenAPI generation with Swagger UI - Authentication utilities (JWT, RBAC, OAuth2/OIDC) - Database adapters, ORM helpers, and migrations - Background jobs with pluggable queue backends
Basic Usage:
app := elgon.New(elgon.Config{Addr: ":8080"})
app.GET("/", func(c *elgon.Ctx) error {
return c.JSON(200, map[string]string{"message": "hello"})
})
if err := app.Run(); err != nil {
log.Fatal(err)
}
Middleware:
app.Use( middleware.Recover(), middleware.RequestID(), middleware.Logger(...), )
Observability:
metrics := observability.NewMetrics() app.Use(metrics.Middleware()) metrics.RegisterRoute(app, "/metrics")
OpenAPI:
openapi.NewGenerator("My API", elgon.Version).
Register(app, "/openapi.json", "/docs")
Project Structure:
- elgon: core application, router, and context - middleware: HTTP middleware implementations - config: configuration loading utilities - observability: metrics and tracing - openapi: OpenAPI generation and docs UI - auth: authentication and authorization helpers - db: database adapters - orm: higher-level database abstractions - migrate: migration engine - jobs: background job processing
For more examples and guides, see the README and examples directory.
Index ¶
- Constants
- func ErrBadRequest(msg string, details any) error
- func ErrConflict(msg string) error
- func ErrForbidden(msg string) error
- func ErrInternal(msg string) error
- func ErrNotFound(msg string) error
- func ErrUnauthorized(msg string) error
- type App
- func (a *App) DELETE(path string, h HandlerFunc, mw ...Middleware)
- func (a *App) GET(path string, h HandlerFunc, mw ...Middleware)
- func (a *App) Group(prefix string, mw ...Middleware) *Group
- func (a *App) Named(name string) *NamedRoute
- func (a *App) ORM() *orm.Client
- func (a *App) PATCH(path string, h HandlerFunc, mw ...Middleware)
- func (a *App) POST(path string, h HandlerFunc, mw ...Middleware)
- func (a *App) PUT(path string, h HandlerFunc, mw ...Middleware)
- func (a *App) Plugins() []string
- func (a *App) RegisterPlugins(plugins ...Plugin) error
- func (a *App) Routes() []RouteInfo
- func (a *App) Run() error
- func (a *App) SQL() db.Adapter
- func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (a *App) SetORMDialect(dialect string)
- func (a *App) SetSQL(adapter db.Adapter)
- func (a *App) SetValidator(v Validator)
- func (a *App) Use(mw ...Middleware)
- type Config
- type Ctx
- func (c *Ctx) BindJSON(dst any) error
- func (c *Ctx) Get(key string) (any, bool)
- func (c *Ctx) Header(name string) string
- func (c *Ctx) JSON(status int, body any) error
- func (c *Ctx) Param(name string) string
- func (c *Ctx) Query(name string) string
- func (c *Ctx) RoutePattern() string
- func (c *Ctx) Set(key string, value any)
- func (c *Ctx) Text(status int, msg string) error
- func (c *Ctx) Validate(v any) error
- type ErrorBody
- type ErrorResponse
- type Group
- func (g *Group) DELETE(path string, h HandlerFunc, mw ...Middleware)
- func (g *Group) GET(path string, h HandlerFunc, mw ...Middleware)
- func (g *Group) Group(prefix string, mw ...Middleware) *Group
- func (g *Group) PATCH(path string, h HandlerFunc, mw ...Middleware)
- func (g *Group) POST(path string, h HandlerFunc, mw ...Middleware)
- func (g *Group) PUT(path string, h HandlerFunc, mw ...Middleware)
- type HTTPError
- type HandlerFunc
- type Middleware
- type NamedRoute
- func (n *NamedRoute) DELETE(path string, h HandlerFunc, mw ...Middleware)
- func (n *NamedRoute) GET(path string, h HandlerFunc, mw ...Middleware)
- func (n *NamedRoute) PATCH(path string, h HandlerFunc, mw ...Middleware)
- func (n *NamedRoute) POST(path string, h HandlerFunc, mw ...Middleware)
- func (n *NamedRoute) PUT(path string, h HandlerFunc, mw ...Middleware)
- type Plugin
- type RouteInfo
- type Validator
Constants ¶
const ( CodeBadRequest = "BAD_REQUEST" CodeForbidden = "FORBIDDEN" CodeNotFound = "NOT_FOUND" CodeConflict = "CONFLICT" CodeInternal = "INTERNAL_ERROR" )
const (
Version = "0.2.3"
)
Variables ¶
This section is empty.
Functions ¶
func ErrBadRequest ¶
func ErrConflict ¶
func ErrForbidden ¶
func ErrInternal ¶
func ErrNotFound ¶
func ErrUnauthorized ¶
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App is the main elgon application.
func (*App) DELETE ¶
func (a *App) DELETE(path string, h HandlerFunc, mw ...Middleware)
func (*App) GET ¶
func (a *App) GET(path string, h HandlerFunc, mw ...Middleware)
func (*App) Named ¶
func (a *App) Named(name string) *NamedRoute
func (*App) PATCH ¶
func (a *App) PATCH(path string, h HandlerFunc, mw ...Middleware)
func (*App) POST ¶
func (a *App) POST(path string, h HandlerFunc, mw ...Middleware)
func (*App) PUT ¶
func (a *App) PUT(path string, h HandlerFunc, mw ...Middleware)
func (*App) RegisterPlugins ¶
RegisterPlugins initializes and registers one or more plugins.
func (*App) SetORMDialect ¶
SetORMDialect sets placeholder behavior for app.ORM() repositories.
func (*App) SetValidator ¶
func (*App) Use ¶
func (a *App) Use(mw ...Middleware)
type Config ¶
type Config struct {
Addr string
ReadTimeout time.Duration
WriteTimeout time.Duration
IdleTimeout time.Duration
ShutdownTimeout time.Duration
DisableHealthz bool
EnableMetricsStub bool
}
Config defines server runtime options.
type Ctx ¶
type Ctx struct {
Writer http.ResponseWriter
Request *http.Request
// contains filtered or unexported fields
}
Ctx wraps request and response objects plus request-scoped helpers.
func (*Ctx) RoutePattern ¶
type ErrorBody ¶
type ErrorBody struct {
Code string `json:"code"`
Message string `json:"message"`
Details any `json:"details,omitempty"`
RequestID string `json:"request_id,omitempty"`
}
ErrorBody describes API error details.
type ErrorResponse ¶
type ErrorResponse struct {
Error ErrorBody `json:"error"`
}
ErrorResponse is the default structured error payload.
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group is a route group with a shared prefix and middleware.
func (*Group) DELETE ¶
func (g *Group) DELETE(path string, h HandlerFunc, mw ...Middleware)
func (*Group) GET ¶
func (g *Group) GET(path string, h HandlerFunc, mw ...Middleware)
func (*Group) PATCH ¶
func (g *Group) PATCH(path string, h HandlerFunc, mw ...Middleware)
func (*Group) POST ¶
func (g *Group) POST(path string, h HandlerFunc, mw ...Middleware)
func (*Group) PUT ¶
func (g *Group) PUT(path string, h HandlerFunc, mw ...Middleware)
type HandlerFunc ¶
HandlerFunc handles an HTTP request and returns an error for centralized handling.
type Middleware ¶
type Middleware func(HandlerFunc) HandlerFunc
Middleware wraps a handler with extra behavior.
type NamedRoute ¶
type NamedRoute struct {
// contains filtered or unexported fields
}
NamedRoute allows registering a route and associating it with a name.
func (*NamedRoute) DELETE ¶
func (n *NamedRoute) DELETE(path string, h HandlerFunc, mw ...Middleware)
func (*NamedRoute) GET ¶
func (n *NamedRoute) GET(path string, h HandlerFunc, mw ...Middleware)
func (*NamedRoute) PATCH ¶
func (n *NamedRoute) PATCH(path string, h HandlerFunc, mw ...Middleware)
func (*NamedRoute) POST ¶
func (n *NamedRoute) POST(path string, h HandlerFunc, mw ...Middleware)
func (*NamedRoute) PUT ¶
func (n *NamedRoute) PUT(path string, h HandlerFunc, mw ...Middleware)
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
api
command
|
|
|
elgon
command
|
|
|
kafkaadapter
Package kafkaadapter provides kafka-go implementations of jobs.KafkaProducer and jobs.KafkaConsumer.
|
Package kafkaadapter provides kafka-go implementations of jobs.KafkaProducer and jobs.KafkaConsumer. |
|
redisadapter
Package redisadapter provides a go-redis implementation of jobs.RedisClient.
|
Package redisadapter provides a go-redis implementation of jobs.RedisClient. |