routesinfo

package
v3.0.0-beta+incompatible Latest Latest
Warning

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

Go to latest
Published: May 30, 2016 License: Apache-2.0 Imports: 4 Imported by: 0

README

RoutesInfo plugin

This plugin collects & stores all registered routes and gives information about them.

The RouteInfo

type RouteInfo struct {
	Method     string
	Domain     string
	Path       string
	RegistedAt time.Time
}

How to use


package main

import (
	"github.com/kataras/iris"
	"github.com/kataras/iris/plugin/routesinfo"
)

func main() {

	info := routesinfo.New()
	iris.Plugins().Add(info)

	iris.Get("/yourpath", func(c *iris.Context) {
		c.Write("yourpath")
	})

	iris.Post("/otherpostpath", func(c *iris.Context) {
		c.Write("other post path")
	})

	all := info.All()
	// allget := info.ByMethod("GET") -> slice
	// alllocalhost := info.ByDomain("localhost") -> slice
	// bypath:= info.ByPath("/yourpath") -> slice
	// bydomainandmethod:= info.ByDomainAndMethod("localhost","GET") -> slice
	// bymethodandpath:= info.ByMethodAndPath("GET","/yourpath") -> single (it could be slice for all domains too but it's not)

	println("The first registed route was: ", all[0].Path, "registed at: ", all[0].RegistedAt.String())
	println("All routes info:")
	for i:= range all {
		println(all[i].String())
		//outputs->
		// Domain: localhost Method: GET Path: /yourpath RegistedAt: 2016/03/27 15:27:05:029 ...
		// Domain: localhost Method: POST Path: /otherpostpath RegistedAt: 2016/03/27 15:27:05:030 ...
	}
	iris.Listen(":8080")

}


Documentation

Index

Constants

View Source
const Name = "RoutesInfo"

Name the name of the plugin, is "RoutesInfo"

Variables

This section is empty.

Functions

This section is empty.

Types

type Plugin

type Plugin struct {
	// contains filtered or unexported fields
}

Plugin the routes info plugin, holds the routes as RouteInfo objects

func New

func New() *Plugin

New returns the Plugin, same as RoutesInfo()

func RoutesInfo

func RoutesInfo() *Plugin

RoutesInfo returns the Plugin, same as New()

func (Plugin) All

func (r Plugin) All() []RouteInfo

All returns all routeinfos returns a slice

func (Plugin) ByDomain

func (r Plugin) ByDomain(domain string) []RouteInfo

ByDomain returns all routeinfos which registed to a specific domain returns a slice, if nothing founds this slice has 0 len&cap

func (Plugin) ByDomainAndMethod

func (r Plugin) ByDomainAndMethod(domain string, method string) []RouteInfo

ByDomainAndMethod returns all routeinfos registed to a specific domain and has specific http method returns a slice, if nothing founds this slice has 0 len&cap

func (Plugin) ByMethod

func (r Plugin) ByMethod(method string) []RouteInfo

ByMethod returns all routeinfos by a http method returns a slice, if nothing founds this slice has 0 len&cap

func (Plugin) ByMethodAndPath

func (r Plugin) ByMethodAndPath(method string, path string) *RouteInfo

ByMethodAndPath returns a single *RouteInfo which has specific http method and path returns only the first match if nothing founds returns nil

func (Plugin) ByPath

func (r Plugin) ByPath(path string) []RouteInfo

ByPath returns all routeinfos by a path maybe one path is the same on GET and POST ( for example /login GET, /login POST) because of that it returns a slice and not only one RouteInfo returns a slice, if nothing founds this slice has 0 len&cap

func (Plugin) GetDescription

func (r Plugin) GetDescription() string

GetDescription RoutesInfo gives information about the registed routes

func (Plugin) GetName

func (r Plugin) GetName() string

GetName ...

func (*Plugin) PostHandle

func (r *Plugin) PostHandle(route iris.IRoute)

PostHandle collect the registed routes information

type RouteInfo

type RouteInfo struct {
	Method     string
	Domain     string
	Path       string
	RegistedAt time.Time
}

RouteInfo holds the method, domain, path and registered time of a route

func (RouteInfo) String

func (ri RouteInfo) String() string

String returns the string presentation of the Route(Info)

Jump to

Keyboard shortcuts

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