allium

package module
v0.0.0-...-f2f513a Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: MIT Imports: 11 Imported by: 0

README

Allium

An ultra-minimalist and experimental Go web framework prioritising developer experience and expressiveness.

Installation

go get github.com/ashtonjamesd/allium

Quick Start

package main

import . "github.com/ashtonjamesd/allium"

func Index(_ Ctx) Res {
    return Ok("Hello, World!")
}

func main() {
    // initialise a web app
    App().
        // register an endpoint
        Get(Index).
        // run the app
        Run()
}

You can also create a reference to app instead of using a fluent interface.

package main

import . "github.com/ashtonjamesd/allium"

func Index(_ Ctx) Res {
    return Ok("Hello, World!")
}

func main() {
    app := App()
    app.Get(Index)

    app.Run()
}

Configuration

The app defaults to port 3000. To change this, use the port method.

app.Port(3000)

The App method also supports an optional port parameter as an alternative to using Port.

Routing

Routing in Allium is intentionally reflective. The names of your controllers can be used to implicitly define behaviour, reducing boilerplate and improving readability.

Using app.Do, Allium automatically infers the HTTP method from the controller name. For example, any function whose name begins with 'get' (case-insensitive) is registered as a GET route:

app.Do(GetPerson)

The following example registers two GET routes, a POST, a DELETE, and a PATCH, purely based on naming conventions:

app.Do(
    GetPerson,
    GetPeople,
    CreatePerson,
    DeletePerson,
    UpdatePerson,
)

See /doc for more information on middleware, environment variables, etc.

Why?

To experiment with a framework focused on developer experience and speed in tandem with Go's fast compile times. I also wanted to learn Go.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Controller

type Controller = func(_ Ctx) Res

type Ctx

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

func (*Ctx) Body

func (c *Ctx) Body() string

type DotEnvParser

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

func (*DotEnvParser) Parse

func (d *DotEnvParser) Parse() map[string]string

func (*DotEnvParser) ParseVariable

func (d *DotEnvParser) ParseVariable() string

type Json

type Json struct{}

type Middleware

type Middleware func(Ctx, func()) Res

type Res

type Res = struct {
	// contains filtered or unexported fields
}

func Accepted

func Accepted(body string) Res

func AlreadyReported

func AlreadyReported(body string) Res

func BadGateway

func BadGateway(body string) Res

func BadRequest

func BadRequest(body string) Res

func BasicAuth

func BasicAuth(ctx Ctx, next func()) Res

func Conflict

func Conflict(body string) Res

func Continue

func Continue(body string) Res

func Created

func Created(body string) Res

func EarlyHints

func EarlyHints(body string) Res

func ExpectationFailed

func ExpectationFailed(body string) Res

func FailedDependency

func FailedDependency(body string) Res

func Forbidden

func Forbidden(body string) Res

func Found

func Found(body string) Res

func GatewayTimeout

func GatewayTimeout(body string) Res

func Gone

func Gone(body string) Res

func HTTPVersionNotSupported

func HTTPVersionNotSupported(body string) Res

func IMUsed

func IMUsed(body string) Res

func InsufficientStorage

func InsufficientStorage(body string) Res

func InternalError

func InternalError(body string) Res

func LengthRequired

func LengthRequired(body string) Res

func Locked

func Locked(body string) Res

func Logger

func Logger(ctx Ctx, next func()) Res

func LoopDetected

func LoopDetected(body string) Res

func MethodNotAllowed

func MethodNotAllowed(body string) Res

func MisdirectedRequest

func MisdirectedRequest(body string) Res

func MovedPermanently

func MovedPermanently(body string) Res

func MultiStatus

func MultiStatus(body string) Res

func MultipleChoices

func MultipleChoices(body string) Res

func NetworkAuthenticationRequired

func NetworkAuthenticationRequired(body string) Res

func NoContent

func NoContent(body string) Res

func NonAuthoritativeInfo

func NonAuthoritativeInfo(body string) Res

func NotAcceptable

func NotAcceptable(body string) Res

func NotExtended

func NotExtended(body string) Res

func NotFound

func NotFound(body string) Res

func NotImplemented

func NotImplemented(body string) Res

func NotModified

func NotModified(body string) Res

func Ok

func Ok(body string) Res

func PartialContent

func PartialContent(body string) Res

func PaymentRequired

func PaymentRequired(body string) Res

func PermanentRedirect

func PermanentRedirect(body string) Res

func PreconditionFailed

func PreconditionFailed(body string) Res

