File: subdomains/wildcard/hosts
~~~
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
127.0.0.1 localhost
::1 localhost
#-iris-For development machine, you have to configure your dns also for online, search google how to do it if you don't know
127.0.0.1 mydomain.com
127.0.0.1 username1.mydomain.com
127.0.0.1 username2.mydomain.com
127.0.0.1 username3.mydomain.com
127.0.0.1 username4.mydomain.com
127.0.0.1 username5.mydomain.com
#-END iris-
~~~
File: subdomains/wildcard/main.go
~~~
//包装主要是关于如何捕获动态子域名的一个例子——通配符.
// 在第一个例子中(子域名1)我们看到了如何为静态子域名创建路由,你知道你将拥有的子域名.
// 在这里,我们将看到一个如何捕获未知子域的示例,如username.mydomain.com:8080.
package main
import (
"github.com/kataras/iris"
)
// 首先在您的服务器机器(dns/。)上注册一个动态通配符子域,如果您使用windows,请检查。hosts。.
//运行这个文件并尝试重定向: http://username1.mydomain.com:8080/ , http://username2.mydomain.com:8080/ , http://username1.mydomain.com/something, http://username1.mydomain.com/something/sadsadsa
func main() {
app := iris.New()
/* 请注意,您可以同时使用这两种子域名 (命名和通配符(*.) )
admin.mydomain.com, :对其他政党来说(*.) 但这不是这个例子的目的
admin := app.Party("admin.")
{
// admin.mydomain.com
admin.Get("/", func(ctx iris.Context) {
ctx.Writef("INDEX FROM admin.mydomain.com")
})
// admin.mydomain.com/hey
admin.Get("/hey", func(ctx iris.Context) {
ctx.Writef("HEY FROM admin.mydomain.com/hey")
})
// admin.mydomain.com/hey2
admin.Get("/hey2", func(ctx iris.Context) {
ctx.Writef("HEY SECOND FROM admin.mydomain.com/hey")
})
}*/
//没有顺序,你也可以在末端注册子域名.
dynamicSubdomains := app.Party("*.")
{
dynamicSubdomains.Get("/", dynamicSubdomainHandler)
dynamicSubdomains.Get("/something", dynamicSubdomainHandler)
dynamicSubdomains.Get("/something/{paramfirst}", dynamicSubdomainHandlerWithParam)
}
app.Get("/", func(ctx iris.Context) {
ctx.Writef("Hello from mydomain.com path: %s", ctx.Path())
})
app.Get("/hello", func(ctx iris.Context) {
ctx.Writef("Hello from mydomain.com path: %s", ctx.Path())
})
// http://mydomain.com:8080
// http://username1.mydomain.com:8080
// http://username2.mydomain.com:8080/something
// http://username3.mydomain.com:8080/something/yourname
app.Run(iris.Addr("mydomain.com:8080")) // for beginners: look ../hosts file
}
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 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"))
}
~~~
- api文档
- yaag
- 认证
- 认证基本
- oauth2
- 缓存
- 客户端
- 简单的
- 配置
- 配置文件
- tml文件
- yaml文件
- 功能
- 处理程序
- Negroni Like
- http
- Real Usecase Raven
- cookies
- Basic
- 安全cookie
- 实验程序
- casbin
- 云监视
- cors
- csrf
- jwt
- 新文学
- Casbin
- 文件服务器
- Hero
- http监听
- http请求
- HTTP Responsewriter
- Miscellaneous
- MVC
- mvc概观
- 中间件
- Hello World
- 登陆
- Session 控制器
- Singleton
- MVC基本
- ORM
- xorm
- 概况
- 路由
- 概观
- 自定义上下文
- 自定义包装
- 动态路径
- 相反
- HTTP错误
- 路由状态
- 路由基本
- Sessions
- 构建
- 子域
- 重定向
- 万维网
- Single
- 通配符
- 多域名
- 测试
- 教程
- 视图
- Template Html 0
- Template Html 1
- Template Html 2
- Template Html 3
- Template Html 4
- Webassembly
- Websocket
