mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 10:41:03 +01:00
add the Context's helpers when working with subdomains
parent
806ad5e7aa
commit
aa12f0a009
|
@ -87,3 +87,31 @@ app.SubdomainRedirect(app, www)
|
||||||
```
|
```
|
||||||
|
|
||||||
The above will redirect all http(s)://mydomain.com/%anypath% to http(s)://www.mydomain.com/%anypath%.
|
The above will redirect all http(s)://mydomain.com/%anypath% to http(s)://www.mydomain.com/%anypath%.
|
||||||
|
|
||||||
|
The `Context` offers four main methods when working with subdomains that may be helpful for you.
|
||||||
|
|
||||||
|
```go
|
||||||
|
// Host returns the host part of the current url.
|
||||||
|
Host() string
|
||||||
|
// 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)
|
||||||
|
// IsWWW returns true if the current subdomain (if any) is www.
|
||||||
|
IsWWW() bool
|
||||||
|
// FullRqeuestURI returns the full URI,
|
||||||
|
// including the scheme, the host and the relative requested path/resource.
|
||||||
|
FullRequestURI() string
|
||||||
|
```
|
||||||
|
|
||||||
|
**Usage**
|
||||||
|
|
||||||
|
```go
|
||||||
|
func info(ctx iris.Context) {
|
||||||
|
method := ctx.Method()
|
||||||
|
subdomain := ctx.Subdomain()
|
||||||
|
path := ctx.Path()
|
||||||
|
|
||||||
|
ctx.Writef("\nInfo\n\n")
|
||||||
|
ctx.Writef("Method: %s\nSubdomain: %s\nPath: %s", method, subdomain, path)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
Loading…
Reference in New Issue
Block a user