1
0
mirror of https://github.com/kataras/iris.git synced 2026-09-19 02:02:38 +00:00
kataras
2017-06-15 20:02:08 +03:00
parent a10e80842f
commit e0128d204d
58 changed files with 11054 additions and 505 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ import (
// $ go test -v
func TestNewApp(t *testing.T) {
app := newApp()
e := httptest.New(app, t)
e := httptest.New(t, app)
// redirects to /admin without basic auth
e.GET("/").Expect().Status(iris.StatusUnauthorized)
File diff suppressed because it is too large Load Diff
Binary file not shown.

Before

Width:  |  Height:  |  Size: 264 KiB

File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
@@ -1,43 +0,0 @@
// for templates + go-bindata checkout the '_examples\intermediate\view\embedding-templates-into-app' folder.
package main
// First of all, execute: $ go get https://github.com/jteeuwen/go-bindata
// Secondly, execute the command: cd $GOPATH/src/github.com/kataras/iris/_examples/intermediate/serve-embedded-files && go-bindata ./assets/...
import (
"github.com/kataras/iris"
"github.com/kataras/iris/context"
)
func main() {
app := iris.New()
app.Get("/", func(ctx context.Context) {
ctx.HTML("<b> Hi from index</b>")
})
// executing this go-bindata command creates a source file named 'bindata.go' which
// gives you the Asset and AssetNames funcs which we will pass into .StaticAssets
// for more viist: https://github.com/jteeuwen/go-bindata
// Iris gives you a way to integrade these functions to your web app
// For the reason that you may use go-bindata to embed more than your assets,
// you should pass the 'virtual directory path', for example here is the : "./assets"
// and the request path, which these files will be served to,
// you can set as "/assets" or "/static" which resulting on http://localhost:8080/static/*anyfile.*extension
app.StaticEmbedded("/static", "./assets", Asset, AssetNames)
// that's all
// this will serve the ./assets (embedded) files to the /static request path for example the favicon.ico will be served as :
// http://localhost:8080/static/favicon.ico
// Methods: GET and HEAD
app.Run(iris.Addr(":8080"))
}
// Navigate to:
// http://localhost:8080/static/favicon.ico
// http://localhost:8080/static/js/jquery-2.1.1.js
// http://localhost:8080/static/css/bootstrap.min.css
// Now, these files are are stored into inside your executable program, no need to keep it in the same location with your assets folder.
@@ -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-
@@ -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)
}
@@ -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())
}
}