1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-26 22:37:08 +00:00

Fix history big mistakes, point links to /v6 tag only https://github.com/kataras/iris/issues/606

Former-commit-id: e0a7ce1a991e5d6600de6cc0a853ef8b1cb8d282
This commit is contained in:
Gerasimos (Makis) Maropoulos
2017-02-18 07:22:57 +02:00
parent 7263649002
commit f83c7fb4e7
7 changed files with 59 additions and 320 deletions

View File

@@ -1,103 +0,0 @@
## Package information
Gorillamux is a plugin for Iris which overrides the Iris' default router with the [Gorilla Mux](https://github.com/gorilla/mux)
which enables path matching using custom `regexp` ( thing that the Iris' default router doesn't supports for performance reasons).
All these without need to change any of your existing Iris code. All features are supported.
## Install
```sh
$ go get -u github.com/iris-contrib/plugin/gorillamux
```
```go
iris.Plugins.Add(gorillamux.New())
```
## [Example](https://github.com/iris-contrib/examples/tree/master/plugin_gorillamux)
```go
package main
import (
"github.com/iris-contrib/plugin/gorillamux"
"github.com/kataras/iris"
)
func main() {
iris.Plugins.Add(gorillamux.New())
// CUSTOM HTTP ERRORS ARE SUPPORTED
// NOTE: Gorilla mux allows customization only on StatusNotFound(404)
// Iris allows for everything, so you can register any other custom http error
// but you have to call it manually from ctx.EmitError(status_code) // 500 for example
// this will work because it's StatusNotFound:
iris.Default.OnError(iris.StatusNotFound, func(ctx *iris.Context) {
ctx.HTML(iris.StatusNotFound, "<h1> CUSTOM NOT FOUND ERROR PAGE </h1>")
})
// GLOBAL/PARTY MIDDLEWARE ARE SUPPORTED
iris.Default.UseFunc(func(ctx *iris.Context) {
println("Request: " + ctx.Path())
ctx.Next()
})
// http://mydomain.com
iris.Default.Get("/", func(ctx *iris.Context) {
ctx.Writef("Hello from index")
})
/// -------------------------------------- IMPORTANT --------------------------------------
/// GORILLA MUX PARAMETERS(regexp) ARE SUPPORTED
/// http://mydomain.com/api/users/42
/// ---------------------------------------------------------------------------------------
iris.Default.Get("/api/users/{userid:[0-9]+}", func(ctx *iris.Context) {
ctx.Writef("User with id: %s", ctx.Param("userid"))
})
// PER-ROUTE MIDDLEWARE ARE SUPPORTED
// http://mydomain.com/other
iris.Default.Get("/other", func(ctx *iris.Context) {
ctx.Writef("/other 1 middleware \n")
ctx.Next()
}, func(ctx *iris.Context) {
ctx.HTML(iris.StatusOK, "<b>Hello from /other</b>")
})
// SUBDOMAINS ARE SUPPORTED
// http://admin.mydomain.com
iris.Default.Party("admin.").Get("/", func(ctx *iris.Context) {
ctx.Writef("Hello from admin. subdomain!")
})
// WILDCARD SUBDOMAINS ARE SUPPORTED
// http://api.mydomain.com/hi
// http://admin.mydomain.com/hi
// http://x.mydomain.com/hi
// [depends on your host configuration,
// you will see an example(win) outside of this folder].
iris.Default.Party("*.").Get("/hi", func(ctx *iris.Context) {
ctx.Writef("Hello from wildcard subdomain: %s", ctx.Subdomain())
})
// DOMAIN NAMING IS SUPPORTED
iris.Default.Listen("mydomain.com")
// iris.Default.Listen(":80")
}
/* HOSTS FILE LINES TO RUN THIS EXAMPLE:
127.0.0.1 mydomain.com
127.0.0.1 admin.mydomain.com
127.0.0.1 api.mydomain.com
127.0.0.1 x.mydomain.com
*/
```
> Custom domain is totally optionally, you can still use `iris.Default.Listen(":8080")` of course.

View File

@@ -1,89 +0,0 @@
## Package information
This is an Iris and typescript bridge plugin.
1. Search for typescript files (.ts)
2. Search for typescript projects (.tsconfig)
3. If 1 || 2 continue else stop
4. Check if typescript is installed, if not then auto-install it (always inside npm global modules, -g)
5. If typescript project then build the project using tsc -p $dir
6. If typescript files and no project then build each typescript using tsc $filename
7. Watch typescript files if any changes happens, then re-build (5|6)
> Note: Ignore all typescript files & projects whose path has '/node_modules/'
## Install
```sh
$ go get -u github.com/iris-contrib/plugin/typescript
```
## Options
This plugin has **optionally** options
1. Bin: string, the typescript installation path/bin/tsc or tsc.cmd, if empty then it will search to the global npm modules
2. Dir: string, Dir set the root, where to search for typescript files/project. Default "./"
3. Ignore: string, comma separated ignore typescript files/project from these directories. Default "" (node_modules are always ignored)
4. Tsconfig: &typescript.Tsconfig{}, here you can set all compilerOptions if no tsconfig.json exists inside the 'Dir'
5. Editor: typescript.Editor(), if setted then alm-tools browser-based typescript IDE will be available. Defailt is nil
> Note: if any string in Ignore doesn't start with './' then it will ignore all files which contains this path string.
For example /node_modules/ will ignore all typescript files that are inside at ANY '/node_modules/', that means and the submodules.
## How to use
```go
package main
import (
"github.com/kataras/iris"
"github.com/iris-contrib/plugin/typescript"
)
func main(){
/* Options
Bin -> the typescript installation path/bin/tsc or tsc.cmd, if empty then it will search to the global npm modules
Dir -> where to search for typescript files/project. Default "./"
Ignore -> comma separated ignore typescript files/project from these directories (/node_modules/ are always ignored). Default ""
Tsconfig -> &typescript.Tsconfig{}, here you can set all compilerOptions if no tsconfig.json exists inside the 'Dir'
Editor -> typescript.Editor(), if setted then alm-tools browser-based typescript IDE will be available. Default is nil.
*/
config := typescript.Config {
Dir: "./scripts/src",
Tsconfig: &typescript.Tsconfig{Module: "commonjs", Target: "es5"}, // or typescript.DefaultTsconfig()
}
//if you want to change only certain option(s) but you want default to all others then you have to do this:
config = typescript.DefaultConfig()
//
iris.Plugins.Add(typescript.New(config)) //or with the default options just: typescript.New()
iris.Default.Get("/", func (ctx *iris.Context){})
iris.Default.Listen(":8080")
}
```
## Editor
[alm-tools](http://alm.tools) is a typescript online IDE/Editor, made by [@basarat](https://twitter.com/basarat) one of the top contributors of the [Typescript](http://www.typescriptlang.org).
Iris gives you the opportunity to edit your client-side using the alm-tools editor, via the editor plugin.
With typescript plugin you have to set the Editor option and you're ready:
```go
typescript.Config {
//...
Editor: typescript.Editor("username","passowrd")
//...
}
```
> [Read more](https://github.com/kataras/iris/tree/development/plugin/editor) for Editor