1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-02 09:47:17 +00:00
kataras
2017-06-15 20:02:08 +03:00
parent a10e80842f
commit e0128d204d
58 changed files with 11054 additions and 505 deletions

View File

@@ -0,0 +1,25 @@
# 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 iris-go.com
127.0.0.1 www.iris-go.com
#-END IRIS-

View File

@@ -0,0 +1,65 @@
package main
import (
"github.com/kataras/iris"
"github.com/kataras/iris/context"
)
func newApp() *iris.Application {
app := iris.New()
app.Get("/", info)
app.Get("/about", info)
app.Get("/contact", info)
usersAPI := app.Party("/api/users")
{
usersAPI.Get("/", info)
usersAPI.Get("/{id:int}", info)
usersAPI.Post("/", info)
usersAPI.Put("/{id:int}", info)
}
www := app.Party("www.")
{
// get all routes that are registered so far, including all "Parties":
currentRoutes := app.GetRoutes()
// register them to the www subdomain/vhost as well:
for _, r := range currentRoutes {
if _, err := www.Handle(r.Method, r.Path, r.Handlers...); err != nil {
app.Log("%s for www. failed: %v", r.Path, err)
}
}
}
return app
}
func main() {
app := newApp()
// http://iris-go.com
// http://iris-go.com/about
// http://iris-go.com/contact
// http://iris-go.com/api/users
// http://iris-go.com/api/users/42
// http://www.iris-go.com
// http://www.iris-go.com/about
// http://www.iris-go.com/contact
// http://www.iris-go.com/api/users
// http://www.iris-go.com/api/users/42
if err := app.Run(iris.Addr("iris-go.com:80")); err != nil {
panic(err)
}
}
func info(ctx context.Context) {
method := ctx.Method()
subdomain := ctx.Subdomain()
path := ctx.Path()
ctx.Writef("\nInfo\n\n")
ctx.Writef("Method: %s\nSubdomain: %s\nPath: %s", method, subdomain, path)
}

View File

@@ -0,0 +1,59 @@
package main
import (
"fmt"
"testing"
"github.com/kataras/iris"
"github.com/kataras/iris/httptest"
)
type testRoute struct {
path string
method string
subdomain string
}
func (r testRoute) response() string {
msg := fmt.Sprintf("\nInfo\n\nMethod: %s\nSubdomain: %s\nPath: %s", r.method, r.subdomain, r.path)
return msg
}
func TestSubdomainWWW(t *testing.T) {
app := newApp()
tests := []testRoute{
// host
{"/", "GET", ""},
{"/about", "GET", ""},
{"/contact", "GET", ""},
{"/api/users", "GET", ""},
{"/api/users/42", "GET", ""},
{"/api/users", "POST", ""},
{"/api/users/42", "PUT", ""},
// www sub domain
{"/", "GET", "www"},
{"/about", "GET", "www"},
{"/contact", "GET", "www"},
{"/api/users", "GET", "www"},
{"/api/users/42", "GET", "www"},
{"/api/users", "POST", "www"},
{"/api/users/42", "PUT", "www"},
}
host := "localhost:1111"
e := httptest.New(t, app, httptest.URL("http://"+host))
for _, test := range tests {
req := e.Request(test.method, test.path)
if subdomain := test.subdomain; subdomain != "" {
req.WithURL("http://" + subdomain + "." + host)
}
req.Expect().
Status(iris.StatusOK).
Body().Equal(test.response())
}
}