Feather is a lightweight modular HTTP framework for Go. It offers simple routing (static, dynamic, regex), global middleware, and a unified context for fast, extensible API and web app development.
- Go 100%
| middlewares | fix: Properly create Logger | |
| playground | Fixed a little typo for dynamic routing | |
| .gitignore | Initial commit | |
| context.go | Fixed some bugs and added proper Logger | |
| feather.go | fix: Properly create Logger | |
| go.mod | Fixed some bugs and added proper Logger | |
| go.sum | Added support for FS, HTTPS connection and two new middlewares, recover and requestId | |
| helper.go | Fixed bug with logger | |
| LICENSE | Create LICENSE | |
| README.md | Fixed typo in README | |
| test.txt | Added dynamic routing with regex and revised the way routes are stocked | |
Feather
Feather is a lightweight, modular HTTP web framework for Go, designed for rapid development of RESTful APIs and web applications. It provides a simple routing system, middleware support, and convenient helpers for handling requests and responses.
Features
- Routing: Register routes with static and dynamic segments, including custom regex for parameters.
- Middleware: Add global middleware functions for logging, CORS, authentication, etc.
- Context: Unified request/response context with helpers for JSON, HTML, files, headers, cookies, and more.
- Extensible: Easily add custom middlewares and handlers.
- Minimal Dependencies: Built on Go's standard library.
Getting Started
Installation
Add Feather to your Go project:
go get codeberg.org/esmyx/feather
Basic Usage
packagemainimport("codeberg.org/esmyx/feather""codeberg.org/esmyx/feather/middlewares")funcmain(){server:=feather.NewServer()// Add logging and CORS middlewareserver.AddMiddleware(middlewares.Logging(),middlewares.CORS([]string{"*"},[]string{"GET","POST","PUT","DELETE"},[]string{"Content-Type"},),)// Define routesserver.GET("/",func(c*feather.Context){c.String(200,"Welcome to Feather!")})server.GET("/user/:id|[0-9]+",func(c*feather.Context){userID:=c.Params["id"]c.JSON(200,map[string]string{"user_id":userID})})// Start serverserver.Listen(":8080")}Routing
- Static routes:
/about - Dynamic routes:
/user/:id - Dynamic with regex:
/post/:slug|[a-z0-9\-]+ - Wildcard:
/files/*path
Middleware
Middlewares are functions that run before the route handler. Use AddMiddleware to register them globally.
Example: Logging and CORS are included in middlewares/.
Context Helpers
c.JSON(status, obj)– Send JSON responsec.String(status, text)– Send plain textc.HTML(status, html)– Send HTMLc.File(status, path)– Send filec.Status(status)– Send status code onlyc.Redirect(status, url)– Redirectc.SetHeader(key, value)– Set response headerc.SetCookie(cookie)– Set cookiec.Query(key)– Get query paramc.JSONBody(v)– Parse JSON bodyc.FormValue(key)– Get form value
License
GNU General Public License v3.0