route

package module
v0.0.0-...-73a7b9d Latest Latest
Warning

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

Go to latest
Published: May 2, 2019 License: MIT Imports: 1 Imported by: 2

README

Route

CircleCI

route manager

Installation

go get github.com/tomocy/route

Useage

Map routes

package route

import (
    // ...
)

func MapRoutes() {
    Web.Map(webRaw)
    API.Map(apiRaw)
}

var (
    Web = make(route.RouteMap)
    API = make(route.RouteMap)
)

var (
    webRaw = route.RawMap{
        "user.index": "http://localhost/users",
        "user.new": "http://localhost/users/new",
        "user.create": "http://localhost/users",
    }
    apiRaw = route.RawMap{
        "user.index": "http://localhost/api/users/index",
    }
)

(RouteMap).Route(string) returns *url.URL

http.HandlerFunc(route.Web.Route("user.new").Path, func(w http.ResponseWriter, r *http.Request) {
    // handle user.new
})
http.HandlerFunc(route.Web.Route("user.create").Path, {
    // handle user.create

    // after creating a user
    http.Redirect(w, r, route.Web.Route("user.index").String(), http.StatusSeeOther)
})

Author

tomocy

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RawMap

type RawMap map[string]string

type RouteMap

type RouteMap map[string]*url.URL

func (RouteMap) Map

func (m RouteMap) Map(rmap RawMap)

func (RouteMap) Route

func (m RouteMap) Route(name string) *url.URL

Jump to

Keyboard shortcuts

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