mirror of
https://github.com/kataras/iris.git
synced 2025-12-22 20:37:05 +00:00
Prepare for custom child router(s) via plugin(s) for tomorrow
This commit is contained in:
26
http.go
26
http.go
@@ -315,14 +315,19 @@ func (s *Server) Port() (port int) {
|
||||
return
|
||||
}
|
||||
|
||||
// FullHost returns the scheme+host
|
||||
func (s *Server) FullHost() string {
|
||||
// Scheme returns http:// or https:// if SSL is enabled
|
||||
func (s *Server) Scheme() string {
|
||||
scheme := "http://"
|
||||
// we need to be able to take that before(for testing &debugging) and after server's listen
|
||||
if s.IsSecure() || (s.Config.CertFile != "" && s.Config.KeyFile != "") {
|
||||
scheme = "https://"
|
||||
}
|
||||
return scheme + s.Host()
|
||||
return scheme
|
||||
}
|
||||
|
||||
// FullHost returns the scheme+host
|
||||
func (s *Server) FullHost() string {
|
||||
return s.Scheme() + s.Host()
|
||||
}
|
||||
|
||||
// Hostname returns the hostname part of the host (host expect port)
|
||||
@@ -850,7 +855,7 @@ func (e *muxEntry) add(path string, middleware Middleware) error {
|
||||
|
||||
if len(path) >= len(e.part) && e.part == path[:len(e.part)] {
|
||||
|
||||
if len(e.part) >= len(path) || path[len(e.part)] == '/' {
|
||||
if len(e.part) >= len(path) || path[len(e.part)] == slashByte {
|
||||
continue loop
|
||||
}
|
||||
}
|
||||
@@ -859,7 +864,7 @@ func (e *muxEntry) add(path string, middleware Middleware) error {
|
||||
|
||||
c := path[0]
|
||||
|
||||
if e.entryCase == hasParams && c == '/' && len(e.nodes) == 1 {
|
||||
if e.entryCase == hasParams && c == slashByte && len(e.nodes) == 1 {
|
||||
e = e.nodes[0]
|
||||
e.precedence++
|
||||
continue loop
|
||||
@@ -1148,6 +1153,8 @@ type (
|
||||
Method() string
|
||||
// Path returns the path
|
||||
Path() string
|
||||
// SetPath changes/sets the path for the Route
|
||||
SetPath(string)
|
||||
// Middleware returns the slice of Handler([]Handler) registed to this route
|
||||
Middleware() Middleware
|
||||
}
|
||||
@@ -1239,6 +1246,10 @@ func (r route) Path() string {
|
||||
return r.path
|
||||
}
|
||||
|
||||
func (r *route) SetPath(s string) {
|
||||
r.path = s
|
||||
}
|
||||
|
||||
func (r route) Middleware() Middleware {
|
||||
return r.middleware
|
||||
}
|
||||
@@ -1265,6 +1276,8 @@ type (
|
||||
tree *muxTree
|
||||
lookups []*route
|
||||
|
||||
onLookup func(Route)
|
||||
|
||||
api *muxAPI
|
||||
errorHandlers map[int]Handler
|
||||
logger *logger.Logger
|
||||
@@ -1360,6 +1373,9 @@ func (mux *serveMux) register(method []byte, subdomain string, path string, midd
|
||||
|
||||
// add to the lookups, it's just a collection of routes information
|
||||
lookup := newRoute(method, subdomain, path, middleware)
|
||||
if mux.onLookup != nil {
|
||||
mux.onLookup(lookup)
|
||||
}
|
||||
mux.lookups = append(mux.lookups, lookup)
|
||||
|
||||
return lookup
|
||||
|
||||
Reference in New Issue
Block a user