GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Why Go
  • Case Studies
  • Use Cases
  • Security
  • Learn
  • Effective Go
  • Go User Manual
  • Standard library
  • Release Notes
  • API
  • Packages
  • Recorded Talks
  • Meetups
  • Conferences

This view

  • Original page
  • New address

GeezerVison is showing pkg.go.dev — alf package - github.com/PiterWeb/Alf-Router - Go Packages

Details

  • checked Valid go.mod file

    The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.

  • checked Redistributable license

    Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.

  • unchecked Tagged version

    Modules with tagged versions give importers more predictable builds.

  • unchecked Stable version

    When a project reaches major version v1 it is considered stable.

  • Learn more about best practices

Repository

github.com/PiterWeb/Alf-Router

Links

  • Open Source Insights Logo Open Source Insights

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 📦:
  1. fasthttp (http ☁)
  2. ffjson (parse interfaces to json fast)
  3. pterm (show info, errors & warnings)

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 📌
  • Go 1.18
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
  • func App(config *AppConfig) error
  • func CreateRouter(r []Route) methodRoutes
  • type AppConfig
  • type Ctx
  • type Header
  • type Middleware
  • type Plugin
  • type Route

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 App ¶

func App(config *AppConfig) error

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 Header ¶

type Header struct {
	Name  string // name of the header
	Value string // value of the header
}

type Middleware ¶

type Middleware func(ctx *Ctx) bool // func that returns true if passed and false if an error ocurred

type Plugin ¶

type Plugin interface {
	Init_plugin(*AppConfig) error
}

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
}

Source Files ¶

View all Source files
  • core.go
  • headers.go
  • methods.go
  • middleware.go
  • routes.go
  • types.go

Directories ¶

Path Synopsis
errors
plugins
events
ts
utils
json
templates
Click to show internal directories.
Click to hide internal directories.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.