mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 02:31:04 +01:00
apps.Switch/Hosts minor doc improvement
This commit is contained in:
parent
f29d690c5f
commit
4cbd9deff7
|
@ -121,9 +121,9 @@ Example Code:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
switcher := Switch(Hosts{
|
switcher := Switch(Hosts{
|
||||||
"mydomain.com": app,
|
{Pattern: "mydomain.com", Target: app},
|
||||||
"test.mydomain.com": testSubdomainApp,
|
{Pattern: "test.mydomain.com", Target: testSubdomainApp},
|
||||||
"otherdomain.com": "appName",
|
{Pattern: "otherdomain.com", Target: "appName"},
|
||||||
})
|
})
|
||||||
switcher.Listen(":80")
|
switcher.Listen(":80")
|
||||||
```
|
```
|
||||||
|
@ -211,7 +211,7 @@ Switch(Join{
|
||||||
App: myapp,
|
App: myapp,
|
||||||
},
|
},
|
||||||
Hosts{
|
Hosts{
|
||||||
{"^test.*$", myapp},
|
{Pattern: "^test.*$", Target: myapp},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
|
@ -15,9 +15,9 @@ import (
|
||||||
// Example Code:
|
// Example Code:
|
||||||
//
|
//
|
||||||
// switcher := Switch(Hosts{
|
// switcher := Switch(Hosts{
|
||||||
// "mydomain.com": app,
|
// { Pattern: "mydomain.com", Target: app },
|
||||||
// "test.mydomain.com": testSubdomainApp,
|
// { Pattern: "test.mydomain.com", Target: testSubdomainApp },
|
||||||
// "otherdomain.com": "appName",
|
// { Pattern: "otherdomain.com", "Target: appName" },
|
||||||
// })
|
// })
|
||||||
// switcher.Listen(":80")
|
// switcher.Listen(":80")
|
||||||
//
|
//
|
||||||
|
@ -35,6 +35,28 @@ import (
|
||||||
//
|
//
|
||||||
// Wrap with the `Join` slice to pass
|
// Wrap with the `Join` slice to pass
|
||||||
// more than one provider at the same time.
|
// more than one provider at the same time.
|
||||||
|
//
|
||||||
|
// An alternative way for manually embedding an Iris Application to another one is:
|
||||||
|
//
|
||||||
|
// app := iris.New() // root app.
|
||||||
|
// myOtherApp := api.NewServer(otherServerConfiguration) // embedded app.
|
||||||
|
// // myOtherApp.Logger().SetLevel("debug")
|
||||||
|
//
|
||||||
|
// if err := myOtherApp.Build(); err != nil {
|
||||||
|
// panic(err)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// app.Any("/api/identity/{p:path}", func(ctx iris.Context) {
|
||||||
|
// apiPath := "/" + ctx.Params().Get("p")
|
||||||
|
// r := ctx.Request()
|
||||||
|
// r.URL.Path = apiPath
|
||||||
|
// r.URL.RawPath = apiPath
|
||||||
|
// ctx.Params().Remove("p")
|
||||||
|
//
|
||||||
|
// myOtherApp.ServeHTTPC(ctx)
|
||||||
|
// })
|
||||||
|
//
|
||||||
|
// app.Listen(":80")
|
||||||
func Switch(provider SwitchProvider, options ...SwitchOption) *iris.Application {
|
func Switch(provider SwitchProvider, options ...SwitchOption) *iris.Application {
|
||||||
cases := provider.GetSwitchCases()
|
cases := provider.GetSwitchCases()
|
||||||
if len(cases) == 0 {
|
if len(cases) == 0 {
|
||||||
|
|
|
@ -36,6 +36,22 @@ type (
|
||||||
|
|
||||||
var _ SwitchProvider = Hosts{}
|
var _ SwitchProvider = Hosts{}
|
||||||
|
|
||||||
|
// AnyDomain is a regexp that matches any domain.
|
||||||
|
// It can be used as the Pattern field of a Host.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// apps.Switch(apps.Hosts{
|
||||||
|
// {
|
||||||
|
// Pattern: "^id.*$", Target: identityApp,
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// Pattern: apps.AnyDomain, Target: app,
|
||||||
|
// },
|
||||||
|
// }).Listen(":80")
|
||||||
|
const AnyDomain = `^(([a-zA-Z]{1})|([a-zA-Z]{1}[a-zA-Z]{1})|([a-zA-Z]{1}[0-9]{1})|([0-9]{1}[a-zA-Z]{1})|([a-zA-Z0-9][a-zA-Z0-9-_]{1,61}[a-zA-Z0-9]))\.([a-zA-Z]{2,6}|[a-zA-Z0-9-]{2,30}\.[a-zA-Z
|
||||||
|
]{2,3})$`
|
||||||
|
|
||||||
// GetSwitchCases completes the SwitchProvider.
|
// GetSwitchCases completes the SwitchProvider.
|
||||||
// It returns a slice of SwitchCase which
|
// It returns a slice of SwitchCase which
|
||||||
// if passed on `Switch` function, they act
|
// if passed on `Switch` function, they act
|
||||||
|
|
Loading…
Reference in New Issue
Block a user