mirror of
https://github.com/kataras/iris.git
synced 2026-01-23 20:05:59 +00:00
8.4.0 | New MVC Features | Refactor examples and godoc for go 1.9 use. Read HISTORY.md.
Former-commit-id: 90c05e743052bc3722e7fefaa0cbb0ed5153a1fb
This commit is contained in:
@@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/context"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -17,18 +16,18 @@ func main() {
|
||||
|
||||
dashboard := app.Party("dashboard.")
|
||||
{
|
||||
dashboard.Get("/", func(ctx context.Context) {
|
||||
dashboard.Get("/", func(ctx iris.Context) {
|
||||
ctx.Writef("HEY FROM dashboard")
|
||||
})
|
||||
}
|
||||
system := app.Party("system.")
|
||||
{
|
||||
system.Get("/", func(ctx context.Context) {
|
||||
system.Get("/", func(ctx iris.Context) {
|
||||
ctx.Writef("HEY FROM system")
|
||||
})
|
||||
}
|
||||
|
||||
app.Get("/", func(ctx context.Context) {
|
||||
app.Get("/", func(ctx iris.Context) {
|
||||
ctx.Writef("HEY FROM frontend /")
|
||||
})
|
||||
// http://domain.local:80
|
||||
|
||||
@@ -3,7 +3,6 @@ package main
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/context"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -15,26 +14,26 @@ func main() {
|
||||
admin := app.Party("admin.")
|
||||
{
|
||||
// admin.mydomain.com
|
||||
admin.Get("/", func(c context.Context) {
|
||||
admin.Get("/", func(c iris.Context) {
|
||||
c.Writef("INDEX FROM admin.mydomain.com")
|
||||
})
|
||||
// admin.mydomain.com/hey
|
||||
admin.Get("/hey", func(c context.Context) {
|
||||
admin.Get("/hey", func(c iris.Context) {
|
||||
c.Writef("HEY FROM admin.mydomain.com/hey")
|
||||
})
|
||||
// admin.mydomain.com/hey2
|
||||
admin.Get("/hey2", func(c context.Context) {
|
||||
admin.Get("/hey2", func(c iris.Context) {
|
||||
c.Writef("HEY SECOND FROM admin.mydomain.com/hey")
|
||||
})
|
||||
}
|
||||
|
||||
// mydomain.com/
|
||||
app.Get("/", func(c context.Context) {
|
||||
app.Get("/", func(c iris.Context) {
|
||||
c.Writef("INDEX FROM no-subdomain hey")
|
||||
})
|
||||
|
||||
// mydomain.com/hey
|
||||
app.Get("/hey", func(c context.Context) {
|
||||
app.Get("/hey", func(c iris.Context) {
|
||||
c.Writef("HEY FROM no-subdomain hey")
|
||||
})
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ package main
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/context"
|
||||
)
|
||||
|
||||
// register a dynamic-wildcard subdomain to your server machine(dns/...) first, check ./hosts if you use windows.
|
||||
@@ -20,15 +19,15 @@ func main() {
|
||||
admin := app.Party("admin.")
|
||||
{
|
||||
// admin.mydomain.com
|
||||
admin.Get("/", func(ctx context.Context) {
|
||||
admin.Get("/", func(ctx iris.Context) {
|
||||
ctx.Writef("INDEX FROM admin.mydomain.com")
|
||||
})
|
||||
// admin.mydomain.com/hey
|
||||
admin.Get("/hey", func(ctx context.Context) {
|
||||
admin.Get("/hey", func(ctx iris.Context) {
|
||||
ctx.Writef("HEY FROM admin.mydomain.com/hey")
|
||||
})
|
||||
// admin.mydomain.com/hey2
|
||||
admin.Get("/hey2", func(ctx context.Context) {
|
||||
admin.Get("/hey2", func(ctx iris.Context) {
|
||||
ctx.Writef("HEY SECOND FROM admin.mydomain.com/hey")
|
||||
})
|
||||
}*/
|
||||
@@ -43,11 +42,11 @@ func main() {
|
||||
dynamicSubdomains.Get("/something/{paramfirst}", dynamicSubdomainHandlerWithParam)
|
||||
}
|
||||
|
||||
app.Get("/", func(ctx context.Context) {
|
||||
app.Get("/", func(ctx iris.Context) {
|
||||
ctx.Writef("Hello from mydomain.com path: %s", ctx.Path())
|
||||
})
|
||||
|
||||
app.Get("/hello", func(ctx context.Context) {
|
||||
app.Get("/hello", func(ctx iris.Context) {
|
||||
ctx.Writef("Hello from mydomain.com path: %s", ctx.Path())
|
||||
})
|
||||
|
||||
@@ -58,14 +57,14 @@ func main() {
|
||||
app.Run(iris.Addr("mydomain.com:8080")) // for beginners: look ../hosts file
|
||||
}
|
||||
|
||||
func dynamicSubdomainHandler(ctx context.Context) {
|
||||
func dynamicSubdomainHandler(ctx iris.Context) {
|
||||
username := ctx.Subdomain()
|
||||
ctx.Writef("Hello from dynamic subdomain path: %s, here you can handle the route for dynamic subdomains, handle the user: %s", ctx.Path(), username)
|
||||
// if http://username4.mydomain.com:8080/ prints:
|
||||
// Hello from dynamic subdomain path: /, here you can handle the route for dynamic subdomains, handle the user: username4
|
||||
}
|
||||
|
||||
func dynamicSubdomainHandlerWithParam(ctx context.Context) {
|
||||
func dynamicSubdomainHandlerWithParam(ctx iris.Context) {
|
||||
username := ctx.Subdomain()
|
||||
ctx.Writef("Hello from dynamic subdomain path: %s, here you can handle the route for dynamic subdomains, handle the user: %s", ctx.Path(), username)
|
||||
ctx.Writef("The paramfirst is: %s", ctx.Params().Get("paramfirst"))
|
||||
|
||||
@@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/context"
|
||||
)
|
||||
|
||||
func newApp() *iris.Application {
|
||||
@@ -53,7 +52,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func info(ctx context.Context) {
|
||||
func info(ctx iris.Context) {
|
||||
method := ctx.Method()
|
||||
subdomain := ctx.Subdomain()
|
||||
path := ctx.Path()
|
||||
|
||||
Reference in New Issue
Block a user