1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-28 07:17:06 +00:00

Add notes for the new lead maintainer of the open-source iris project and align with @get-ion/ion by @hiveminded

Former-commit-id: da4f38eb9034daa49446df3ee529423b98f9b331
This commit is contained in:
kataras
2017-07-10 18:32:42 +03:00
parent 2d4c2779a7
commit 9f85b74fc9
344 changed files with 4842 additions and 5174 deletions

View File

@@ -0,0 +1,32 @@
# 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 username1.127.0.0.1
127.0.0.1 username2.127.0.0.1
127.0.0.1 username3.127.0.0.1
127.0.0.1 username4.127.0.0.1
127.0.0.1 username5.127.0.0.1
# note that you can always use custom subdomains
#-END iris-
# Windows: Drive:/Windows/system32/drivers/etc/hosts, on Linux: /etc/hosts

View File

@@ -0,0 +1,71 @@
// Package main an example on how to naming your routes & use the custom 'url' HTML Template Engine, same for other template engines.
package main
import (
"github.com/kataras/iris"
"github.com/kataras/iris/context"
"github.com/kataras/iris/core/router"
)
const (
host = "127.0.0.1:8080"
)
func main() {
app := iris.New()
// create a custom path reverser, iris let you define your own host and scheme
// which is useful when you have nginx or caddy in front of iris.
rv := router.NewRoutePathReverser(app, router.WithHost(host), router.WithScheme("http"))
// locate and define our templates as usual.
templates := iris.HTML("./templates", ".html")
// add a custom func of "url" and pass the rv.URL as its template function body,
// so {{url "routename" "paramsOrSubdomainAsFirstArgument"}} will work inside our templates.
templates.AddFunc("url", rv.URL)
app.RegisterView(templates)
// wildcard subdomain, will catch username1.... username2.... username3... username4.... username5...
// that our below links are providing via page.html's first argument which is the subdomain.
subdomain := app.Party("*.")
mypathRoute := subdomain.Get("/mypath", emptyHandler)
mypathRoute.Name = "my-page1"
mypath2Route := subdomain.Get("/mypath2/{paramfirst}/{paramsecond}", emptyHandler)
mypath2Route.Name = "my-page2"
mypath3Route := subdomain.Get("/mypath3/{paramfirst}/statichere/{paramsecond}", emptyHandler)
mypath3Route.Name = "my-page3"
mypath4Route := subdomain.Get("/mypath4/{paramfirst}/statichere/{paramsecond}/{otherparam}/{something:path}", emptyHandler)
mypath4Route.Name = "my-page4"
mypath5Route := subdomain.Handle("GET", "/mypath5/{paramfirst}/statichere/{paramsecond}/{otherparam}/anything/{something:path}", emptyHandler)
mypath5Route.Name = "my-page5"
mypath6Route := subdomain.Get("/mypath6/{paramfirst}/{paramsecond}/staticParam/{paramThirdAfterStatic}", emptyHandler)
mypath6Route.Name = "my-page6"
app.Get("/", func(ctx context.Context) {
// for username5./mypath6...
paramsAsArray := []string{"username5", "theParam1", "theParam2", "paramThirdAfterStatic"}
ctx.ViewData("ParamsAsArray", paramsAsArray)
if err := ctx.View("page.html"); err != nil {
panic(err)
}
})
// http://127.0.0.1:8080
app.Run(iris.Addr(host))
}
func emptyHandler(ctx context.Context) {
ctx.Writef("Hello from subdomain: %s , you're in path: %s", ctx.Subdomain(), ctx.Path())
}
// Note:
// If you got an empty string on {{ url }} or {{ urlpath }} it means that
// args length are not aligned with the route's parameters length
// or the route didn't found by the passed name.

View File

@@ -0,0 +1,29 @@
<!-- the only difference between normal named routes and dynamic subdomains named routes is that the first argument of url
is the subdomain part instead of named parameter-->
<a href="{{url "my-page1" "username1"}}">username1.127.0.0.1:8080/mypath</a>
<br />
<br />
<a href="{{url "my-page2" "username2" "theParam1" "theParam2"}}">
username2.127.0.0.1:8080/mypath2/{paramfirst}/{paramsecond}
</a>
<br />
<br />
<a href="{{url "my-page3" "username3" "theParam1" "theParam2AfterStatic"}}">
username3.127.0.0.1:8080/mypath3/{paramfirst}/statichere/{paramsecond}
</a>
<br />
<br />
<a href="{{url "my-page4" "username4" "theParam1" "theparam2AfterStatic" "otherParam" "matchAnything"}}">
username4.127.0.0.1:8080/mypath4/{paramfirst}/statichere/{paramsecond}/{otherParam}/{something:path}
</a>
<br />
<br />
<a href="{{url "my-page5" "username5" "theParam1" "theparam2AfterStatic" "otherParam" "matchAnything"}}">
username5.127.0.0.1:8080/mypath5/{paramfirst}/statichere/{paramsecond}/{otherparam}/anything/{something:path}
</a>
<br/>
<br/>
<a href="{{url "my-page6" .ParamsAsArray }}">
username5.127.0.0.1:8080/mypath6/{paramfirst}/{paramsecond}/staticParam/{paramThirdAfterStatic}
</a>