Home

Awesome

<p align="center"> <a href="https://gogearbox.com"> <img src="https://raw.githubusercontent.com/gogearbox/gearbox/master/assets/gearbox-512.png"/> </a> <br /> <a href="https://godoc.org/github.com/gogearbox/gearbox"> <img src="https://godoc.org/github.com/gogearbox/gearbox?status.png" /> </a> <img src="https://github.com/gogearbox/gearbox/workflows/Test%20&%20Build/badge.svg?branch=master" /> <a href="https://codecov.io/gh/gogearbox/gearbox"> <img src="https://codecov.io/gh/gogearbox/gearbox/branch/master/graph/badge.svg" /> </a> <a href="https://goreportcard.com/report/github.com/gogearbox/gearbox"> <img src="https://goreportcard.com/badge/github.com/gogearbox/gearbox" /> </a> <a href="https://discord.com/invite/CT8my4R"> <img src="https://img.shields.io/discord/716724372642988064?label=Discord&logo=discord"> </a> <a href="https://deepsource.io/gh/gogearbox/gearbox/?ref=repository-badge" target="_blank"> <img alt="DeepSource" title="DeepSource" src="https://static.deepsource.io/deepsource-badge-light-mini.svg"> </a> </p>

gearbox :gear: is a web framework for building micro services written in Go with a focus on high performance. It's built on fasthttp which is up to 10x faster than net/http

gearbox seeks to be

Supported Go versions & installation

:gear: gearbox requires version 1.14 or higher of Go (Download Go)

Just use go get to download and install gearbox

go get -u github.com/gogearbox/gearbox

Examples

package main

import (
	"github.com/gogearbox/gearbox"
)

func main() {
	// Setup gearbox
	gb := gearbox.New()

	// Define your handlers
	gb.Get("/hello", func(ctx gearbox.Context) {
		ctx.SendString("Hello World!")
	})

	// Start service
	gb.Start(":3000")
}

Parameters

package main

import (
	"github.com/gogearbox/gearbox"
)

func main() {
	// Setup gearbox
	gb := gearbox.New()

	// Handler with parameter
	gb.Get("/users/:user", func(ctx gearbox.Context) {
		ctx.SendString(ctx.Param("user"))
	})

	// Start service
	gb.Start(":3000")
}

Middlewares

package main

import (
	"log"

	"github.com/gogearbox/gearbox"
)

func main() {
	// Setup gearbox
	gb := gearbox.New()

	// create a logger middleware
	logMiddleware := func(ctx gearbox.Context) {
		log.Printf("log message!")

		// Next is what allows the request to continue to the next
		// middleware/handler
		ctx.Next()
	}

	// create an unauthorized middleware
	unAuthorizedMiddleware := func(ctx gearbox.Context) {
		ctx.Status(gearbox.StatusUnauthorized)
			.SendString("You are unauthorized to access this page!")
	}

	// Register the log middleware for all requests
	gb.Use(logMiddleware)

	// Define your handlers
	gb.Get("/hello", func(ctx gearbox.Context) {
		ctx.SendString("Hello World!")
	})

	// Register the routes to be used when grouping routes
	routes := []*gearbox.Route{
		gb.Get("/id", func(ctx gearbox.Context) {
			ctx.SendString("User X")
		}),
		gb.Delete("/id", func(ctx gearbox.Context) {
			ctx.SendString("Deleted")
		}),
	}

	// Group account routes
	accountRoutes := gb.Group("/account", routes)

	// Group account routes to be under api
	gb.Group("/api", accountRoutes)

	// Define a route with unAuthorizedMiddleware as the middleware
	// you can define as many middlewares as you want and have
	// the handler as the last argument
	gb.Get("/protected", unAuthorizedMiddleware, func(ctx gearbox.Context) {
		ctx.SendString("You accessed a protected page")
	})

	// Start service
	gb.Start(":3000")
}

Static Files

package main

import (
	"github.com/gogearbox/gearbox"
)

func main() {
	// Setup gearbox
	gb := gearbox.New()

	// Serve files in assets directory for prefix static
	// for example /static/gearbox.png, etc.
	gb.Static("/static", "./assets")

	// Start service
	gb.Start(":3000")
}

Benchmarks

<p align="center"> <img src="https://raw.githubusercontent.com/gogearbox/gearbox/master/assets/benchmark-pipeline.png" width="85%"/> </p>

For more results, check Our Docs

Contribute & Support

Check Our Docs for more information about gearbox and how to contribute

Sponsors

Organizations that are helping to manage, promote, and support Gearbox :gear:

<img src="https://raw.githubusercontent.com/gogearbox/gearbox/master/assets/trella-sponsor.png"/>
trella: A B2B technology platform and trucking <br/>marketplace that connects shippers with carriers

Who uses Gearbox

Gearbox :gear: is being used by multiple organizations including but not limited to

<img src="https://raw.githubusercontent.com/gogearbox/gearbox/master/assets/erply-user.png"/> <img src="https://raw.githubusercontent.com/gogearbox/gearbox/master/assets/trella-sponsor.png"/>

Contributors

<a href="https://github.com/gogearbox/gearbox/graphs/contributors"> <img src="https://contributors-img.firebaseapp.com/image?repo=gogearbox/gearbox" /> </a>

Get in touch!

Feel free to chat with us on Discord, or email us at gearbox@googlegroups.com if you have questions, or suggestions

License

gearbox is licensed under MIT License

Logo is created by Mahmoud Sayed and distributed under Creative Commons License

Third-party library licenses