mirror of
https://github.com/kataras/iris.git
synced 2025-12-22 20:37:05 +00:00
Add context.FindClosest(n) to find closest paths - useful for 404 pages to suggest valid pages
Former-commit-id: 90ff7c9da5369df5bd99fbbecf9955a8c555fea5
This commit is contained in:
@@ -310,6 +310,12 @@ type Context interface {
|
||||
// Subdomain returns the subdomain of this request, if any.
|
||||
// Note that this is a fast method which does not cover all cases.
|
||||
Subdomain() (subdomain string)
|
||||
// FindClosest returns a list of "n" paths close to
|
||||
// this request based on subdomain and request path.
|
||||
//
|
||||
// Order may change.
|
||||
// Example: https://github.com/kataras/iris/tree/master/_examples/routing/not-found-suggests
|
||||
FindClosest(n int) []string
|
||||
// IsWWW returns true if the current subdomain (if any) is www.
|
||||
IsWWW() bool
|
||||
// FullRqeuestURI returns the full URI,
|
||||
@@ -1600,6 +1606,15 @@ func (ctx *context) Subdomain() (subdomain string) {
|
||||
return
|
||||
}
|
||||
|
||||
// FindClosest returns a list of "n" paths close to
|
||||
// this request based on subdomain and request path.
|
||||
//
|
||||
// Order may change.
|
||||
// Example: https://github.com/kataras/iris/tree/master/_examples/routing/not-found-suggests
|
||||
func (ctx *context) FindClosest(n int) []string {
|
||||
return ctx.Application().FindClosestPaths(ctx.Subdomain(), ctx.Path(), n)
|
||||
}
|
||||
|
||||
// IsWWW returns true if the current subdomain (if any) is www.
|
||||
func (ctx *context) IsWWW() bool {
|
||||
host := ctx.Host()
|
||||
|
||||
Reference in New Issue
Block a user