aero

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2017 License: MIT Imports: 5 Imported by: 0

README

aero Go Report Card

Aero is tiny Express-inspired router for golang.

Install

You need go version 1.7++

go get github.com/aldidana/aero

Example

package main

import (
	"fmt"
	"github.com/aldidana/aero"
	"net/http"
)

func main() {
	router := aero.Router()

	router.Get("/", func(res http.ResponseWriter, req *http.Request) {
		res.Write([]byte("Index Page"))
	})

	// Using params
	// This handler will match /hello/bingo but it will not match /hello/ and /hello
	router.Get("/hello/:name", helloHandler)

	http.ListenAndServe(":5678", router)
}

func helloHandler(res http.ResponseWriter, req *http.Request) {
	name := req.Context().Value("name")

	fmt.Fprintf(res, "Hello %v\n", name)
}

TODO

  • Testing
  • Group several routes
  • Maybe route logging 🍻

License

MIT @Aldi Priya Perdana

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aero

type Aero struct {
	NotFound http.HandlerFunc
	// contains filtered or unexported fields
}

Aero is a router handler

func Router

func Router() *Aero

Router is initialized router

func (*Aero) Delete

func (aero *Aero) Delete(path string, handlers ...http.HandlerFunc)

Delete is to add a new DELETE route to the router

func (*Aero) Get

func (aero *Aero) Get(path string, handlers ...http.HandlerFunc)

Get is to add a new GET route to the router

func (*Aero) Head

func (aero *Aero) Head(path string, handlers ...http.HandlerFunc)

Head is to add a new HEAD route to the router

func (*Aero) Options

func (aero *Aero) Options(path string, handlers ...http.HandlerFunc)

Options is to add a new OPTIONS route to the router

func (*Aero) Patch

func (aero *Aero) Patch(path string, handlers ...http.HandlerFunc)

Patch is to add a new PATCH route to the router

func (*Aero) Post

func (aero *Aero) Post(path string, handlers ...http.HandlerFunc)

Post is to add a new POST route to the router

func (*Aero) Put

func (aero *Aero) Put(path string, handlers ...http.HandlerFunc)

Put is to add a new PUT route to the router

func (*Aero) ServeHTTP

func (aero *Aero) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP is to implements `http.Handler` interface for this router to serves HTTP requests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL