Gorbit is an Express-inspired web framework for Go focused on simplicity, performance, and an intuitive developer experience. It provides routing, middleware, WebSockets, static file serving, and modular APIs without unnecessary abstractions.
- Installation
- Quick Start
- Routing
- Route Parameters
- Middleware
- Router Groups
- CORS
- BindJSON
- Cookies
- File Uploads
- Responses
- WebSockets
- Project Structure
- Examples
- Documentation
- Roadmap
- Contributing
- License
- 🚀 Lightweight with zero unnecessary abstractions
- ⚡ Fast HTTP router
- 📦 Modular middleware system
- 🔌 Built-in WebSocket support
- 📁 Route mounting
- 🎯 URL parameters
- 🔄 Middleware chaining
- 🧩 Simple and expressive API
- ❤️ Easy to learn for Node.js developers
Requires Go 1.26 or newer.
go get github.com/pav-studio/gorbitpackage main
import (
"log"
gb "github.com/pav-studio/gorbit"
"github.com/pav-studio/gorbit/middleware"
)
func main() {
app := gb.New(3000)
app.Use(middleware.AllowAllCORS())
app.GET("/", func(c *gb.Ctx) {
c.OK(gb.JSON{
"framework": "Gorbit",
"message": "Hello, World!",
"status": "running",
})
})
app.GET("/hello/:name", func(c *gb.Ctx) {
c.OK(gb.JSON{
"message": "Hello, " + c.Param("name") + "!",
})
})
if err := app.Start(); err != nil {
log.Fatal(err)
}
}Run:
go run .Server:
http://localhost:3000
Share data between middleware and handlers during a request.
app.Use(func(c *gb.Ctx) {
c.Set("userID", 42)
c.Next()
})
app.GET("/profile", func(c *gb.Ctx) {
id, _ := c.Get("userID")
c.OK(gb.JSON{
"id": id,
})
})Gorbit supports the standard HTTP methods and expressive route definitions with URL parameters.
app.GET("/users", func(c *gb.Ctx) {
c.OK(gb.JSON{
"users": []string{
"Alice",
"Bob",
},
})
})app.POST("/users", func(c *gb.Ctx) {
type CreateUserRequest struct {
Name string `json:"name"`
}
var body CreateUserRequest
if err := c.BindJSON(&body); err != nil {
c.BadRequest(gb.JSON{
"error": "Invalid request body",
})
return
}
c.Created(gb.JSON{
"name": body.Name,
})
})app.PUT("/users/:id", func(c *gb.Ctx) {
c.OK(gb.JSON{
"id": c.Param("id"),
"message": "User updated",
})
})app.DELETE("/users/:id", func(c *gb.Ctx) {
c.OK(gb.JSON{
"message": "User deleted",
})
})Route parameters make it easy to capture values directly from the URL.
app.GET("/users/:id", func(c *gb.Ctx) {
c.OK(gb.JSON{
"id": c.Param("id"),
})
})Request:
GET /users/42
Response:
{
"id": "42"
}
Middleware allows you to intercept requests before they reach your route handlers. Call c.Next() to continue the chain.
Global middleware:
app.Use(middleware.AllowAllCORS())Custom middleware:
app.Use(func(c *gb.Ctx) {
log.Println(c.Method(), c.Path())
c.Next()
})Organize related endpoints into reusable routers and mount them under a common prefix.
api := gb.NewRouter()
api.GET("/users", func(c *gb.Ctx) {
c.OK(gb.JSON{
"users": []string{
"Alice",
"Bob",
},
})
})
app.Mount("/api", api)Routes become:
GET /api/users
Router middleware:
api.Use(func(c *gb.Ctx) {
token := c.Header("Authorization")
if token == "" {
c.Unauthorized(gb.JSON{
"error": "Missing authorization header",
})
return
}
c.Next()
})Gorbit includes configurable CORS middleware for local development and production deployments.
Allow everything:
app.Use(middleware.AllowAllCORS())Custom configuration:
app.Use(middleware.CORS(
middleware.CORSOptions{
AllowOrigins: []string{
"http://localhost:5173",
},
AllowMethods: []string{
"GET",
"POST",
},
AllowHeaders: []string{
"Authorization",
"Content-Type",
},
AllowCredentials: true,
MaxAge: 3600,
},
))Automatically decode JSON request bodies into Go structs.
type LoginRequest struct {
Username string `json:"username"`
Password string `json:"password"`
}
app.POST("/login", func(c *gb.Ctx) {
var body LoginRequest
if err := c.BindJSON(&body); err != nil {
c.BadRequest(gb.JSON{
"error": "Invalid JSON",
})
return
}
c.OK(body)
})Read and write HTTP cookies using built-in helper methods.
c.SetCookieValue("token", token, gb.CookieOptions{
HttpOnly: true,
MaxAge: 3600,
})
token, err := c.Cookie("token")
if err != nil {
c.Unauthorized(gb.JSON{
"error": "Token missing",
})
return
}Handle multipart form uploads with a simple API.
file, err := c.FormFile("image")
if err != nil {
c.BadRequest(gb.JSON{
"error": "No file uploaded",
})
return
}
if err := file.SaveTo("./uploads/" + file.Filename); err != nil {
c.InternalServerError(gb.JSON{
"error": "Failed to save file",
})
return
}
c.OK(gb.JSON{
"filename": file.Filename,
})Use built-in response helpers to return common HTTP responses.
c.OK(gb.JSON{
"message": "Success",
})
c.Created(gb.JSON{
"id": 42,
})
c.BadRequest(gb.JSON{
"error": "Invalid request",
})
c.NotFound(gb.JSON{
"error": "Resource not found",
})
c.InternalServerError(gb.JSON{
"error": "Something went wrong",
})Serve files from a local directory with a single line.
app.Static("/public", "./public")A request to /public/logo.png will serve ./public/logo.png.
Create event-driven WebSocket servers using Gorbit's built-in WebSocket manager.
app.WS.Handle("/chat", func(client *gb.WSClient) {
client.OnConnect(func(c *gb.WSClient) {
println("Connected")
})
client.On("message", func(c *gb.WSClient, data json.RawMessage) {
c.Emit("message", gb.JSON{
"text": "Hello from Gorbit!",
})
})
client.OnConnect(func(c *gb.WSClient) {
c.Join("general")
})
})my-api/
├── main.go
├── go.mod
├── controllers/
├── middleware/
├── routes/
│ ├── auth.go
│ ├── users.go
│ └── posts.go
├── services/
├── models/
└── utils/
Looking for more?
| Resource | Description |
|---|---|
| 📚 Documentation | https://gorbit.dev/docs |
| 📖 Go Reference | https://pkg.go.dev/github.com/pav-studio/gorbit |
| 💻 GitHub | https://github.com/pav-studio/gorbit |
The examples/ directory contains complete applications demonstrating common Gorbit use cases.
| Example | Description |
|---|---|
| quickstart | Basic HTTP server |
| rest-api | RESTful API with routers and middleware |
| websocket-chat | Event-driven WebSocket server |
| file-upload | Multipart file uploads |
Contributions are welcome.
- Fork the repository.
- Create a feature branch.
- Commit your changes.
- Open a Pull Request.
This project is licensed under the MIT License.