1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-20 19:37:03 +00:00
Former-commit-id: d8dd7c426dc9f14c870f103fef703595a2915612
This commit is contained in:
Gerasimos (Makis) Maropoulos
2018-01-20 05:17:31 +02:00
parent a4ff39df65
commit e176ff7b0c
15 changed files with 384 additions and 24 deletions

View File

@@ -11,25 +11,41 @@ func newApp() *iris.Application {
app.Get("/about", info)
app.Get("/contact", info)
usersAPI := app.Party("/api/users")
{
usersAPI.Get("/", info)
usersAPI.Get("/{id:int}", info)
app.PartyFunc("/api/users", func(r iris.Party) {
r.Get("/", info)
r.Get("/{id:int}", info)
usersAPI.Post("/", info)
r.Post("/", info)
usersAPI.Put("/{id:int}", info)
}
r.Put("/{id:int}", info)
}) /* <- same as:
usersAPI := app.Party("/api/users")
{ // those brackets are just syntactic-sugar things.
// This method is rarely used but you can make use of it when you want
// scoped variables to that code block only.
usersAPI.Get/Post...
}
usersAPI.Get/Post...
*/
www := app.Party("www.")
{
// get all routes that are registered so far, including all "Parties" but subdomains:
// http://www.mydomain.com/hi
www.Get("/hi", func(ctx iris.Context) {
ctx.Writef("hi from www.mydomain.com")
})
// Just to show how you can get all routes and copy them to another
// party or subdomain:
// Get all routes that are registered so far, including all "Parties" but subdomains:
currentRoutes := app.GetRoutes()
// register them to the www subdomain/vhost as well:
// Register them to the www subdomain/vhost as well:
for _, r := range currentRoutes {
www.Handle(r.Method, r.Path, r.Handlers...)
}
}
// See also the "subdomains/redirect" to register redirect router wrappers between subdomains,
// i.e mydomain.com to www.mydomain.com (like facebook does for SEO reasons(;)).
return app
}
@@ -43,6 +59,7 @@ func main() {
// http://mydomain.com/api/users/42
// http://www.mydomain.com
// http://www.mydomain.com/hi
// http://www.mydomain.com/about
// http://www.mydomain.com/contact
// http://www.mydomain.com/api/users