README
¶
🦌 ALF (API Like Flutter) Router
🔴 This library is actually well tested but the API may change with the time introducing breaking changes
Description
👉 This is a micro-framework / router built on ⬆ top of the fasthttp package. Alf relies on scalability and his simple structure wich is similar to Flutter projects 📴
✨ Inspired by Flutter & Fiber
Purpouse
👷♂️ Make a router to start faster and simpler my backend projects
📖 Learn
- Explore the fasthttp package ⏭
- Publish my own package 📦
- Learn more deeply how a web server works 🌐
Technologies used 📘
- Go (Golang)
Core External Packages 📦:
Features :
- Fast Router 💨
- Concurrent Route Setup ⌚
- Send JSON Responses (docs)
- HTML/Go Templates Out of the BOX ✨ (docs)
- Plugins 🧩 :
- Generate Types for TS (tygo pkg) (docs)
Docs
Prerequisites 📌
Set up your first project 💻
Download the package ⬇
go get github.com/PiterWeb/Alf-Router
Import it into your code 🔠
import (
alf "github.com/PiterWeb/Alf-Router"
)
Write this simple structure
err := alf.App(&alf.AppConfig{
Port: "3000",
Routes: alf.CreateRouter([]alf.Route{
{
Path: "/",
Handle: func(ctx *alf.Ctx) error {
_, err := ctx.WriteString("Hello World")
return err
},
Method: "get",
},
}),
})
if err != nil {
panic(err)
}
Now you have setup 🔨 an index route
Documentation
¶
Index ¶
Constants ¶
View Source
const ( GET method = "GET" POST method = "POST" DELETE method = "DELETE" PUT method = "PUT" PATCH method = "PATCH" HEAD method = "HEAD" OPTIONS method = "OPTIONS" )
Variables ¶
This section is empty.
Functions ¶
func CreateRouter ¶
func CreateRouter(r []Route) methodRoutes
Types ¶
type AppConfig ¶
type AppConfig struct {
Routes methodRoutes // routes of the app
Middleware []Middleware // global middlewares
Headers []Header // global headers
Port string // port of the app | default value '8080'
NotFound func(ctx *Ctx) // func that handles NotFound requests
ServeStatic bool // if true, the app will serve static files on "/static"
Plugins []Plugin // structs that implements the Plugin interface and runs Init_plugin() before starting the server
}
type Ctx ¶
type Ctx = fasthttp.RequestCtx // alias for Ctx
type Middleware ¶
type Route ¶
type Route struct {
Path string // path
Method method // method (only one)
Handle func(ctx *Ctx) error // func that handles the route
Children []Route // children of the route (if the route isnt the root route) [all childrens inherit parents Middlewares and Headers ]
Error func(ctx *Ctx, err error) // func that handles errors of the route (if err returned on handle method will be invoked with the error in the parameters)
Middleware []Middleware // middlewares of the route
Headers []Header // headers
}
Click to show internal directories.
Click to hide internal directories.