mirror of
https://github.com/kataras/iris.git
synced 2026-01-07 20:17:05 +00:00
Update to version 8.5.8 | Read HISTORY.md
Former-commit-id: 82128ce7a2896a9a8bafd7a5268b0b42057fc21a
This commit is contained in:
@@ -17,6 +17,7 @@ It doesn't always contain the "best ways" but it does cover each important featu
|
||||
- [POC: Isomorphic react/hot reloadable/redux/css-modules starter kit](https://github.com/kataras/iris-starter-kit)
|
||||
- [Tutorial: DropzoneJS Uploader](tutorial/dropzonejs)
|
||||
- [Tutorial: Caddy](tutorial/caddy)
|
||||
- [Tutorial:Iris Go Framework + MongoDB](https://medium.com/go-language/iris-go-framework-mongodb-552e349eab9c)
|
||||
|
||||
### Structuring
|
||||
|
||||
@@ -276,6 +277,7 @@ You can serve [quicktemplate](https://github.com/valyala/quicktemplate) files to
|
||||
- Single Page Applications
|
||||
* [single Page Application](file-server/single-page-application/basic/main.go)
|
||||
* [embedded Single Page Application](file-server/single-page-application/embedded-single-page-application/main.go)
|
||||
* [embedded Single Page Application with other routes](file-server/single-page-application/embedded-single-page-application-with-other-routes/main.go)
|
||||
|
||||
### How to Read from `context.Request() *http.Request`
|
||||
|
||||
|
||||
@@ -0,0 +1,285 @@
|
||||
// Code generated by go-bindata.
|
||||
// sources:
|
||||
// public/app.js
|
||||
// public/css/main.css
|
||||
// public/index.html
|
||||
// DO NOT EDIT!
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func bindataRead(data []byte, name string) ([]byte, error) {
|
||||
gz, err := gzip.NewReader(bytes.NewBuffer(data))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Read %q: %v", name, err)
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
_, err = io.Copy(&buf, gz)
|
||||
clErr := gz.Close()
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Read %q: %v", name, err)
|
||||
}
|
||||
if clErr != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
type asset struct {
|
||||
bytes []byte
|
||||
info os.FileInfo
|
||||
}
|
||||
|
||||
type bindataFileInfo struct {
|
||||
name string
|
||||
size int64
|
||||
mode os.FileMode
|
||||
modTime time.Time
|
||||
}
|
||||
|
||||
func (fi bindataFileInfo) Name() string {
|
||||
return fi.name
|
||||
}
|
||||
func (fi bindataFileInfo) Size() int64 {
|
||||
return fi.size
|
||||
}
|
||||
func (fi bindataFileInfo) Mode() os.FileMode {
|
||||
return fi.mode
|
||||
}
|
||||
func (fi bindataFileInfo) ModTime() time.Time {
|
||||
return fi.modTime
|
||||
}
|
||||
func (fi bindataFileInfo) IsDir() bool {
|
||||
return false
|
||||
}
|
||||
func (fi bindataFileInfo) Sys() interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
var _publicAppJs = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x2a\xcf\xcc\x4b\xc9\x2f\xd7\x4b\xcc\x49\x2d\x2a\xd1\x50\x4a\x2c\x28\xd0\xcb\x2a\x56\xc8\xc9\x4f\x4c\x49\x4d\x51\x48\x2b\xca\xcf\x55\x88\x51\xd2\x57\xd2\xb4\x06\x04\x00\x00\xff\xff\xa9\x06\xf7\xa3\x27\x00\x00\x00")
|
||||
|
||||
func publicAppJsBytes() ([]byte, error) {
|
||||
return bindataRead(
|
||||
_publicAppJs,
|
||||
"public/app.js",
|
||||
)
|
||||
}
|
||||
|
||||
func publicAppJs() (*asset, error) {
|
||||
bytes, err := publicAppJsBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "public/app.js", size: 39, mode: os.FileMode(511), modTime: time.Unix(1499700236, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
var _publicCssMainCss = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x4a\xca\x4f\xa9\x54\xa8\xe6\xe5\x52\x50\x50\x50\x48\x4a\x4c\xce\x4e\x2f\xca\x2f\xcd\x4b\xd1\x4d\xce\xcf\xc9\x2f\xb2\x52\x48\xca\x49\x4c\xce\xb6\xe6\xe5\xaa\xe5\xe5\x02\x04\x00\x00\xff\xff\x03\x25\x9c\x89\x29\x00\x00\x00")
|
||||
|
||||
func publicCssMainCssBytes() ([]byte, error) {
|
||||
return bindataRead(
|
||||
_publicCssMainCss,
|
||||
"public/css/main.css",
|
||||
)
|
||||
}
|
||||
|
||||
func publicCssMainCss() (*asset, error) {
|
||||
bytes, err := publicCssMainCssBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "public/css/main.css", size: 41, mode: os.FileMode(511), modTime: time.Unix(1499700236, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
var _publicIndexHtml = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x4c\x8e\x41\x0e\xc2\x20\x10\x45\xf7\x24\xdc\xe1\xa7\x07\x28\xe9\x7e\x64\xed\x35\x10\x46\xc1\x50\x21\x30\x0b\xbd\xbd\x29\xc5\xc4\xf5\x7f\x6f\xde\x50\x94\x3d\x5b\xad\xb4\xa2\xc8\x2e\x58\xad\x00\x80\x24\x49\x66\x7b\xe5\x9c\x0b\xee\xad\xec\xe8\xe2\x24\x79\x54\xf7\x60\x32\xe7\xaa\x15\x99\xe9\x68\x45\xb7\x12\x3e\x3f\x3b\x6e\x16\x7f\x6e\x7a\x05\x7e\xaf\x47\x08\x64\xe2\x36\xf8\x49\x76\xdf\x52\x15\xf4\xe6\x2f\x8b\x71\xb5\xae\xcf\xbe\x58\x80\xcc\x39\x8c\xc6\xbc\x3c\x72\xc7\xb3\xdf\x00\x00\x00\xff\xff\x7e\xad\xd1\x97\xb3\x00\x00\x00")
|
||||
|
||||
func publicIndexHtmlBytes() ([]byte, error) {
|
||||
return bindataRead(
|
||||
_publicIndexHtml,
|
||||
"public/index.html",
|
||||
)
|
||||
}
|
||||
|
||||
func publicIndexHtml() (*asset, error) {
|
||||
bytes, err := publicIndexHtmlBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "public/index.html", size: 179, mode: os.FileMode(511), modTime: time.Unix(1510219864, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
// Asset loads and returns the asset for the given name.
|
||||
// It returns an error if the asset could not be found or
|
||||
// could not be loaded.
|
||||
func Asset(name string) ([]byte, error) {
|
||||
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
if f, ok := _bindata[cannonicalName]; ok {
|
||||
a, err := f()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
|
||||
}
|
||||
return a.bytes, nil
|
||||
}
|
||||
return nil, fmt.Errorf("Asset %s not found", name)
|
||||
}
|
||||
|
||||
// MustAsset is like Asset but panics when Asset would return an error.
|
||||
// It simplifies safe initialization of global variables.
|
||||
func MustAsset(name string) []byte {
|
||||
a, err := Asset(name)
|
||||
if err != nil {
|
||||
panic("asset: Asset(" + name + "): " + err.Error())
|
||||
}
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
// AssetInfo loads and returns the asset info for the given name.
|
||||
// It returns an error if the asset could not be found or
|
||||
// could not be loaded.
|
||||
func AssetInfo(name string) (os.FileInfo, error) {
|
||||
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
if f, ok := _bindata[cannonicalName]; ok {
|
||||
a, err := f()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
|
||||
}
|
||||
return a.info, nil
|
||||
}
|
||||
return nil, fmt.Errorf("AssetInfo %s not found", name)
|
||||
}
|
||||
|
||||
// AssetNames returns the names of the assets.
|
||||
func AssetNames() []string {
|
||||
names := make([]string, 0, len(_bindata))
|
||||
for name := range _bindata {
|
||||
names = append(names, name)
|
||||
}
|
||||
return names
|
||||
}
|
||||
|
||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||
var _bindata = map[string]func() (*asset, error){
|
||||
"public/app.js": publicAppJs,
|
||||
"public/css/main.css": publicCssMainCss,
|
||||
"public/index.html": publicIndexHtml,
|
||||
}
|
||||
|
||||
// AssetDir returns the file names below a certain
|
||||
// directory embedded in the file by go-bindata.
|
||||
// For example if you run go-bindata on data/... and data contains the
|
||||
// following hierarchy:
|
||||
// data/
|
||||
// foo.txt
|
||||
// img/
|
||||
// a.png
|
||||
// b.png
|
||||
// then AssetDir("data") would return []string{"foo.txt", "img"}
|
||||
// AssetDir("data/img") would return []string{"a.png", "b.png"}
|
||||
// AssetDir("foo.txt") and AssetDir("notexist") would return an error
|
||||
// AssetDir("") will return []string{"data"}.
|
||||
func AssetDir(name string) ([]string, error) {
|
||||
node := _bintree
|
||||
if len(name) != 0 {
|
||||
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
pathList := strings.Split(cannonicalName, "/")
|
||||
for _, p := range pathList {
|
||||
node = node.Children[p]
|
||||
if node == nil {
|
||||
return nil, fmt.Errorf("Asset %s not found", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
if node.Func != nil {
|
||||
return nil, fmt.Errorf("Asset %s not found", name)
|
||||
}
|
||||
rv := make([]string, 0, len(node.Children))
|
||||
for childName := range node.Children {
|
||||
rv = append(rv, childName)
|
||||
}
|
||||
return rv, nil
|
||||
}
|
||||
|
||||
type bintree struct {
|
||||
Func func() (*asset, error)
|
||||
Children map[string]*bintree
|
||||
}
|
||||
var _bintree = &bintree{nil, map[string]*bintree{
|
||||
"public": &bintree{nil, map[string]*bintree{
|
||||
"app.js": &bintree{publicAppJs, map[string]*bintree{}},
|
||||
"css": &bintree{nil, map[string]*bintree{
|
||||
"main.css": &bintree{publicCssMainCss, map[string]*bintree{}},
|
||||
}},
|
||||
"index.html": &bintree{publicIndexHtml, map[string]*bintree{}},
|
||||
}},
|
||||
}}
|
||||
|
||||
// RestoreAsset restores an asset under the given directory
|
||||
func RestoreAsset(dir, name string) error {
|
||||
data, err := Asset(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
info, err := AssetInfo(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RestoreAssets restores an asset under the given directory recursively
|
||||
func RestoreAssets(dir, name string) error {
|
||||
children, err := AssetDir(name)
|
||||
// File
|
||||
if err != nil {
|
||||
return RestoreAsset(dir, name)
|
||||
}
|
||||
// Dir
|
||||
for _, child := range children {
|
||||
err = RestoreAssets(dir, filepath.Join(name, child))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func _filePath(dir, name string) string {
|
||||
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package main
|
||||
|
||||
import "github.com/kataras/iris"
|
||||
|
||||
// $ go get -u github.com/jteeuwen/go-bindata/...
|
||||
// $ go-bindata ./public/...
|
||||
// $ go build
|
||||
// $ ./embedded-single-page-application-with-other-routes
|
||||
|
||||
func newApp() *iris.Application {
|
||||
app := iris.New()
|
||||
app.OnErrorCode(404, func(ctx iris.Context) {
|
||||
ctx.Writef("404 not found here")
|
||||
})
|
||||
|
||||
assetHandler := app.StaticEmbeddedHandler("./public", Asset, AssetNames)
|
||||
app.SPA(assetHandler)
|
||||
|
||||
// Note:
|
||||
// if you want a dynamic index page then see the file-server/embedded-single-page-application
|
||||
// which is registering a view engine based on bindata as well and a root route.
|
||||
|
||||
app.Get("/ping", func(ctx iris.Context) {
|
||||
ctx.WriteString("pong")
|
||||
})
|
||||
app.Get("/.well-known", func(ctx iris.Context) {
|
||||
ctx.WriteString("well-known")
|
||||
})
|
||||
app.Get(".well-known/ready", func(ctx iris.Context) {
|
||||
ctx.WriteString("ready")
|
||||
})
|
||||
app.Get(".well-known/live", func(ctx iris.Context) {
|
||||
ctx.WriteString("live")
|
||||
})
|
||||
app.Get(".well-known/metrics", func(ctx iris.Context) {
|
||||
ctx.Writef("metrics")
|
||||
})
|
||||
return app
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := newApp()
|
||||
|
||||
// http://localhost:8080/index.html
|
||||
// http://localhost:8080/app.js
|
||||
// http://localhost:8080/css/main.css
|
||||
//
|
||||
// http://localhost:8080/ping
|
||||
// http://localhost:8080/.well-known
|
||||
// http://localhost:8080/.well-known/ready
|
||||
// http://localhost:8080/.well-known/live
|
||||
// http://localhost:8080/.well-known/metrics
|
||||
//
|
||||
// Remember: we could use the root wildcard `app.Get("/{param:path}")` and serve the files manually as well.
|
||||
app.Run(iris.Addr(":8080"))
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
window.alert("app.js loaded from \"/");
|
||||
@@ -0,0 +1,3 @@
|
||||
body {
|
||||
background-color: black;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Hello from static page</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1> Hello from index.html </h1>
|
||||
|
||||
|
||||
<script src="/app.js"> </script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -25,7 +25,11 @@ func newApp() *iris.Application {
|
||||
assetHandler := app.StaticEmbeddedHandler("./public", Asset, AssetNames)
|
||||
// as an alternative of SPA you can take a look at the /routing/dynamic-path/root-wildcard
|
||||
// example too
|
||||
app.SPA(assetHandler)
|
||||
|
||||
// public/index.html is a dynamic view, it's handlded by root,
|
||||
// and we don't want to be visible as a raw data, so we will
|
||||
// the return value of `app.SPA` to modify the `IndexNames` by;
|
||||
app.SPA(assetHandler).AddIndexName("index.html")
|
||||
|
||||
return app
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user