Documentation
¶
Overview ¶
Package framework is what the router of one HTTP framework needs from the generator, and what every framework shares.
Index ¶
- Variables
- func Brace(path string, name, wildcard func(string) string) (string, error)
- func Check(path string) error
- func CheckClean(p string) error
- func CheckMethod(method string) error
- func ConflictsByKey(routes []Route, key func(Route) string) ([]Route, []Conflict)
- func ConflictsByShape(routes []Route) ([]Route, []Conflict)
- func Escaping(special string) func(string) (string, error)
- func EscapingColon(s string) (string, error)
- func Identifier(name string) string
- func Params(path string) []string
- func Rejecting(special string) func(string) (string, error)
- func Rename(path string, name func(string) string) (string, []string, error)
- func RestName(taken []string) string
- func Same(name string) string
- func Shape(pattern string) string
- func Unmarked(name string) string
- type Colon
- type Conflict
- type Framework
- type Handler
- type Route
Constants ¶
This section is empty.
Variables ¶
var ( ErrPattern = errors.New("the router rejects the path") ErrMethod = errors.New("the router does not take the method") )
Functions ¶
func Brace ¶
Brace writes path for a router that takes {name} too, with names and a trailing /* as given.
func Check ¶
Check fails on what no router takes: a path without a leading slash, a { without its } and a * that is not last.
func CheckClean ¶
CheckClean fails on a path that is not clean, such as /a//b; a trailing slash is clean.
func CheckMethod ¶
CheckMethod fails on a method a router with one function per method has none for, such as QUERY or one a spec adds on its own.
func ConflictsByKey ¶
ConflictsByKey drops every route that has the key of an earlier one, with the reason. Routes of one key match the same requests on the router, so the later one would replace or shadow the earlier one without a word.
func ConflictsByShape ¶
ConflictsByShape drops every route that has the method and the shape of an earlier one's path: a repeat of it, or one whose path parameters are named otherwise. It serves routers that key parameters by position and let a later route replace an earlier one.
func Escaping ¶
Escaping writes a literal with each of the characters in special escaped by a backslash, as routers that read them as the start of a parameter take a literal one.
func EscapingColon ¶
EscapingColon escapes the colons of a literal, and fails on a leading colon or a star.
func Identifier ¶
Identifier is name as a router that takes Go identifiers holds it: any other character becomes an underscore, and a leading digit gets one in front.
func Rejecting ¶
Rejecting writes a literal as it is, or fails when it holds one of the characters in special, which the router reads as the start of a parameter and cannot escape.
func Rename ¶
Rename writes each {name} of path as name gives it; a missing, repeated or merged name fails.
func RestName ¶
RestName names the value a trailing * takes the rest of the path into: rest, with an underscore added for as long as a parameter of the path has the name.
Types ¶
type Colon ¶
type Colon struct {
Literal func(s string) (string, error)
Name func(name string) string
Wildcard string
IsWildcardNamed bool
IsPrefixAllowed bool
}
Colon writes routes for a router that takes parameters as :name, running to the end of their segment. Literal writes a literal piece of the path, or fails for one the router cannot hold; Name writes the name of a parameter; Wildcard is what a trailing /* becomes. A parameter may follow a literal prefix in its segment when IsPrefixAllowed is set. IsWildcardNamed adds a free name to the wildcard.
func (Colon) Pattern ¶
Pattern writes path as the router takes it. Besides what Check fails on, it fails on a parameter with a suffix or one that shares its segment with another, a parameter with a prefix unless IsPrefixAllowed, a parameter without a name or named twice, a * that is not a segment of its own, and a literal Literal rejects. It also fails on two names Name makes one.
type Framework ¶
type Framework interface {
Name() string
Imports() []gomodel.Import
// RoutePattern writes an operation's method and OpenAPI path as the router takes them, or
// fails for a method or a path the router rejects.
RoutePattern(method, path string) (string, error)
// Conflicts drops every route the router cannot hold next to an earlier one, with the reason.
Conflicts(routes []Route) ([]Route, []Conflict)
// Handler is the shape of the adapter's handlers, with the framework's types written as the
// file of s spells them.
Handler(s *gocode.Scope) Handler
// PathParam writes the expression that reads a path parameter in a handler, where r is the
// request and c the framework's context, when the handler has one.
PathParam(s *gocode.Scope, name string) string
// Templates holds templates/router.tmpl, the template of the router part.
Templates() fs.FS
}
Framework is one HTTP framework a router is generated for.
type Handler ¶
type Handler struct {
Signature string
Writer string
Request string
Epilogue string
ServeSignature string
Context string
ContextServeSignature string
}
Handler is the shape of the handlers the adapter gives a framework. Signature follows the handler's name: its parameters, and its result when it has one. Writer and Request are the response writer and the request the handler has; Epilogue is the statement that ends it, empty when it needs none. ServeSignature is the shape of the method that serves an operation inside the operation middleware, which takes w and r. Context is the framework's context, when the handler has one; ContextServeSignature then takes it before w and r, for an operation that reads its path parameters from it.
func ContextHandler ¶
ContextHandler is the shape of a handler that takes the router's context and returns nil.
func HTTPHandler ¶
HTTPHandler is the handler shape of an http.HandlerFunc.
type Route ¶
Route is one operation on the router. Pattern is the route as the framework writes it. Names, when set, name its path values in the order the router holds them.
func StaticFirst ¶
StaticFirst orders routes for a router that takes the first route that matches: at each segment a literal comes before a parameter and a parameter before a wildcard, and routes that tie keep their order, so no route shadows a more specific one after it. A parameter next to a literal comes before one alone, the longer literal first.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package beego is the router for github.com/beego/beego/v2.
|
Package beego is the router for github.com/beego/beego/v2. |
|
Package chi is the router for github.com/go-chi/chi.
|
Package chi is the router for github.com/go-chi/chi. |
|
Package echo is the router for github.com/labstack/echo, whose handlers take an echo.Context and return an error.
|
Package echo is the router for github.com/labstack/echo, whose handlers take an echo.Context and return an error. |
|
Package echov5 is the router for github.com/labstack/echo/v5, whose handlers take an *echo.Context and return an error.
|
Package echov5 is the router for github.com/labstack/echo/v5, whose handlers take an *echo.Context and return an error. |
|
Package fasthttp is the router for github.com/fasthttp/router over github.com/valyala/fasthttp.
|
Package fasthttp is the router for github.com/fasthttp/router over github.com/valyala/fasthttp. |
|
Package fiber is the router for github.com/gofiber/fiber/v3.
|
Package fiber is the router for github.com/gofiber/fiber/v3. |
|
Package gin is the router for github.com/gin-gonic/gin.
|
Package gin is the router for github.com/gin-gonic/gin. |
|
Package goframe is the router for github.com/gogf/gf/v2.
|
Package goframe is the router for github.com/gogf/gf/v2. |
|
Package gorillamux is the router for github.com/gorilla/mux.
|
Package gorillamux is the router for github.com/gorilla/mux. |
|
Package gozero is the router for the rest package of github.com/zeromicro/go-zero: the router of its rest server, which rest.WithRouter gives one.
|
Package gozero is the router for the rest package of github.com/zeromicro/go-zero: the router of its rest server, which rest.WithRouter gives one. |
|
Package hertz is the router for github.com/cloudwego/hertz.
|
Package hertz is the router for github.com/cloudwego/hertz. |
|
Package iris is the router for github.com/kataras/iris/v12.
|
Package iris is the router for github.com/kataras/iris/v12. |
|
Package kratos is the router for the HTTP transport of github.com/go-kratos/kratos/v2, whose handlers take a kratos Context and return an error.
|
Package kratos is the router for the HTTP transport of github.com/go-kratos/kratos/v2, whose handlers take a kratos Context and return an error. |
|
Package stdhttp is the router for http.ServeMux of the standard library, with its method and wildcard patterns.
|
Package stdhttp is the router for http.ServeMux of the standard library, with its method and wildcard patterns. |