func PreconditionRequired

func PreconditionRequired(body string) Res

func Processing

func Processing(body string) Res

func ProxyAuthRequired

func ProxyAuthRequired(body string) Res

func RequestEntityTooLarge

func RequestEntityTooLarge(body string) Res

func RequestHeaderFieldsTooLarge

func RequestHeaderFieldsTooLarge(body string) Res

func RequestTimeout

func RequestTimeout(body string) Res

func RequestURITooLong

func RequestURITooLong(body string) Res

func RequestedRangeNotSatisfiable

func RequestedRangeNotSatisfiable(body string) Res

func ResetContent

func ResetContent(body string) Res

func Response

func Response(statusCode int, body string) Res

func SeeOther

func SeeOther(body string) Res

func ServiceUnavailable

func ServiceUnavailable(body string) Res

func SwitchingProtocols

func SwitchingProtocols(body string) Res

func Teapot

func Teapot(body string) Res

func TemporaryRedirect

func TemporaryRedirect(body string) Res

func TooEarly

func TooEarly(body string) Res

func TooManyRequests

func TooManyRequests(body string) Res

func Unauthorized

func Unauthorized(body string) Res

func UnavailableForLegalReasons

func UnavailableForLegalReasons(body string) Res

func UnprocessableEntity

func UnprocessableEntity(body string) Res

func UnsupportedMediaType

func UnsupportedMediaType(body string) Res

func UpgradeRequired

func UpgradeRequired(body string) Res

func UseProxy

func UseProxy(body string) Res

func VariantAlsoNegotiates

func VariantAlsoNegotiates(body string) Res

type Route

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

type RouteNameMode

type RouteNameMode int
const (
	CamelCase RouteNameMode = iota
	SnakeCase
	PascalCase
)

type WebApp

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

func App

func App(portMaybe ...int) *WebApp

Create a new Allium web app instance with an optional port parameter.

func (*WebApp) Connect

func (app *WebApp) Connect(handler Controller) *WebApp

func (*WebApp) Debug

func (app *WebApp) Debug(val bool) *WebApp

Displays debug information on the web application.

func (*WebApp) Delete

func (app *WebApp) Delete(handler Controller) *WebApp

func (*WebApp) Do

func (app *WebApp) Do(handlers ...Controller) *WebApp

func (*WebApp) DoRoute

func (app *WebApp) DoRoute(handler Controller, method string)

func (*WebApp) DotEnv

func (app *WebApp) DotEnv(dotenvFile string) *WebApp

Specifies a file for environment variable injection.

func (*WebApp) Env

func (app *WebApp) Env(environment string) *WebApp

Sets the application environment string.

func (*WebApp) Get

func (app *WebApp) Get(handler Controller) *WebApp

func (*WebApp) Gmw

func (app *WebApp) Gmw(middlewares ...Middleware) *WebApp

Registers middleware into the global middleware pipeline. Applies to all routes.

func (*WebApp) Head

func (app *WebApp) Head(handler Controller) *WebApp

func (*WebApp) Mw

func (app *WebApp) Mw(middlewares ...Middleware) *WebApp

Registers middleware for a specific route.

func (*WebApp) Options

func (app *WebApp) Options(handler Controller) *WebApp

func (*WebApp) Patch

func (app *WebApp) Patch(handler Controller) *WebApp

func (*WebApp) Port

func (app *WebApp) Port(port int) *WebApp

Specify the port for which the server runs on.

func (*WebApp) Post

func (app *WebApp) Post(handler Controller) *WebApp

func (*WebApp) PrintRoutes

func (app *WebApp) PrintRoutes()

PrintRoutes outputs all registered routes with their HTTP methods and resources

func (*WebApp) Put

func (app *WebApp) Put(handler Controller) *WebApp

func (*WebApp) RegisterRoutes

func (app *WebApp) RegisterRoutes()

func (*WebApp) RouteBy

func (app *WebApp) RouteBy(routeMode RouteNameMode) *WebApp

Changes the route name generation to use a different casing. The default is camelCase.

func (*WebApp) Run

func (app *WebApp) Run() bool

Runs the web application.

func (*WebApp) Sqlite

func (app *WebApp) Sqlite(path string) *WebApp

func (*WebApp) Trace

func (app *WebApp) Trace(handler Controller) *WebApp

func (*WebApp) Var

func (app *WebApp) Var(key string) string

Attempts to get an injected environment variable

Directories

Path Synopsis
cmd
allium command

Jump to

Keyboard shortcuts

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