orbit

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: MIT Imports: 25 Imported by: 0

README

Go Orbit

Go Orbit is a lightweight HTTP web framework for Go, built on net/http and httprouter.

It provides routing, middleware, route groups, request helpers, structured responses, static files, error handling, TLS, and graceful shutdown.

Installation

go get git.trcreatives.at/packages/go-orbit

Quick Start

package main

import (
    "log"
    "net/http"

    orbit "git.trcreatives.at/packages/go-orbit"
)

func main() {
    app := orbit.New()

    app.GET("/", func(ctx *orbit.Context) error {
        return ctx.String(http.StatusOK, "Hello from Orbit!")
    })

    if err := app.Start(":8080"); err != nil {
        log.Fatal(err)
    }
}

Documentation

See docs/.

License

See LICENSE.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

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

func New

func New() *App

func (*App) CONNECT

func (app *App) CONNECT(path string, h Handler, mws ...Middleware)

func (*App) DELETE

func (app *App) DELETE(path string, h Handler, mws ...Middleware)

func (*App) GET

func (app *App) GET(path string, h Handler, mws ...Middleware)

func (*App) Group

func (app *App) Group(prefix string, mws ...Middleware) *Group

func (*App) HEAD

func (app *App) HEAD(path string, h Handler, mws ...Middleware)

func (*App) Handle

func (app *App) Handle(method, path string, h Handler, mws ...Middleware)

func (*App) OPTIONS

func (app *App) OPTIONS(path string, h Handler, mws ...Middleware)

func (*App) PATCH

func (app *App) PATCH(path string, h Handler, mws ...Middleware)

func (*App) POST

func (app *App) POST(path string, h Handler, mws ...Middleware)

func (*App) PUT

func (app *App) PUT(path string, h Handler, mws ...Middleware)

func (*App) ServeHTTP

func (app *App) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*App) SetErrorHandler

func (app *App) SetErrorHandler(errorHandler ErrorHandler)

func (*App) SetGlobalOptionsHandler

func (app *App) SetGlobalOptionsHandler(globalOptionsHandler Handler)

func (*App) SetMethodNotAllowedHandler

func (app *App) SetMethodNotAllowedHandler(methodNotAllowedHandler Handler)

func (*App) SetNotFoundHandler

func (app *App) SetNotFoundHandler(notFoundHandler Handler)

func (*App) SetRedirectFixedPath

func (app *App) SetRedirectFixedPath(redirectFixedPath bool)

func (*App) SetRedirectTrailingSlash

func (app *App) SetRedirectTrailingSlash(redirectTrailingSlash bool)

func (*App) SetServerIdleTimeout

func (app *App) SetServerIdleTimeout(idleTimeout time.Duration)

func (*App) SetServerMaxHeaderBytes

func (app *App) SetServerMaxHeaderBytes(maxHeaderBytes int)

func (*App) SetServerReadHeaderTimeout

func (app *App) SetServerReadHeaderTimeout(readHeaderTimeout time.Duration)

func (*App) SetServerReadTimeout

func (app *App) SetServerReadTimeout(readTimeout time.Duration)

func (*App) SetServerShutdownTimeout

func (app *App) SetServerShutdownTimeout(shutdownTimeout time.Duration)

func (*App) SetServerWriteTimeout

func (app *App) SetServerWriteTimeout(writeTimeout time.Duration)

func (*App) Start

func (app *App) Start(listenAddr string) error

func (*App) StartTLS

func (app *App) StartTLS(listenAddr, certFile, keyFile string) error

func (*App) Static

func (app *App) Static(prefix, root string, mws ...Middleware)

func (*App) StaticFS

func (app *App) StaticFS(prefix string, fs http.FileSystem, mws ...Middleware)

func (*App) TRACE

func (app *App) TRACE(path string, h Handler, mws ...Middleware)

func (*App) Use

func (app *App) Use(mws ...Middleware)

type CORSConfig added in v1.1.0

type CORSConfig struct {
	AllowOrigins     []string
	AllowMethods     []string
	AllowHeaders     []string
	ExposeHeaders    []string
	AllowCredentials bool
	MaxAge           time.Duration
}

type Context

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

func (*Context) AddHeader

func (ctx *Context) AddHeader(name, value string)

func (*Context) BasicAuth

func (ctx *Context) BasicAuth() (string, string, bool)

func (*Context) Body

func (ctx *Context) Body() io.ReadCloser

