-
-
Notifications
You must be signed in to change notification settings - Fork 176
/
main.go
59 lines (47 loc) · 1.46 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/middleware/rewrite"
)
func main() {
app := newApp()
// http://mydomain.com -> http://www.mydomain.com
// http://mydomain.com/user -> http://www.mydomain.com/user
// http://mydomain.com/user/login -> http://www.mydomain.com/user/login
app.Listen(":80")
}
func newApp() *iris.Application {
app := iris.New()
app.Logger().SetLevel("debug")
static := app.Subdomain("static")
static.Get("/", staticIndex)
app.Get("/", index)
userRouter := app.Party("/user")
userRouter.Get("/", userGet)
userRouter.Get("/login", userGetLogin)
// redirects := rewrite.Load("redirects.yml")
// ^ see _examples/routing/rewrite example for that.
//
// Now let's do that by code.
rewriteEngine, _ := rewrite.New(rewrite.Options{
PrimarySubdomain: "www",
})
// Enable this line for debugging:
// rewriteEngine.SetLogger(app.Logger())
app.WrapRouter(rewriteEngine.Rewrite)
return app
}
func staticIndex(ctx iris.Context) {
ctx.Writef("This is the static.mydomain.com index.")
}
func index(ctx iris.Context) {
ctx.Writef("This is the www.mydomain.com index.")
}
func userGet(ctx iris.Context) {
// Also, ctx.Subdomain(), ctx.SubdomainFull(), ctx.Host() and ctx.Path()
// can be helpful when working with subdomains.
ctx.Writef("This is the www.mydomain.com/user endpoint.")
}
func userGetLogin(ctx iris.Context) {
ctx.Writef("This is the www.mydomain.com/user/login endpoint.")
}