Categorygithub.com/jspc/routes
modulepackage
1.0.0
Repository: https://github.com/jspc/routes.git
Documentation: pkg.go.dev

# README

GoDoc Go Report Card CircleCI Codecov Code Climate maintainability

routes

import "github.com/jspc/routes"

Overview

Package routes is a small, no-frills routing library for fasthttp. It's designed to sit within a fasthttp aware service to determine which route, from a map, to direct a ctx at.

It is designed:

  1. To contain no third party module (beyond fasthttp)

  2. To be as unobtrusive as possible

Index

Examples

Package files

doc.go routes.go

type Routes

type Routes struct {
    Routes  map[string]fasthttp.RequestHandler
    Catcher fasthttp.RequestHandler
}

Routes represents the fasthttp aware routes and configuration that determine which route to choose

func New

func New() *Routes

New is a friendly, convenience function for returning an instance of routes.Routes that can be used in client code

func (*Routes) Add

func (r *Routes) Add(pattern string, f fasthttp.RequestHandler)

Add takes a pattern, a function, and adds them to its self so requests can be routed correctly.

A pattern can be a full url, or can use parameters. Params in URLs look like:

/users/:user/address

This would match on:

/users/12345/address

(For instance)

Add() does no checking for existing routes; it is the responsibility of the developer to ensure there are no duplicates. The last function assigned to a patter will be used.

func (Routes) Route

func (r Routes) Route(ctx *fasthttp.RequestCtx)

Route will send a fasthttp request to the correct function based on the path in the request. Parameters, as defined in a route, are accessed by ctx.userValue(param)


Generated by godoc2md

# Functions

New is a friendly, convenience function for returning an instance of routes.Routes that can be used in client code.

# Structs

Routes represents the fasthttp aware routes and configuration that determine which route to choose.