---------------------------------------------------------------------- Request body ----------------------------------------------------------------------

func (*Context) Bytes

func (ctx *Context) Bytes(status int, contentType string, body []byte) error

---------------------------------------------------------------------- Response bodies ----------------------------------------------------------------------

func (*Context) ContentType

func (ctx *Context) ContentType() string

func (*Context) Cookie

func (ctx *Context) Cookie(name string) (*http.Cookie, error)

---------------------------------------------------------------------- Request cookies ----------------------------------------------------------------------

func (*Context) Cookies

func (ctx *Context) Cookies() []*http.Cookie

func (*Context) DecodeForm added in v1.2.0

func (ctx *Context) DecodeForm(destination any) error

func (*Context) DecodeJSON

func (ctx *Context) DecodeJSON(destination any) error

func (*Context) DecodeXML

func (ctx *Context) DecodeXML(destination any) error

func (*Context) DeleteCookie

func (ctx *Context) DeleteCookie(cookie *http.Cookie)

func (*Context) DeleteHeader

func (ctx *Context) DeleteHeader(name string)

func (*Context) DeleteValue

func (ctx *Context) DeleteValue(key string)

func (*Context) File

func (ctx *Context) File(path string) error

---------------------------------------------------------------------- Files ----------------------------------------------------------------------

func (*Context) Flush

func (ctx *Context) Flush() error

func (*Context) FormFile

func (ctx *Context) FormFile(name string) (multipart.File, *multipart.FileHeader, error)

func (*Context) FormValue

func (ctx *Context) FormValue(name string) string

func (*Context) FormValues

func (ctx *Context) FormValues(name string) ([]string, error)

func (*Context) Forms

func (ctx *Context) Forms() (url.Values, error)

func (*Context) HTML

func (ctx *Context) HTML(status int, value string) error

func (*Context) HasQuery

func (ctx *Context) HasQuery(name string) bool

func (*Context) Header

func (ctx *Context) Header(name string) string

---------------------------------------------------------------------- Request headers ----------------------------------------------------------------------

func (*Context) Headers

func (ctx *Context) Headers() http.Header

func (*Context) Host

func (ctx *Context) Host() string

func (*Context) IsTLS

func (ctx *Context) IsTLS() bool

func (*Context) JSON

func (ctx *Context) JSON(status int, value any) error

func (*Context) LimitBody

func (ctx *Context) LimitBody(maxBytes int64)

func (*Context) Method

func (ctx *Context) Method() string

---------------------------------------------------------------------- Request metadata ----------------------------------------------------------------------

func (*Context) MultipartForm

func (ctx *Context) MultipartForm(maxMemory int64) (*multipart.Form, error)

---------------------------------------------------------------------- Multipart forms and uploads ----------------------------------------------------------------------

func (*Context) MultipartReader

func (ctx *Context) MultipartReader() (*multipart.Reader, error)

func (*Context) NoContent

func (ctx *Context) NoContent(status int) error

func (*Context) Param

func (ctx *Context) Param(name string) string

---------------------------------------------------------------------- Routing ----------------------------------------------------------------------

func (*Context) Params

func (ctx *Context) Params() map[string]string

func (*Context) ParseForm

func (ctx *Context) ParseForm() error

---------------------------------------------------------------------- Forms ----------------------------------------------------------------------

func (*Context) ParseQuery

func (ctx *Context) ParseQuery() (url.Values, error)

func (*Context) Path

func (ctx *Context) Path() string

func (*Context) Queries

func (ctx *Context) Queries() url.Values

func (*Context) Query

func (ctx *Context) Query(name string) string

---------------------------------------------------------------------- Query parameters ----------------------------------------------------------------------

func (*Context) QueryValues

func (ctx *Context) QueryValues(name string) []string

func (*Context) Redirect

func (ctx *Context) Redirect(status int, location string)

---------------------------------------------------------------------- Redirects ----------------------------------------------------------------------

func (*Context) RemoteIP

func (ctx *Context) RemoteIP() string

func (*Context) Render added in v1.3.0

func (ctx *Context) Render(status int, component templ.Component) error

func (*Context) Request

func (ctx *Context) Request() *http.Request

---------------------------------------------------------------------- Core ----------------------------------------------------------------------

func (*Context) RequestContext

func (ctx *Context) RequestContext() context.Context

---------------------------------------------------------------------- Standard context ----------------------------------------------------------------------

