Skip to main content


Gearbox ⚙️ instance that provides functionalities of Gearbox


creates a new instance of Gearbox with optional settings

New(settings ...*Settings) Gearbox 


You can pass application settings when calling New

func main() {    // Setup gearbox    g := gearbox.New(&gearbox.Settings{        CaseInSensitive: true        ServerName:      "gearbox"    })
    // ...
    // Start service    g.Start(":3000")}

Settings fields

ServerNamestringEnables the Server HTTP header with the given value""
CaseInSensitiveboolWhen disabled, /Foo and /foo are different routes. When enabled, /Fooand /foo are treated the samefalse
HandleMethodNotAllowedboolEnables answering with HTTP status code 405 if request does not match with any route, but there are another methods are allowed for that route otherwise answer with Not Found handlers or status code 404.false
HandleOPTIONSboolEnables automatic replies to OPTIONS requests if there are no handlers registered for that routefalse
AutoRecoverboolEnables automatic recovering from panic while executing handlers by answering with HTTP status code 500 and logging error message without stopping servicefalse
MaxRequestBodySizeintSets the maximum allowed size for a request body, if the size exceeds the configured limit, it sends 413 - Request Entity Too Large response4 * 1024 * 1024
ConcurrencyintMaximum number of concurrent connections256 * 1024
CacheSizeintMaximum size of LRU cache if it's enabled1000
DisableCachingboolDisable LRU caching (used for speed up route matching) for recent CacheSize matched routesfalse
DisableKeepaliveboolDisable keep-alive connections, the server will close incoming connections after sending the first response to clientfalse
DisableDefaultDateboolWhen set to true causes the default date header to be excluded from the responsefalse
DisableDefaultContentTypeboolWhen set to true, causes the default Content-Type header to be excluded from the Responsefalse
DisableStartupMessageboolWhen set to true, it will not print out Gearbox bannerfalse
DisableHeaderNormalizingboolBy default all header names are normalized: conteNT-tYPE -> Content-Typefalse
ReadTimeouttime.DurationThe amount of time allowed to read the full request, including bodyunlimited
WriteTimeouttime.DurationThe maximum duration before timing out writes of the responseunlimited
IdleTimeouttime.DurationThe maximum amount of time to wait for the next request when keep-alive is enabled. If IdleTimeout is zero, the value of ReadTimeout is usedunlimited

HTTP Methods#

Routes an HTTP request, where METHOD is the HTTP method of the request


The GET method requests a representation of the specified resource. Requests using GET should only retrieve data

Get(path string, handlers ...handlerFunc) *Route


The HEAD method asks for a response identical to that of a GET request, but without the response body

Head(path string, handlers ...handlerFunc) *Route


The POST method is used to submit an entity to the specified resource, often causing a change in state or side effects on the server

Post(path string, handlers ...handlerFunc) *Route


The PUT method replaces all current representations of the target resource with the request payload

Put(path string, handlers ...handlerFunc) *Route


The DELETE method deletes the specified resource

Delete(path string, handlers ...handlerFunc) *Route


The CONNECT method establishes a tunnel to the server identified by the target resource

Connect(path string, handlers ...handlerFunc) *Route


The OPTIONS method is used to describe the communication options for the target resource

Options(path string, handlers ...handlerFunc) *Route


The TRACE method performs a message loop-back test along the path to the target resource

Trace(path string, handlers ...handlerFunc) *Route


The PATCH method is used to apply partial modifications to a resource

Patch(path string, handlers ...handlerFunc) *Route

Not Found#

A default handlers that will be called if there is no matches for requested route

NotFound(handlers ...handlerFunc)


Applies middlware(s) to be called in order they were defined before calling handlers

Use(middlewares ...handlerFunc)


Serves static file(s) in root directory uder specific prefix

Static(prefix, root string)

For Example

// Serve files in assets directory for prefix static// requests will be like // http://localhost:3000/static/gearbox.pnggb.Static("/static", "./assets")


Groups registered routes under specific prefix

Group(prefix string, routes []*Route) []*Route

For Example

gb.Group("/account",  []*gearbox.Route{    gb.Get("/id", func(ctx gearbox.Context) {        ctx.SendString("User X")    })})

Handles requests for /account/id