mirror of
https://github.com/kataras/iris.git
synced 2025-12-21 20:07:04 +00:00
Add (10) more _examples. TOC: https://github.com/kataras/iris/tree/v6/_examples
Part 3. Former-commit-id: 229b86baca4043c69517968318d9a962d2e026d0
This commit is contained in:
43
_examples/advanced/subdomains/single/main.go
Normal file
43
_examples/advanced/subdomains/single/main.go
Normal file
@@ -0,0 +1,43 @@
|
||||
// Package main register static subdomains, simple as parties, check ./hosts if you use windows
|
||||
package main
|
||||
|
||||
import (
|
||||
"gopkg.in/kataras/iris.v6"
|
||||
"gopkg.in/kataras/iris.v6/adaptors/httprouter"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
app.Adapt(iris.DevLogger())
|
||||
// subdomains works with all available routers, like other features too.
|
||||
app.Adapt(httprouter.New())
|
||||
|
||||
// no order, you can register subdomains at the end also.
|
||||
admin := app.Party("admin.")
|
||||
{
|
||||
// admin.mydomain.com
|
||||
admin.Get("/", func(c *iris.Context) {
|
||||
c.Writef("INDEX FROM admin.mydomain.com")
|
||||
})
|
||||
// admin.mydomain.com/hey
|
||||
admin.Get("/hey", func(c *iris.Context) {
|
||||
c.Writef("HEY FROM admin.mydomain.com/hey")
|
||||
})
|
||||
// admin.mydomain.com/hey2
|
||||
admin.Get("/hey2", func(c *iris.Context) {
|
||||
c.Writef("HEY SECOND FROM admin.mydomain.com/hey")
|
||||
})
|
||||
}
|
||||
|
||||
// mydomain.com/
|
||||
app.Get("/", func(c *iris.Context) {
|
||||
c.Writef("INDEX FROM no-subdomain hey")
|
||||
})
|
||||
|
||||
// mydomain.com/hey
|
||||
app.Get("/hey", func(c *iris.Context) {
|
||||
c.Writef("HEY FROM no-subdomain hey")
|
||||
})
|
||||
|
||||
app.Listen("mydomain.com:80") // for beginners: look ../hosts file
|
||||
}
|
||||
Reference in New Issue
Block a user