func (*Context) Response

func (ctx *Context) Response() http.ResponseWriter

func (*Context) ResponseHeader

func (ctx *Context) ResponseHeader(name string) string

---------------------------------------------------------------------- Response headers ----------------------------------------------------------------------

func (*Context) Scheme

func (ctx *Context) Scheme() string

func (*Context) SetContentType

func (ctx *Context) SetContentType(contentType string)

func (*Context) SetCookie

func (ctx *Context) SetCookie(cookie *http.Cookie)

---------------------------------------------------------------------- Response cookies ----------------------------------------------------------------------

func (*Context) SetHeader

func (ctx *Context) SetHeader(name, value string)

func (*Context) SetRequestContext

func (ctx *Context) SetRequestContext(c context.Context)

func (*Context) SetValue

func (ctx *Context) SetValue(key string, value any)

---------------------------------------------------------------------- Request-scoped values ----------------------------------------------------------------------

func (*Context) Size

func (ctx *Context) Size() int64

func (*Context) Status

func (ctx *Context) Status() int

---------------------------------------------------------------------- Response state ----------------------------------------------------------------------

func (*Context) Stream

func (ctx *Context) Stream(status int, contentType string, reader io.Reader) error

---------------------------------------------------------------------- Streaming ----------------------------------------------------------------------

func (*Context) String

func (ctx *Context) String(status int, value string) error

func (*Context) Validate added in v1.2.0

func (ctx *Context) Validate(value any) error

---------------------------------------------------------------------- Validation ----------------------------------------------------------------------

func (*Context) Value

func (ctx *Context) Value(key string) (any, bool)

func (*Context) Values

func (ctx *Context) Values() map[string]any

func (*Context) WriteHeader

func (ctx *Context) WriteHeader(status int)

---------------------------------------------------------------------- Response status ----------------------------------------------------------------------

func (*Context) Written

func (ctx *Context) Written() bool

func (*Context) XML

func (ctx *Context) XML(status int, value any) error

type ErrorHandler

type ErrorHandler func(ctx *Context, err error) error

type Group

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

func (*Group) CONNECT

func (g *Group) CONNECT(path string, h Handler, mws ...Middleware)

func (*Group) DELETE

func (g *Group) DELETE(path string, h Handler, mws ...Middleware)

func (*Group) GET

func (g *Group) GET(path string, h Handler, mws ...Middleware)

func (*Group) Group

func (g *Group) Group(prefix string, mws ...Middleware) *Group

func (*Group) HEAD

func (g *Group) HEAD(path string, h Handler, mws ...Middleware)

func (*Group) Handle

func (g *Group) Handle(method, path string, h Handler, mws ...Middleware)

func (*Group) OPTIONS

func (g *Group) OPTIONS(path string, h Handler, mws ...Middleware)

func (*Group) PATCH

func (g *Group) PATCH(path string, h Handler, mws ...Middleware)

func (*Group) POST

func (g *Group) POST(path string, h Handler, mws ...Middleware)

func (*Group) PUT

func (g *Group) PUT(path string, h Handler, mws ...Middleware)

func (*Group) TRACE

func (g *Group) TRACE(path string, h Handler, mws ...Middleware)

func (*Group) Use

func (g *Group) Use(mws ...Middleware)

type Handler

type Handler func(ctx *Context) error

type Map

type Map map[string]any

type Middleware

type Middleware func(next Handler) Handler

func BodyLimit added in v1.1.0

func BodyLimit(maxBytes int64) Middleware

func CORS added in v1.1.0

func CORS(config CORSConfig) Middleware

func Recovery added in v1.1.0

func Recovery() Middleware

type Router

type Router interface {
	Use(mws ...Middleware)
	Group(prefix string, mws ...Middleware) *Group

	Handle(method, path string, h Handler, mws ...Middleware)

	CONNECT(path string, h Handler, mws ...Middleware)
	DELETE(path string, h Handler, mws ...Middleware)
	GET(path string, h Handler, mws ...Middleware)
	HEAD(path string, h Handler, mws ...Middleware)
	OPTIONS(path string, h Handler, mws ...Middleware)
	PATCH(path string, h Handler, mws ...Middleware)
	POST(path string, h Handler, mws ...Middleware)
	PUT(path string, h Handler, mws ...Middleware)
	TRACE(path string, h Handler, mws ...Middleware)
}

Jump to

Keyboard shortcuts

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