diff --git a/.travis.yml b/.travis.yml index a5339475..cc1e38f2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,9 @@ os: - linux - osx go: - - go1.8 +# - go1.8 works of course but +# we must encourage users to update to the latest go version, +# so examples are running on go 1.9 mode. - tip go_import_path: github.com/kataras/iris install: diff --git a/HISTORY.md b/HISTORY.md index b4994b37..b955dccd 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -21,6 +21,17 @@ Developers are not forced to upgrade if they don't really need it. Upgrade whene # Su, 27 August 2017 | v8.4.0 +## Miscellaneous + +- Update `vendor blackfriday` package to its latest version, 2.0.0 +- Update [documentation](https://godoc.org/github.com/kataras/iris) for go 1.9 +- Update [_examples](_examples) folder for go 1.9 +- Update examples inside https://github.com/iris-contrib/middleware for go 1.9 +- Update https://github.com/kataras/iris-contrib/examples for go 1.9 +- Update https://iris-go.com/v8/recipe for go 1.9 + +## Router + Add a new macro type for path parameters, `long`, it's the go type `int64`. ```go @@ -29,7 +40,7 @@ app.Get("/user/{id:long}", func(ctx context.Context) { }) ``` -And the promise we gave to you some days ago. +## MVC The ability to pre-calculate, register and map different (relative) paths inside a single controller with zero performance cost. @@ -1413,7 +1424,7 @@ General - Several enhancements for the typescript transpiler, view engine, websocket server and sessions manager - All `Listen` methods replaced with a single `Run` method, see [here](https://github.com/kataras/iris/tree/master/_examples/beginner/listening) - Configuration, easier to modify the defaults, see [here](https://github.com/kataras/iris/tree/master/_examples/beginner/cofiguration) -- `HandlerFunc` removed, just `Handler` of `func(context.Context)` where context.Context derives from `import "github.com/kataras/iris/context"` (on August this import path will be optional) +- `HandlerFunc` removed, just `Handler` of `func(context.Context)` where context.Context derives from `import "github.com/kataras/iris/context"` (**NEW**: this import path is optional, use `iris.Context` if you've installed Go 1.9) - Simplify API, i.e: instead of `Handle,HandleFunc,Use,UseFunc,Done,DoneFunc,UseGlobal,UseGlobalFunc` use `Handle,Use,Done,UseGlobal`. - Response time decreased even more (9-35%, depends on the application) - The `Adaptors` idea replaced with a more structural design pattern, but you have to apply these changes: diff --git a/README.md b/README.md index 99f236d4..37b91e3b 100644 --- a/README.md +++ b/README.md @@ -72,14 +72,11 @@ Iris may have reached version 8, but we're not stopping there. We have many feat - [A URL Shortener Service using Go, Iris and Bolt](https://medium.com/@kataras/a-url-shortener-service-using-go-iris-and-bolt-4182f0b00ae7) - [Why I preferred Go over Node.js for simple Web Application](https://medium.com/@tigranbs/why-i-preferred-go-over-node-js-for-simple-web-application-d4a549e979b9) * [Versioning](#-version) - * [When should I upgrade?](#should-i-upgrade-my-iris) - * [Where can I find older versions?](#where-can-i-find-older-versions) -* [Get Hired](#-get-hired) * [People](#-people) ### 🚀 Installation -The only requirement is the [Go Programming Language](https://golang.org/dl/), at least version 1.8 +The only requirement is the [Go Programming Language](https://golang.org/dl/), at least version 1.8 but **1.9** is highly recommended. ```sh $ go get -u github.com/kataras/iris @@ -90,10 +87,8 @@ $ go get -u github.com/kataras/iris ```go // file: main.go package main -import ( - "github.com/kataras/iris" - "github.com/kataras/iris/context" -) +import "github.com/kataras/iris" + func main() { app := iris.New() // Load all templates from the "./templates" folder @@ -103,14 +98,14 @@ func main() { // Method: GET // Resource: http://localhost:8080 - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { // Bind: {{.message}} with "Hello world!" ctx.ViewData("message", "Hello world!") // Render template file: ./templates/hello.html ctx.View("hello.html") }) - // Start the server using a network address and block. + // Start the server using a network address. app.Run(iris.Addr(":8080")) } ``` @@ -133,24 +128,27 @@ $ go run main.go ```
-Hello World with Go 1.9 +Hello World with Go 1.8 -Go 1.9 just released. +Iris declares all of its type alias at the same file in order to be easy to be discovered. -Dcumentation and examples will be updated soon to use the already-type aliases inside the framework, such as `iris.Context` instead of the origin package. +> If you just upgraded to go 1.9 from 1.8 you can always search for a compatible type alias at the [context.go](context.go) file and opposite, if you use go 1.8 and you're new to Iris you can see [that](context.go) file to see the compatible packages. -If you've installed [Go 1.9](https://golang.org/dl) then you can omit the `github.com/kataras/iris/context` package from the imports statement. +If Go 1.8 remains the basic host for your go apps then you should declare and use the `github.com/kataras/iris/context` package on your source file's imports statement. ```go package main -import "github.com/kataras/iris" +import ( + "github.com/kataras/iris" + "github.com/kataras/iris/context" +) func main() { app := iris.New() app.RegisterView(iris.HTML("./templates", ".html")) - - app.Get("/", func(ctx iris.Context) { + + app.Get("/", func(ctx context.Context) { ctx.ViewData("message", "Hello world!") ctx.View("hello.html") }) @@ -352,6 +350,7 @@ Testers should upgrade immediately, if you're willing to use _iris_ in productio Previous versions can be found at [releases page](https://github.com/kataras/iris/releases). + + ### 🥇 People The original author of _Iris_ is [@kataras](https://github.com/kataras), you can reach him via diff --git a/_examples/README.md b/_examples/README.md index 2498295f..c22d6ce5 100644 --- a/_examples/README.md +++ b/_examples/README.md @@ -123,7 +123,7 @@ the template file via `Data` field. Access to the template layout via the `Layout` field. -Access to the low-level `context.Context` via the `Ctx` field. +Access to the low-level `iris.Context/context.Context` via the `Ctx` field. Flow as you used to, `Controllers` can be registered to any `Party`, including Subdomains, the Party's begin and done handlers work as expected. @@ -238,7 +238,7 @@ You can serve [quicktemplate](https://github.com/valyala/quicktemplate) files to - [Stream Writer](http_responsewriter/stream-writer/main.go) - [Transactions](http_responsewriter/transactions/main.go) -> The `context.ResponseWriter()` returns an enchament version of a http.ResponseWriter, these examples show some places where the Context uses this object. Besides that you can use it as you did before iris. +> The `context/context#ResponseWriter()` returns an enchament version of a http.ResponseWriter, these examples show some places where the Context uses this object. Besides that you can use it as you did before iris. ### ORM diff --git a/_examples/authentication/basicauth/main.go b/_examples/authentication/basicauth/main.go index 6ad5b275..8a7caadb 100644 --- a/_examples/authentication/basicauth/main.go +++ b/_examples/authentication/basicauth/main.go @@ -4,7 +4,6 @@ import ( "time" "github.com/kataras/iris" - "github.com/kataras/iris/context" "github.com/kataras/iris/middleware/basicauth" ) @@ -25,7 +24,7 @@ func newApp() *iris.Application { app.Get("/mysecret", authentication, h) */ - app.Get("/", func(ctx context.Context) { ctx.Redirect("/admin") }) + app.Get("/", func(ctx iris.Context) { ctx.Redirect("/admin") }) // to party @@ -49,7 +48,7 @@ func main() { app.Run(iris.Addr(":8080")) } -func h(ctx context.Context) { +func h(ctx iris.Context) { username, password, _ := ctx.Request().BasicAuth() // third parameter it will be always true because the middleware // makes sure for that, otherwise this handler will not be executed. diff --git a/_examples/authentication/oauth2/main.go b/_examples/authentication/oauth2/main.go index 18ea831f..562a2a12 100644 --- a/_examples/authentication/oauth2/main.go +++ b/_examples/authentication/oauth2/main.go @@ -25,7 +25,6 @@ import ( "sort" "github.com/kataras/iris" - "github.com/kataras/iris/context" "github.com/kataras/iris/sessions" @@ -95,7 +94,7 @@ func init() { // the URL query string. If you provide it in a different way, // assign your own function to this variable that returns the provider // name for your request. -var GetProviderName = func(ctx context.Context) (string, error) { +var GetProviderName = func(ctx iris.Context) (string, error) { // try to get it from the url param "provider" if p := ctx.URLParam("provider"); p != "" { return p, nil @@ -124,7 +123,7 @@ for the requested provider. See https://github.com/markbates/goth/examples/main.go to see this in action. */ -func BeginAuthHandler(ctx context.Context) { +func BeginAuthHandler(ctx iris.Context) { url, err := GetAuthURL(ctx) if err != nil { ctx.StatusCode(iris.StatusBadRequest) @@ -145,7 +144,7 @@ as either "provider" or ":provider" or from the context's value of "provider" ke I would recommend using the BeginAuthHandler instead of doing all of these steps yourself, but that's entirely up to you. */ -func GetAuthURL(ctx context.Context) (string, error) { +func GetAuthURL(ctx iris.Context) (string, error) { providerName, err := GetProviderName(ctx) if err != nil { return "", err @@ -173,7 +172,7 @@ func GetAuthURL(ctx context.Context) (string, error) { // If no state string is associated with the request, one will be generated. // This state is sent to the provider and can be retrieved during the // callback. -var SetState = func(ctx context.Context) string { +var SetState = func(ctx iris.Context) string { state := ctx.URLParam("state") if len(state) > 0 { return state @@ -186,7 +185,7 @@ var SetState = func(ctx context.Context) string { // GetState gets the state returned by the provider during the callback. // This is used to prevent CSRF attacks, see // http://tools.ietf.org/html/rfc6749#section-10.12 -var GetState = func(ctx context.Context) string { +var GetState = func(ctx iris.Context) string { return ctx.URLParam("state") } @@ -199,7 +198,7 @@ as either "provider" or ":provider". See https://github.com/markbates/goth/examples/main.go to see this in action. */ -var CompleteUserAuth = func(ctx context.Context) (goth.User, error) { +var CompleteUserAuth = func(ctx iris.Context) (goth.User, error) { providerName, err := GetProviderName(ctx) if err != nil { return goth.User{}, err @@ -237,7 +236,7 @@ var CompleteUserAuth = func(ctx context.Context) (goth.User, error) { } // Logout invalidates a user session. -func Logout(ctx context.Context) error { +func Logout(ctx iris.Context) error { providerName, err := GetProviderName(ctx) if err != nil { return err @@ -363,7 +362,7 @@ func main() { // start of the router - app.Get("/auth/{provider}/callback", func(ctx context.Context) { + app.Get("/auth/{provider}/callback", func(ctx iris.Context) { user, err := CompleteUserAuth(ctx) if err != nil { @@ -377,12 +376,12 @@ func main() { } }) - app.Get("/logout/{provider}", func(ctx context.Context) { + app.Get("/logout/{provider}", func(ctx iris.Context) { Logout(ctx) ctx.Redirect("/", iris.StatusTemporaryRedirect) }) - app.Get("/auth/{provider}", func(ctx context.Context) { + app.Get("/auth/{provider}", func(ctx iris.Context) { // try to get the user without re-authenticating if gothUser, err := CompleteUserAuth(ctx); err == nil { ctx.ViewData("", gothUser) @@ -394,7 +393,7 @@ func main() { } }) - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.ViewData("", providerIndex) diff --git a/_examples/cache/simple/main.go b/_examples/cache/simple/main.go index 3a86df78..0e507e96 100644 --- a/_examples/cache/simple/main.go +++ b/_examples/cache/simple/main.go @@ -4,7 +4,6 @@ import ( "time" "github.com/kataras/iris" - "github.com/kataras/iris/context" "github.com/kataras/iris/cache" ) @@ -67,7 +66,7 @@ func main() { app.Run(iris.Addr(":8080")) } -func writeMarkdown(ctx context.Context) { +func writeMarkdown(ctx iris.Context) { // tap multiple times the browser's refresh button and you will // see this println only once every 10 seconds. println("Handler executed. Content refreshed.") diff --git a/_examples/configuration/from-configuration-structure/main.go b/_examples/configuration/from-configuration-structure/main.go index 3c7fbdc5..b3da663e 100644 --- a/_examples/configuration/from-configuration-structure/main.go +++ b/_examples/configuration/from-configuration-structure/main.go @@ -2,12 +2,11 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" ) func main() { app := iris.New() - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.HTML("Hello!") }) // [...] diff --git a/_examples/configuration/from-toml-file/main.go b/_examples/configuration/from-toml-file/main.go index 2046e749..fe08b255 100644 --- a/_examples/configuration/from-toml-file/main.go +++ b/_examples/configuration/from-toml-file/main.go @@ -2,13 +2,12 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" ) func main() { app := iris.New() - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.HTML("Hello!") }) // [...] diff --git a/_examples/configuration/from-yaml-file/main.go b/_examples/configuration/from-yaml-file/main.go index 206d11fd..679b0d76 100644 --- a/_examples/configuration/from-yaml-file/main.go +++ b/_examples/configuration/from-yaml-file/main.go @@ -2,12 +2,11 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" ) func main() { app := iris.New() - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.HTML("Hello!") }) // [...] diff --git a/_examples/configuration/functional/main.go b/_examples/configuration/functional/main.go index 8e5ab2b1..9165b5d3 100644 --- a/_examples/configuration/functional/main.go +++ b/_examples/configuration/functional/main.go @@ -2,12 +2,11 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" ) func main() { app := iris.New() - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.HTML("Hello!") }) // [...] diff --git a/_examples/convert-handlers/negroni-like/main.go b/_examples/convert-handlers/negroni-like/main.go index 3770951d..4f65f46c 100644 --- a/_examples/convert-handlers/negroni-like/main.go +++ b/_examples/convert-handlers/negroni-like/main.go @@ -4,7 +4,6 @@ import ( "net/http" "github.com/kataras/iris" - "github.com/kataras/iris/context" ) func main() { @@ -13,14 +12,14 @@ func main() { app.Use(ionMiddleware) // Method GET: http://localhost:8080/ - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.HTML("

Home

") // this will print an error, // this route's handler will never be executed because the middleware's criteria not passed. }) // Method GET: http://localhost:8080/ok - app.Get("/ok", func(ctx context.Context) { + app.Get("/ok", func(ctx iris.Context) { ctx.Writef("Hello world!") // this will print "OK. Hello world!". }) diff --git a/_examples/convert-handlers/nethttp/main.go b/_examples/convert-handlers/nethttp/main.go index c79d9473..641939a5 100644 --- a/_examples/convert-handlers/nethttp/main.go +++ b/_examples/convert-handlers/nethttp/main.go @@ -4,7 +4,6 @@ import ( "net/http" "github.com/kataras/iris" - "github.com/kataras/iris/context" ) func main() { @@ -13,12 +12,12 @@ func main() { app.Use(ionMiddleware) // Method GET: http://localhost:8080/ - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.HTML("Home") }) // Method GET: http://localhost:8080/ok - app.Get("/ok", func(ctx context.Context) { + app.Get("/ok", func(ctx iris.Context) { ctx.HTML("Hello world!") }) diff --git a/_examples/file-server/favicon/main.go b/_examples/file-server/favicon/main.go index dd69477c..d9935e60 100644 --- a/_examples/file-server/favicon/main.go +++ b/_examples/file-server/favicon/main.go @@ -2,7 +2,6 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" ) func main() { @@ -14,7 +13,7 @@ func main() { // app.Favicon("./static/favicons/favicon.ico.ico", "/favicon_16_16.ico") // This will serve the ./static/favicons/favicon.ico.ico to: localhost:8080/favicon_16_16.ico - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.HTML(` press here to see the favicon.ico. At some browsers like chrome, it should be visible at the top-left side of the browser's window, because some browsers make requests to the /favicon.ico automatically, diff --git a/_examples/file-server/send-files/main.go b/_examples/file-server/send-files/main.go index bc7a4a6a..ca3d5045 100644 --- a/_examples/file-server/send-files/main.go +++ b/_examples/file-server/send-files/main.go @@ -2,13 +2,12 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" ) func main() { app := iris.New() - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { file := "./files/first.zip" ctx.SendFile(file, "c.zip") }) diff --git a/_examples/file-server/single-page-application/basic/main.go b/_examples/file-server/single-page-application/basic/main.go index c4bffc63..6ed45228 100644 --- a/_examples/file-server/single-page-application/basic/main.go +++ b/_examples/file-server/single-page-application/basic/main.go @@ -2,8 +2,6 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" - "github.com/kataras/iris/view" ) // same as embedded-single-page-application but without go-bindata, the files are "physical" stored in the @@ -15,15 +13,15 @@ var page = struct { func newApp() *iris.Application { app := iris.New() - app.RegisterView(view.HTML("./public", ".html")) + app.RegisterView(iris.HTML("./public", ".html")) - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.ViewData("Page", page) ctx.View("index.html") }) // or just serve index.html as it is: - // app.Get("/", func(ctx context.Context) { + // app.Get("/", func(ctx iris.Context) { // ctx.ServeFile("index.html", false) // }) diff --git a/_examples/file-server/single-page-application/embedded-single-page-application/main.go b/_examples/file-server/single-page-application/embedded-single-page-application/main.go index f1476030..1f8d28e4 100644 --- a/_examples/file-server/single-page-application/embedded-single-page-application/main.go +++ b/_examples/file-server/single-page-application/embedded-single-page-application/main.go @@ -2,8 +2,6 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" - "github.com/kataras/iris/view" ) // $ go get -u github.com/jteeuwen/go-bindata/... @@ -17,9 +15,9 @@ var page = struct { func newApp() *iris.Application { app := iris.New() - app.RegisterView(view.HTML("./public", ".html").Binary(Asset, AssetNames)) + app.RegisterView(iris.HTML("./public", ".html").Binary(Asset, AssetNames)) - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.ViewData("Page", page) ctx.View("index.html") }) diff --git a/_examples/hello-world/main.go b/_examples/hello-world/main.go index ae18a4eb..5a1d9132 100644 --- a/_examples/hello-world/main.go +++ b/_examples/hello-world/main.go @@ -1,10 +1,7 @@ -// +build !go1.9 - package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" "github.com/kataras/iris/middleware/logger" "github.com/kataras/iris/middleware/recover" @@ -20,21 +17,21 @@ func main() { // Method: GET // Resource: http://localhost:8080/ - app.Handle("GET", "/", func(ctx context.Context) { + app.Handle("GET", "/", func(ctx iris.Context) { ctx.HTML("Welcome!") }) // same as app.Handle("GET", "/ping", [...]) // Method: GET // Resource: http://localhost:8080/ping - app.Get("/ping", func(ctx context.Context) { + app.Get("/ping", func(ctx iris.Context) { ctx.WriteString("pong") }) // Method: GET // Resource: http://localhost:8080/hello - app.Get("/hello", func(ctx context.Context) { - ctx.JSON(context.Map{"message": "Hello iris web framework."}) + app.Get("/hello", func(ctx iris.Context) { + ctx.JSON(iris.Map{"message": "Hello iris web framework."}) }) // http://localhost:8080 diff --git a/_examples/hello-world/main_go19.go b/_examples/hello-world/main_go19.go deleted file mode 100644 index e48b3cc5..00000000 --- a/_examples/hello-world/main_go19.go +++ /dev/null @@ -1,44 +0,0 @@ -// +build go1.9 - -package main - -import ( - "github.com/kataras/iris" -) - -// Same as `main.go` for go1.8+ but it omits the -// `github.com/kataras/iris/context` import path -// because of the type alias feature of go 1.9. - -func main() { - // The `iris#Default` adds two built'n handlers - // that can recover from any http-relative panics - // and log the requests to the terminal. - // - // Use `iris#New` instead. - app := iris.Default() - - // Method: GET - // Resource: http://localhost:8080/ - app.Handle("GET", "/", func(ctx iris.Context) { - ctx.HTML("Hello world!") - }) - - // same as app.Handle("GET", "/ping", [...]) - // Method: GET - // Resource: http://localhost:8080/ping - app.Get("/ping", func(ctx iris.Context) { - ctx.WriteString("pong") - }) - - // Method: GET - // Resource: http://localhost:8080/hello - app.Get("/hello", func(ctx iris.Context) { - ctx.JSON(iris.Map{"message": "Hello iris web framework."}) - }) - - // http://localhost:8080 - // http://localhost:8080/ping - // http://localhost:8080/hello - app.Run(iris.Addr(":8080")) -} diff --git a/_examples/http-listening/custom-httpserver/easy-way/main.go b/_examples/http-listening/custom-httpserver/easy-way/main.go index 1a5a61e1..ff260302 100644 --- a/_examples/http-listening/custom-httpserver/easy-way/main.go +++ b/_examples/http-listening/custom-httpserver/easy-way/main.go @@ -4,17 +4,16 @@ import ( "net/http" "github.com/kataras/iris" - "github.com/kataras/iris/context" ) func main() { app := iris.New() - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.Writef("Hello from the server") }) - app.Get("/mypath", func(ctx context.Context) { + app.Get("/mypath", func(ctx iris.Context) { ctx.Writef("Hello from %s", ctx.Path()) }) diff --git a/_examples/http-listening/custom-httpserver/multi/main.go b/_examples/http-listening/custom-httpserver/multi/main.go index 8203248c..d7758dac 100644 --- a/_examples/http-listening/custom-httpserver/multi/main.go +++ b/_examples/http-listening/custom-httpserver/multi/main.go @@ -4,17 +4,16 @@ import ( "net/http" "github.com/kataras/iris" - "github.com/kataras/iris/context" ) func main() { app := iris.New() - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.Writef("Hello from the server") }) - app.Get("/mypath", func(ctx context.Context) { + app.Get("/mypath", func(ctx iris.Context) { ctx.Writef("Hello from %s", ctx.Path()) }) diff --git a/_examples/http-listening/custom-httpserver/std-way/main.go b/_examples/http-listening/custom-httpserver/std-way/main.go index 3396f007..d3551836 100644 --- a/_examples/http-listening/custom-httpserver/std-way/main.go +++ b/_examples/http-listening/custom-httpserver/std-way/main.go @@ -4,17 +4,16 @@ import ( "net/http" "github.com/kataras/iris" - "github.com/kataras/iris/context" ) func main() { app := iris.New() - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.Writef("Hello from the server") }) - app.Get("/mypath", func(ctx context.Context) { + app.Get("/mypath", func(ctx iris.Context) { ctx.Writef("Hello from %s", ctx.Path()) }) diff --git a/_examples/http-listening/custom-listener/main.go b/_examples/http-listening/custom-listener/main.go index a8a77a27..90d86214 100644 --- a/_examples/http-listening/custom-listener/main.go +++ b/_examples/http-listening/custom-listener/main.go @@ -4,17 +4,16 @@ import ( "net" "github.com/kataras/iris" - "github.com/kataras/iris/context" ) func main() { app := iris.New() - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.Writef("Hello from the server") }) - app.Get("/mypath", func(ctx context.Context) { + app.Get("/mypath", func(ctx iris.Context) { ctx.Writef("Hello from %s", ctx.Path()) }) diff --git a/_examples/http-listening/custom-listener/unix-reuseport/main.go b/_examples/http-listening/custom-listener/unix-reuseport/main.go index 58391233..e9bc96b6 100644 --- a/_examples/http-listening/custom-listener/unix-reuseport/main.go +++ b/_examples/http-listening/custom-listener/unix-reuseport/main.go @@ -17,7 +17,6 @@ import ( "github.com/valyala/tcplisten" "github.com/kataras/iris" - "github.com/kataras/iris/context" ) // $ go get github.com/valyala/tcplisten @@ -26,7 +25,7 @@ import ( func main() { app := iris.New() - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.HTML("Hello World!") }) diff --git a/_examples/http-listening/graceful-shutdown/custom-notifier/main.go b/_examples/http-listening/graceful-shutdown/custom-notifier/main.go index e808e5dd..f1b38197 100644 --- a/_examples/http-listening/graceful-shutdown/custom-notifier/main.go +++ b/_examples/http-listening/graceful-shutdown/custom-notifier/main.go @@ -8,13 +8,12 @@ import ( "time" "github.com/kataras/iris" - "github.com/kataras/iris/context" ) func main() { app := iris.New() - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.HTML("

hi, I just exist in order to see if the server is closed

") }) diff --git a/_examples/http-listening/graceful-shutdown/default-notifier/main.go b/_examples/http-listening/graceful-shutdown/default-notifier/main.go index c99138f3..0c560136 100644 --- a/_examples/http-listening/graceful-shutdown/default-notifier/main.go +++ b/_examples/http-listening/graceful-shutdown/default-notifier/main.go @@ -5,7 +5,6 @@ import ( "time" "github.com/kataras/iris" - "github.com/kataras/iris/context" ) // Before continue: @@ -26,7 +25,7 @@ func main() { app.Shutdown(ctx) }) - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.HTML("

hi, I just exist in order to see if the server is closed

") }) diff --git a/_examples/http-listening/iris-configurator-and-host-configurator/counter/configurator.go b/_examples/http-listening/iris-configurator-and-host-configurator/counter/configurator.go index 2e367859..72988303 100644 --- a/_examples/http-listening/iris-configurator-and-host-configurator/counter/configurator.go +++ b/_examples/http-listening/iris-configurator-and-host-configurator/counter/configurator.go @@ -4,7 +4,6 @@ import ( "time" "github.com/kataras/iris" - "github.com/kataras/iris/context" "github.com/kataras/iris/core/host" ) @@ -25,7 +24,7 @@ func Configurator(app *iris.Application) { }) // or put the ticker outside of the gofunc and put the configurator before or after the app.Get, outside of this gofunc }() - app.Get("/counter", func(ctx context.Context) { + app.Get("/counter", func(ctx iris.Context) { ctx.Writef("Counter value = %d", counterValue) }) } diff --git a/_examples/http-listening/listen-addr/main.go b/_examples/http-listening/listen-addr/main.go index a8ae8398..aef4e86c 100644 --- a/_examples/http-listening/listen-addr/main.go +++ b/_examples/http-listening/listen-addr/main.go @@ -2,13 +2,12 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" ) func main() { app := iris.New() - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.HTML("

Hello World!

") }) diff --git a/_examples/http-listening/listen-addr/omit-server-errors/main.go b/_examples/http-listening/listen-addr/omit-server-errors/main.go index a58f5b11..db2e01bf 100644 --- a/_examples/http-listening/listen-addr/omit-server-errors/main.go +++ b/_examples/http-listening/listen-addr/omit-server-errors/main.go @@ -2,13 +2,12 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" ) func main() { app := iris.New() - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.HTML("

Hello World!

") }) diff --git a/_examples/http-listening/listen-letsencrypt/main.go b/_examples/http-listening/listen-letsencrypt/main.go index 01e02ff4..bf325288 100644 --- a/_examples/http-listening/listen-letsencrypt/main.go +++ b/_examples/http-listening/listen-letsencrypt/main.go @@ -3,21 +3,20 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" ) func main() { app := iris.New() - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.Writef("Hello from SECURE SERVER!") }) - app.Get("/test2", func(ctx context.Context) { + app.Get("/test2", func(ctx iris.Context) { ctx.Writef("Welcome to secure server from /test2!") }) - app.Get("/redirect", func(ctx context.Context) { + app.Get("/redirect", func(ctx iris.Context) { ctx.Redirect("/test2") }) diff --git a/_examples/http-listening/listen-tls/main.go b/_examples/http-listening/listen-tls/main.go index b82391b7..04b57de6 100644 --- a/_examples/http-listening/listen-tls/main.go +++ b/_examples/http-listening/listen-tls/main.go @@ -4,7 +4,6 @@ import ( "net/url" "github.com/kataras/iris" - "github.com/kataras/iris/context" "github.com/kataras/iris/core/host" ) @@ -12,11 +11,11 @@ import ( func main() { app := iris.New() - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.Writef("Hello from the SECURE server") }) - app.Get("/mypath", func(ctx context.Context) { + app.Get("/mypath", func(ctx iris.Context) { ctx.Writef("Hello from the SECURE server on path /mypath") }) diff --git a/_examples/http-listening/notify-on-shutdown/main.go b/_examples/http-listening/notify-on-shutdown/main.go index 41996e7e..67400aa8 100644 --- a/_examples/http-listening/notify-on-shutdown/main.go +++ b/_examples/http-listening/notify-on-shutdown/main.go @@ -5,14 +5,13 @@ import ( "time" "github.com/kataras/iris" - "github.com/kataras/iris/context" "github.com/kataras/iris/core/host" ) func main() { app := iris.New() - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.HTML("

Hello, try to refresh the page after ~10 secs

") }) diff --git a/_examples/http_request/read-form/main.go b/_examples/http_request/read-form/main.go index 6957bf42..3b277a87 100644 --- a/_examples/http_request/read-form/main.go +++ b/_examples/http_request/read-form/main.go @@ -3,8 +3,6 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" - "github.com/kataras/iris/view" ) type Visitor struct { @@ -17,16 +15,16 @@ func main() { app := iris.New() // set the view html template engine - app.RegisterView(view.HTML("./templates", ".html").Reload(true)) + app.RegisterView(iris.HTML("./templates", ".html").Reload(true)) - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { if err := ctx.View("form.html"); err != nil { ctx.StatusCode(iris.StatusInternalServerError) ctx.WriteString(err.Error()) } }) - app.Post("/form_action", func(ctx context.Context) { + app.Post("/form_action", func(ctx iris.Context) { visitor := Visitor{} err := ctx.ReadForm(&visitor) if err != nil { diff --git a/_examples/http_request/read-json/main.go b/_examples/http_request/read-json/main.go index c565315d..b90f9da7 100644 --- a/_examples/http_request/read-json/main.go +++ b/_examples/http_request/read-json/main.go @@ -2,7 +2,6 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" ) type Company struct { @@ -11,7 +10,7 @@ type Company struct { Other string } -func MyHandler(ctx context.Context) { +func MyHandler(ctx iris.Context) { c := &Company{} if err := ctx.ReadJSON(c); err != nil { ctx.StatusCode(iris.StatusBadRequest) diff --git a/_examples/http_request/request-logger/main.go b/_examples/http_request/request-logger/main.go index 1239dc54..24c43794 100644 --- a/_examples/http_request/request-logger/main.go +++ b/_examples/http_request/request-logger/main.go @@ -2,7 +2,6 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" "github.com/kataras/iris/middleware/logger" ) @@ -28,7 +27,7 @@ func main() { app.Use(customLogger) - h := func(ctx context.Context) { + h := func(ctx iris.Context) { ctx.Writef("Hello from %s", ctx.Path()) } app.Get("/", h) @@ -40,12 +39,12 @@ func main() { // http errors have their own handlers, therefore // registering a middleare should be done manually. /* - app.OnErrorCode(404 ,customLogger, func(ctx context.Context) { + app.OnErrorCode(404 ,customLogger, func(ctx iris.Context) { ctx.Writef("My Custom 404 error page ") }) */ // or catch all http errors: - app.OnAnyErrorCode(customLogger, func(ctx context.Context) { + app.OnAnyErrorCode(customLogger, func(ctx iris.Context) { // this should be added to the logs, at the end because of the `logger.Config#MessageContextKey` ctx.Values().Set("logger_message", "a dynamic message passed to the logs") diff --git a/_examples/http_request/request-logger/request-logger-file/main.go b/_examples/http_request/request-logger/request-logger-file/main.go index 21fcf3d1..ed5d7043 100644 --- a/_examples/http_request/request-logger/request-logger-file/main.go +++ b/_examples/http_request/request-logger/request-logger-file/main.go @@ -6,7 +6,6 @@ import ( "time" "github.com/kataras/iris" - "github.com/kataras/iris/context" "github.com/kataras/iris/middleware/logger" ) @@ -18,11 +17,11 @@ func main() { defer close() app.Use(r) - app.OnAnyErrorCode(r, func(ctx context.Context) { + app.OnAnyErrorCode(r, func(ctx iris.Context) { ctx.HTML("

Error: Please try this instead.

") }) - h := func(ctx context.Context) { + h := func(ctx iris.Context) { ctx.Writef("Hello from %s", ctx.Path()) } @@ -66,7 +65,7 @@ var excludeExtensions = [...]string{ ".svg", } -func newRequestLogger() (h context.Handler, close func() error) { +func newRequestLogger() (h iris.Handler, close func() error) { close = func() error { return nil } c := logger.Config{ @@ -93,7 +92,7 @@ func newRequestLogger() (h context.Handler, close func() error) { // we don't want to use the logger // to log requests to assets and etc - c.AddSkipper(func(ctx context.Context) bool { + c.AddSkipper(func(ctx iris.Context) bool { path := ctx.Path() for _, ext := range excludeExtensions { if strings.HasSuffix(path, ext) { diff --git a/_examples/http_request/upload-files/main.go b/_examples/http_request/upload-files/main.go index f6ff3763..a9d574e0 100644 --- a/_examples/http_request/upload-files/main.go +++ b/_examples/http_request/upload-files/main.go @@ -9,17 +9,15 @@ import ( "time" "github.com/kataras/iris" - "github.com/kataras/iris/context" - "github.com/kataras/iris/view" ) func main() { app := iris.New() - app.RegisterView(view.HTML("./templates", ".html")) + app.RegisterView(iris.HTML("./templates", ".html")) // Serve the form.html to the user - app.Get("/upload", func(ctx context.Context) { + app.Get("/upload", func(ctx iris.Context) { //create a token (optionally) now := time.Now().Unix() @@ -33,8 +31,8 @@ func main() { }) // Handle the post request from the upload_form.html to the server - app.Post("/upload", context.LimitRequestBodySize(10<<20), - func(ctx context.Context) { + app.Post("/upload", iris.LimitRequestBodySize(10<<20), + func(ctx iris.Context) { // or use ctx.SetMaxRequestBodySize(10 << 20) //to limit the uploaded file(s) size. diff --git a/_examples/http_responsewriter/quicktemplate/controllers/execute_template.go b/_examples/http_responsewriter/quicktemplate/controllers/execute_template.go index fbe39872..320063dd 100644 --- a/_examples/http_responsewriter/quicktemplate/controllers/execute_template.go +++ b/_examples/http_responsewriter/quicktemplate/controllers/execute_template.go @@ -3,11 +3,11 @@ package controllers import ( "github.com/kataras/iris/_examples/http_responsewriter/quicktemplate/templates" - "github.com/kataras/iris/context" + "github.com/kataras/iris" ) // ExecuteTemplate renders a "tmpl" partial template to the `context#ResponseWriter`. -func ExecuteTemplate(ctx context.Context, tmpl templates.Partial) { +func ExecuteTemplate(ctx iris.Context, tmpl templates.Partial) { ctx.Gzip(true) ctx.ContentType("text/html") templates.WriteTemplate(ctx.ResponseWriter(), tmpl) diff --git a/_examples/http_responsewriter/quicktemplate/controllers/hello.go b/_examples/http_responsewriter/quicktemplate/controllers/hello.go index e95262ec..2c73e1da 100644 --- a/_examples/http_responsewriter/quicktemplate/controllers/hello.go +++ b/_examples/http_responsewriter/quicktemplate/controllers/hello.go @@ -3,11 +3,11 @@ package controllers import ( "github.com/kataras/iris/_examples/http_responsewriter/quicktemplate/templates" - "github.com/kataras/iris/context" + "github.com/kataras/iris" ) // Hello renders our ../templates/hello.qtpl file using the compiled ../templates/hello.qtpl.go file. -func Hello(ctx context.Context) { +func Hello(ctx iris.Context) { // vars := make(map[string]interface{}) // vars["message"] = "Hello World!" // vars["name"] = ctx.Params().Get("name") diff --git a/_examples/http_responsewriter/quicktemplate/controllers/index.go b/_examples/http_responsewriter/quicktemplate/controllers/index.go index 2462a8c3..6809b4a6 100644 --- a/_examples/http_responsewriter/quicktemplate/controllers/index.go +++ b/_examples/http_responsewriter/quicktemplate/controllers/index.go @@ -3,11 +3,11 @@ package controllers import ( "github.com/kataras/iris/_examples/http_responsewriter/quicktemplate/templates" - "github.com/kataras/iris/context" + "github.com/kataras/iris" ) // Index renders our ../templates/index.qtpl file using the compiled ../templates/index.qtpl.go file. -func Index(ctx context.Context) { +func Index(ctx iris.Context) { tmpl := &templates.Index{} // render the template diff --git a/_examples/http_responsewriter/stream-writer/main.go b/_examples/http_responsewriter/stream-writer/main.go index 5e290fd5..ac6f178d 100644 --- a/_examples/http_responsewriter/stream-writer/main.go +++ b/_examples/http_responsewriter/stream-writer/main.go @@ -6,7 +6,6 @@ import ( "time" // showcase the delay "github.com/kataras/iris" - "github.com/kataras/iris/context" ) func main() { @@ -14,7 +13,7 @@ func main() { timeWaitForCloseStream := 4 * time.Second - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { i := 0 // goroutine in order to no block and just wait, // goroutine is OPTIONAL and not a very good option but it depends on the needs @@ -35,7 +34,7 @@ func main() { time.Sleep(timeWaitForCloseStream) }) - app.Get("/alternative", func(ctx context.Context) { + app.Get("/alternative", func(ctx iris.Context) { // Send the response in chunks and wait for a second between each chunk. ctx.StreamWriter(func(w io.Writer) bool { for i := 1; i <= 4; i++ { diff --git a/_examples/http_responsewriter/write-rest/main.go b/_examples/http_responsewriter/write-rest/main.go index d3d35d71..7527b1e8 100644 --- a/_examples/http_responsewriter/write-rest/main.go +++ b/_examples/http_responsewriter/write-rest/main.go @@ -26,7 +26,7 @@ func main() { app := iris.New() // Read - app.Post("/decode", func(ctx context.Context) { + app.Post("/decode", func(ctx iris.Context) { var user User ctx.ReadJSON(&user) @@ -34,7 +34,7 @@ func main() { }) // Write - app.Get("/encode", func(ctx context.Context) { + app.Get("/encode", func(ctx iris.Context) { peter := User{ Firstname: "John", Lastname: "Doe", @@ -48,28 +48,28 @@ func main() { // Other content types, - app.Get("/binary", func(ctx context.Context) { + app.Get("/binary", func(ctx iris.Context) { // useful when you want force-download of contents of raw bytes form. ctx.Binary([]byte("Some binary data here.")) }) - app.Get("/text", func(ctx context.Context) { + app.Get("/text", func(ctx iris.Context) { ctx.Text("Plain text here") }) - app.Get("/json", func(ctx context.Context) { + app.Get("/json", func(ctx iris.Context) { ctx.JSON(map[string]string{"hello": "json"}) // or myjsonStruct{hello:"json} }) - app.Get("/jsonp", func(ctx context.Context) { + app.Get("/jsonp", func(ctx iris.Context) { ctx.JSONP(map[string]string{"hello": "jsonp"}, context.JSONP{Callback: "callbackName"}) }) - app.Get("/xml", func(ctx context.Context) { - ctx.XML(ExampleXML{One: "hello", Two: "xml"}) // or context.Map{"One":"hello"...} + app.Get("/xml", func(ctx iris.Context) { + ctx.XML(ExampleXML{One: "hello", Two: "xml"}) // or iris.Map{"One":"hello"...} }) - app.Get("/markdown", func(ctx context.Context) { + app.Get("/markdown", func(ctx iris.Context) { ctx.Markdown([]byte("# Hello Dynamic Markdown -- iris")) }) diff --git a/_examples/miscellaneous/file-logger/main.go b/_examples/miscellaneous/file-logger/main.go index bd82c982..59b98a1d 100644 --- a/_examples/miscellaneous/file-logger/main.go +++ b/_examples/miscellaneous/file-logger/main.go @@ -5,7 +5,6 @@ import ( "time" "github.com/kataras/iris" - "github.com/kataras/iris/context" ) // get a filename based on the date, file logs works that way the most times @@ -34,7 +33,7 @@ func main() { // attach the file as logger, remember, iris' app logger is just an io.Writer. app.Logger().SetOutput(newLogFile()) - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { // for the sake of simplicity, in order see the logs at the ./_today_.txt ctx.Application().Logger().Info("Request path: " + ctx.Path()) ctx.Writef("hello") diff --git a/_examples/miscellaneous/i18n/main.go b/_examples/miscellaneous/i18n/main.go index f56cf263..53e653d2 100644 --- a/_examples/miscellaneous/i18n/main.go +++ b/_examples/miscellaneous/i18n/main.go @@ -2,7 +2,6 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" "github.com/kataras/iris/middleware/i18n" ) @@ -17,7 +16,7 @@ func newApp() *iris.Application { "el-GR": "./locales/locale_el-GR.ini", "zh-CN": "./locales/locale_zh-CN.ini"}})) - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { // it tries to find the language by: // ctx.Values().GetString("language") diff --git a/_examples/miscellaneous/pprof/main.go b/_examples/miscellaneous/pprof/main.go index bf688f87..2b2a79e9 100644 --- a/_examples/miscellaneous/pprof/main.go +++ b/_examples/miscellaneous/pprof/main.go @@ -2,7 +2,6 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" "github.com/kataras/iris/middleware/pprof" ) @@ -10,7 +9,7 @@ import ( func main() { app := iris.New() - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.HTML("

Please click here") }) diff --git a/_examples/miscellaneous/recaptcha/main.go b/_examples/miscellaneous/recaptcha/main.go index 440b52cd..e4b8c97f 100644 --- a/_examples/miscellaneous/recaptcha/main.go +++ b/_examples/miscellaneous/recaptcha/main.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/kataras/iris" - "github.com/kataras/iris/context" "github.com/kataras/iris/middleware/recaptcha" ) @@ -34,12 +33,12 @@ var htmlForm = `
` -func showRecaptchaForm(ctx context.Context) { +func showRecaptchaForm(ctx iris.Context) { contents := fmt.Sprintf(htmlForm, publicDataSiteKey) ctx.HTML(contents) } -func postComment(ctx context.Context) { +func postComment(ctx iris.Context) { // [...] - ctx.JSON(context.Map{"success": true}) + ctx.JSON(iris.Map{"success": true}) } diff --git a/_examples/miscellaneous/recover/main.go b/_examples/miscellaneous/recover/main.go index 95206cd0..a366f3b5 100644 --- a/_examples/miscellaneous/recover/main.go +++ b/_examples/miscellaneous/recover/main.go @@ -2,7 +2,6 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" "github.com/kataras/iris/middleware/recover" ) @@ -14,7 +13,7 @@ func main() { i := 0 // let's simmilate a panic every next request - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { i++ if i%2 == 0 { panic("a panic here") diff --git a/_examples/mvc/login/user/auth.go b/_examples/mvc/login/user/auth.go index c4d9a5f6..ba7c0053 100644 --- a/_examples/mvc/login/user/auth.go +++ b/_examples/mvc/login/user/auth.go @@ -5,7 +5,7 @@ import ( "strconv" "strings" - "github.com/kataras/iris/context" + "github.com/kataras/iris" "github.com/kataras/iris/mvc" ) @@ -29,7 +29,7 @@ type AuthController struct { } // BeginRequest saves login state to the context, the user id. -func (c *AuthController) BeginRequest(ctx context.Context) { +func (c *AuthController) BeginRequest(ctx iris.Context) { c.SessionController.BeginRequest(ctx) if userID := c.Session.Get(sessionIDKey); userID != nil { @@ -116,7 +116,7 @@ func (c *AuthController) logout() { // AllowUser will check if this client is a logged user, // if not then it will redirect that guest to the login page // otherwise it will allow the execution of the next handler. -func AllowUser(ctx context.Context) { +func AllowUser(ctx iris.Context) { if ctx.Values().Get(sessionIDKey) != nil { ctx.Next() return diff --git a/_examples/orm/xorm/main.go b/_examples/orm/xorm/main.go index fc1b1687..c8c3e08a 100644 --- a/_examples/orm/xorm/main.go +++ b/_examples/orm/xorm/main.go @@ -6,7 +6,6 @@ import ( "time" "github.com/kataras/iris" - "github.com/kataras/iris/context" "github.com/go-xorm/xorm" _ "github.com/mattn/go-sqlite3" @@ -55,14 +54,14 @@ func main() { app.Logger().Fatalf("orm failed to initialized User table: %v", err) } - app.Get("/insert", func(ctx context.Context) { + app.Get("/insert", func(ctx iris.Context) { user := &User{Username: "kataras", Salt: "hash---", Password: "hashed", CreatedAt: time.Now(), UpdatedAt: time.Now()} orm.Insert(user) ctx.Writef("user inserted: %#v", user) }) - app.Get("/get", func(ctx context.Context) { + app.Get("/get", func(ctx iris.Context) { user := User{ID: 1} if ok, _ := orm.Get(&user); ok { ctx.Writef("user found: %#v", user) diff --git a/_examples/overview/main.go b/_examples/overview/main.go index f7e17edd..e7d34193 100644 --- a/_examples/overview/main.go +++ b/_examples/overview/main.go @@ -2,8 +2,6 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" - "github.com/kataras/iris/view" ) // User is just a bindable object structure. @@ -22,10 +20,10 @@ func main() { // Define templates using the std html/template engine. // Parse and load all files inside "./views" folder with ".html" file extension. // Reload the templates on each request (development mode). - app.RegisterView(view.HTML("./views", ".html").Reload(true)) + app.RegisterView(iris.HTML("./views", ".html").Reload(true)) // Register custom handler for specific http errors. - app.OnErrorCode(iris.StatusInternalServerError, func(ctx context.Context) { + app.OnErrorCode(iris.StatusInternalServerError, func(ctx iris.Context) { // .Values are used to communicate between handlers, middleware. errMessage := ctx.Values().GetString("error") if errMessage != "" { @@ -36,22 +34,22 @@ func main() { ctx.Writef("(Unexpected) internal server error") }) - app.Use(func(ctx context.Context) { + app.Use(func(ctx iris.Context) { ctx.Application().Logger().Infof("Begin request for path: %s", ctx.Path()) ctx.Next() }) - // app.Done(func(ctx context.Context) {]}) - app.Subdomain("wtf.").Post("/decode", func(ctx context.Context) {}) - app.Subdomain("wtf.").Post("/decode", func(ctx context.Context) {}) + // app.Done(func(ctx iris.Context) {]}) + app.Subdomain("wtf.").Post("/decode", func(ctx iris.Context) {}) + app.Subdomain("wtf.").Post("/decode", func(ctx iris.Context) {}) // Method POST: http://localhost:8080/decode - app.Post("/decode", func(ctx context.Context) { + app.Post("/decode", func(ctx iris.Context) { var user User ctx.ReadJSON(&user) ctx.Writef("%s %s is %d years old and comes from %s", user.Firstname, user.Lastname, user.Age, user.City) }) // Method GET: http://localhost:8080/encode - app.Get("/encode", func(ctx context.Context) { + app.Get("/encode", func(ctx iris.Context) { doe := User{ Username: "Johndoe", Firstname: "John", @@ -78,7 +76,7 @@ func main() { app.Run(iris.Addr(":8080"), iris.WithCharset("UTF-8")) } -func logThisMiddleware(ctx context.Context) { +func logThisMiddleware(ctx iris.Context) { ctx.Application().Logger().Infof("Path: %s | IP: %s", ctx.Path(), ctx.RemoteAddr()) // .Next is required to move forward to the chain of handlers, @@ -86,7 +84,7 @@ func logThisMiddleware(ctx context.Context) { ctx.Next() } -func profileByUsername(ctx context.Context) { +func profileByUsername(ctx iris.Context) { // .Params are used to get dynamic path parameters. username := ctx.Params().Get("username") ctx.ViewData("Username", username) @@ -95,7 +93,7 @@ func profileByUsername(ctx context.Context) { ctx.View("users/profile.html") } -func getUserByID(ctx context.Context) { +func getUserByID(ctx iris.Context) { userID := ctx.Params().Get("id") // Or convert directly using: .Values().GetInt/GetInt64 etc... // your own db fetch here instead of user :=... user := User{Username: "username" + userID} @@ -103,7 +101,7 @@ func getUserByID(ctx context.Context) { ctx.XML(user) } -func createUser(ctx context.Context) { +func createUser(ctx iris.Context) { var user User err := ctx.ReadForm(&user) if err != nil { diff --git a/_examples/routing/basic/main.go b/_examples/routing/basic/main.go index 88ed1108..d694b20c 100644 --- a/_examples/routing/basic/main.go +++ b/_examples/routing/basic/main.go @@ -2,7 +2,6 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" ) func main() { @@ -14,23 +13,23 @@ func main() { // GET -> HTTP Method // / -> Path - // func(ctx context.Context) -> The route's handler. + // func(ctx iris.Context) -> The route's handler. // // Third receiver should contains the route's handler(s), they are executed by order. - app.Handle("GET", "/", func(ctx context.Context) { + app.Handle("GET", "/", func(ctx iris.Context) { // navigate to the middle of $GOPATH/src/github.com/kataras/iris/context/context.go // to overview all context's method (there a lot of them, read that and you will learn how iris works too) ctx.HTML("Hello from " + ctx.Path()) // Hello from / }) - app.Get("/home", func(ctx context.Context) { + app.Get("/home", func(ctx iris.Context) { ctx.Writef(`Same as app.Handle("GET", "/", [...])`) }) app.Get("/donate", donateHandler, donateFinishHandler) // Pssst, don't forget dynamic-path example for more "magic"! - app.Get("/api/users/{userid:int min(1)}", func(ctx context.Context) { + app.Get("/api/users/{userid:int min(1)}", func(ctx iris.Context) { userID, err := ctx.Params().GetInt("userid") if err != nil { @@ -45,15 +44,15 @@ func main() { "user_id": userID, }) }) - // app.Post("/", func(ctx context.Context){}) -> for POST http method. - // app.Put("/", func(ctx context.Context){})-> for "PUT" http method. - // app.Delete("/", func(ctx context.Context){})-> for "DELETE" http method. - // app.Options("/", func(ctx context.Context){})-> for "OPTIONS" http method. - // app.Trace("/", func(ctx context.Context){})-> for "TRACE" http method. - // app.Head("/", func(ctx context.Context){})-> for "HEAD" http method. - // app.Connect("/", func(ctx context.Context){})-> for "CONNECT" http method. - // app.Patch("/", func(ctx context.Context){})-> for "PATCH" http method. - // app.Any("/", func(ctx context.Context){}) for all http methods. + // app.Post("/", func(ctx iris.Context){}) -> for POST http method. + // app.Put("/", func(ctx iris.Context){})-> for "PUT" http method. + // app.Delete("/", func(ctx iris.Context){})-> for "DELETE" http method. + // app.Options("/", func(ctx iris.Context){})-> for "OPTIONS" http method. + // app.Trace("/", func(ctx iris.Context){})-> for "TRACE" http method. + // app.Head("/", func(ctx iris.Context){})-> for "HEAD" http method. + // app.Connect("/", func(ctx iris.Context){})-> for "CONNECT" http method. + // app.Patch("/", func(ctx iris.Context){})-> for "PATCH" http method. + // app.Any("/", func(ctx iris.Context){}) for all http methods. // More than one route can contain the same path with a different http mapped method. // You can catch any route creation errors with: @@ -64,13 +63,13 @@ func main() { adminRoutes := app.Party("/admin", adminMiddleware) - adminRoutes.Done(func(ctx context.Context) { // executes always last if ctx.Next() + adminRoutes.Done(func(ctx iris.Context) { // executes always last if ctx.Next() ctx.Application().Logger().Infof("response sent to " + ctx.Path()) }) // adminRoutes.Layout("/views/layouts/admin.html") // set a view layout for these routes, see more at view examples. // GET: http://localhost:8080/admin - adminRoutes.Get("/", func(ctx context.Context) { + adminRoutes.Get("/", func(ctx iris.Context) { // [...] ctx.StatusCode(iris.StatusOK) // default is 200 == iris.StatusOK ctx.HTML("

Hello from admin/

") @@ -79,11 +78,11 @@ func main() { }) // GET: http://localhost:8080/admin/login - adminRoutes.Get("/login", func(ctx context.Context) { + adminRoutes.Get("/login", func(ctx iris.Context) { // [...] }) // POST: http://localhost:8080/admin/login - adminRoutes.Post("/login", func(ctx context.Context) { + adminRoutes.Post("/login", func(ctx iris.Context) { // [...] }) @@ -93,18 +92,18 @@ func main() { { // braces are optional, it's just type of style, to group the routes visually. // http://v1.localhost:8080 - v1.Get("/", func(ctx context.Context) { + v1.Get("/", func(ctx iris.Context) { ctx.HTML("Version 1 API. go to /api/users") }) usersAPI := v1.Party("/api/users") { // http://v1.localhost:8080/api/users - usersAPI.Get("/", func(ctx context.Context) { + usersAPI.Get("/", func(ctx iris.Context) { ctx.Writef("All users") }) // http://v1.localhost:8080/api/users/42 - usersAPI.Get("/{userid:int}", func(ctx context.Context) { + usersAPI.Get("/{userid:int}", func(ctx iris.Context) { ctx.Writef("user with id: %s", ctx.Params().Get("userid")) }) } @@ -113,7 +112,7 @@ func main() { // wildcard subdomains. wildcardSubdomain := app.Party("*.") { - wildcardSubdomain.Get("/", func(ctx context.Context) { + wildcardSubdomain.Get("/", func(ctx iris.Context) { ctx.Writef("Subdomain can be anything, now you're here from: %s", ctx.Subdomain()) }) } @@ -137,22 +136,22 @@ func main() { app.Run(iris.Addr(":8080")) } -func adminMiddleware(ctx context.Context) { +func adminMiddleware(ctx iris.Context) { // [...] ctx.Next() // to move to the next handler, or don't that if you have any auth logic. } -func donateHandler(ctx context.Context) { +func donateHandler(ctx iris.Context) { ctx.Writef("Just like an inline handler, but it can be " + "used by other package, anywhere in your project.") // let's pass a value to the next handler // Values is the way handlers(or middleware) are communicating between each other. - ctx.Values().Set("donate_url", "https://github.com/kataras/iris#buy-me-a-cup-of-coffee") + ctx.Values().Set("donate_url", "https://github.com/kataras/iris#-people") ctx.Next() // in order to execute the next handler in the chain, look donate route. } -func donateFinishHandler(ctx context.Context) { +func donateFinishHandler(ctx iris.Context) { // values can be any type of object so we could cast the value to a string // but iris provides an easy to do that, if donate_url is not defined, then it returns an empty string instead. donateURL := ctx.Values().GetString("donate_url") @@ -160,7 +159,7 @@ func donateFinishHandler(ctx context.Context) { ctx.Writef("\n\nDonate sent(?).") } -func notFoundHandler(ctx context.Context) { +func notFoundHandler(ctx iris.Context) { ctx.HTML("Custom route for 404 not found http code, here you can render a view, html, json any valid response.") } diff --git a/_examples/routing/custom-context/new-implementation/main.go b/_examples/routing/custom-context/new-implementation/main.go index 0b46c603..fd3ba49a 100644 --- a/_examples/routing/custom-context/new-implementation/main.go +++ b/_examples/routing/custom-context/new-implementation/main.go @@ -4,7 +4,6 @@ import ( "sync" "github.com/kataras/iris" - "github.com/kataras/iris/context" "github.com/kataras/iris/sessions" ) @@ -25,7 +24,7 @@ var owner = &Owner{ // Let's implement a context which will give us access // to the client's Session with a trivial `ctx.Session()` call. type Context struct { - context.Context + iris.Context session *sessions.Session } @@ -49,7 +48,7 @@ var contextPool = sync.Pool{New: func() interface{} { return &Context{} }} -func acquire(original context.Context) *Context { +func acquire(original iris.Context) *Context { ctx := contextPool.Get().(*Context) ctx.Context = original // set the context to the original one in order to have access to iris's implementation. ctx.session = nil // reset the session @@ -62,8 +61,8 @@ func release(ctx *Context) { // Handler will convert our handler of func(*Context) to an iris Handler, // in order to be compatible with the HTTP API. -func Handler(h func(*Context)) context.Handler { - return func(original context.Context) { +func Handler(h func(*Context)) iris.Handler { + return func(original iris.Context) { ctx := acquire(original) h(ctx) release(ctx) diff --git a/_examples/routing/custom-wrapper/main.go b/_examples/routing/custom-wrapper/main.go index 97dbe3b1..dfcd0402 100644 --- a/_examples/routing/custom-wrapper/main.go +++ b/_examples/routing/custom-wrapper/main.go @@ -5,7 +5,6 @@ import ( "strings" "github.com/kataras/iris" - "github.com/kataras/iris/context" ) // In this example you'll just see one use case of .WrapRouter. @@ -20,15 +19,15 @@ func newApp() *iris.Application { app := iris.New() - app.OnErrorCode(iris.StatusNotFound, func(ctx context.Context) { + app.OnErrorCode(iris.StatusNotFound, func(ctx iris.Context) { ctx.HTML("Resource Not found") }) - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.ServeFile("./public/index.html", false) }) - app.Get("/profile/{username}", func(ctx context.Context) { + app.Get("/profile/{username}", func(ctx iris.Context) { ctx.Writef("Hello %s", ctx.Params().Get("username")) }) diff --git a/_examples/routing/dynamic-path/main.go b/_examples/routing/dynamic-path/main.go index efc201c0..8eaf004d 100644 --- a/_examples/routing/dynamic-path/main.go +++ b/_examples/routing/dynamic-path/main.go @@ -4,7 +4,6 @@ import ( "strconv" "github.com/kataras/iris" - "github.com/kataras/iris/context" ) func main() { @@ -15,7 +14,7 @@ func main() { // with a single known paramete and custom http errors, now it's time to see wildcard parameters and macros. // iris, like net/http std package registers route's handlers - // by a Handler, the iris' type of handler is just a func(ctx context.Context) + // by a Handler, the iris' type of handler is just a func(ctx iris.Context) // where context comes from github.com/kataras/iris/context. // Until go 1.9 you will have to import that package too, after go 1.9 this will be not be necessary. // @@ -92,7 +91,7 @@ func main() { // }) // you can use the "string" type which is valid for a single path parameter that can be anything. - app.Get("/username/{name}", func(ctx context.Context) { + app.Get("/username/{name}", func(ctx iris.Context) { ctx.Writef("Hello %s", ctx.Params().Get("name")) }) // type is missing = {name:string} @@ -116,7 +115,7 @@ func main() { // http://localhost:8080/profile/id>=1 // this will throw 404 even if it's found as route on : /profile/0, /profile/blabla, /profile/-1 // macro parameter functions are optional of course. - app.Get("/profile/{id:int min(1)}", func(ctx context.Context) { + app.Get("/profile/{id:int min(1)}", func(ctx iris.Context) { // second parameter is the error but it will always nil because we use macros, // the validaton already happened. id, _ := ctx.Params().GetInt("id") @@ -124,7 +123,7 @@ func main() { }) // to change the error code per route's macro evaluator: - app.Get("/profile/{id:int min(1)}/friends/{friendid:int min(1) else 504}", func(ctx context.Context) { + app.Get("/profile/{id:int min(1)}/friends/{friendid:int min(1) else 504}", func(ctx iris.Context) { id, _ := ctx.Params().GetInt("id") friendid, _ := ctx.Params().GetInt("friendid") ctx.Writef("Hello id: %d looking for friend id: ", id, friendid) @@ -132,11 +131,11 @@ func main() { // http://localhost:8080/game/a-zA-Z/level/0-9 // remember, alphabetical is lowercase or uppercase letters only. - app.Get("/game/{name:alphabetical}/level/{level:int}", func(ctx context.Context) { + app.Get("/game/{name:alphabetical}/level/{level:int}", func(ctx iris.Context) { ctx.Writef("name: %s | level: %s", ctx.Params().Get("name"), ctx.Params().Get("level")) }) - app.Get("/lowercase/static", func(ctx context.Context) { + app.Get("/lowercase/static", func(ctx iris.Context) { ctx.Writef("static and dynamic paths are not conflicted anymore!") }) @@ -144,18 +143,18 @@ func main() { // which its value is only lowercase letters. // http://localhost:8080/lowercase/anylowercase - app.Get("/lowercase/{name:string regexp(^[a-z]+)}", func(ctx context.Context) { + app.Get("/lowercase/{name:string regexp(^[a-z]+)}", func(ctx iris.Context) { ctx.Writef("name should be only lowercase, otherwise this handler will never executed: %s", ctx.Params().Get("name")) }) // http://localhost:8080/single_file/app.js - app.Get("/single_file/{myfile:file}", func(ctx context.Context) { + app.Get("/single_file/{myfile:file}", func(ctx iris.Context) { ctx.Writef("file type validates if the parameter value has a form of a file name, got: %s", ctx.Params().Get("myfile")) }) // http://localhost:8080/myfiles/any/directory/here/ // this is the only macro type that accepts any number of path segments. - app.Get("/myfiles/{directory:path}", func(ctx context.Context) { + app.Get("/myfiles/{directory:path}", func(ctx iris.Context) { ctx.Writef("path type accepts any number of path segments, path after /myfiles/ is: %s", ctx.Params().Get("directory")) }) // for wildcard path (any number of path segments) without validation you can use: // /myfiles/* diff --git a/_examples/routing/dynamic-path/root-wildcard/main.go b/_examples/routing/dynamic-path/root-wildcard/main.go index 1be0d1ca..bd1b462b 100644 --- a/_examples/routing/dynamic-path/root-wildcard/main.go +++ b/_examples/routing/dynamic-path/root-wildcard/main.go @@ -2,7 +2,6 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" ) func main() { @@ -42,30 +41,30 @@ func main() { app.Run(iris.Addr(":8080"), iris.WithoutServerError(iris.ErrServerClosed)) } -func h(ctx context.Context) { +func h(ctx iris.Context) { param := ctx.Params().Get("p") ctx.WriteString(param) } -func staticWildcardH(ctx context.Context) { +func staticWildcardH(ctx iris.Context) { param := ctx.Params().Get("p") ctx.WriteString("from staticWildcardH: param=" + param) } -func other(ctx context.Context) { +func other(ctx iris.Context) { param := ctx.Params().Get("paramother") ctx.Writef("from other: %s", param) } -func other2(ctx context.Context) { +func other2(ctx iris.Context) { param := ctx.Params().Get("paramothersecond") ctx.Writef("from other2: %s", param) } -func staticPath(ctx context.Context) { +func staticPath(ctx iris.Context) { ctx.Writef("from the static path(/): %s", ctx.Path()) } -func staticPathOther2(ctx context.Context) { +func staticPathOther2(ctx iris.Context) { ctx.Writef("from the static path(/other2/static2): %s", ctx.Path()) } diff --git a/_examples/routing/http-errors/main.go b/_examples/routing/http-errors/main.go index aa020c52..c41dfbf4 100644 --- a/_examples/routing/http-errors/main.go +++ b/_examples/routing/http-errors/main.go @@ -2,26 +2,25 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" ) func main() { app := iris.New() - app.OnErrorCode(iris.StatusInternalServerError, func(ctx context.Context) { + app.OnErrorCode(iris.StatusInternalServerError, func(ctx iris.Context) { ctx.HTML("Message: " + ctx.Values().GetString("message") + "") }) - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.HTML(`Click here to fire the 500 status code`) }) - app.Get("/my500", func(ctx context.Context) { + app.Get("/my500", func(ctx iris.Context) { ctx.Values().Set("message", "this is the error message") ctx.StatusCode(500) }) - app.Get("/u/{firstname:alphabetical}", func(ctx context.Context) { + app.Get("/u/{firstname:alphabetical}", func(ctx iris.Context) { ctx.Writef("Hello %s", ctx.Params().Get("firstname")) }) diff --git a/_examples/routing/main.go b/_examples/routing/main.go index edb76828..738b1ca3 100644 --- a/_examples/routing/main.go +++ b/_examples/routing/main.go @@ -4,7 +4,6 @@ import ( "io/ioutil" "github.com/kataras/iris" - "github.com/kataras/iris/context" ) /* @@ -20,13 +19,13 @@ const notFoundHTML = "

custom http error page

" func registerErrors(app *iris.Application) { // set a custom 404 handler - app.OnErrorCode(iris.StatusNotFound, func(ctx context.Context) { + app.OnErrorCode(iris.StatusNotFound, func(ctx iris.Context) { ctx.HTML(notFoundHTML) }) } func registerGamesRoutes(app *iris.Application) { - gamesMiddleware := func(ctx context.Context) { + gamesMiddleware := func(ctx iris.Context) { ctx.Next() } @@ -107,7 +106,7 @@ func newApp() *iris.Application { // and sends back the same body // remember, we have limit to that body in order // to protect ourselves from "over heating". - app.Post("/", context.LimitRequestBodySize(maxBodySize), func(ctx context.Context) { + app.Post("/", iris.LimitRequestBodySize(maxBodySize), func(ctx iris.Context) { // get request body b, err := ioutil.ReadAll(ctx.Request().Body) // if is larger then send a bad request status @@ -123,7 +122,7 @@ func newApp() *iris.Application { return app } -func h(ctx context.Context) { +func h(ctx iris.Context) { method := ctx.Method() // the http method requested a server's resource. subdomain := ctx.Subdomain() // the subdomain, if any. diff --git a/_examples/routing/overview/main.go b/_examples/routing/overview/main.go index 5b901c1e..80e7133d 100644 --- a/_examples/routing/overview/main.go +++ b/_examples/routing/overview/main.go @@ -2,7 +2,6 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" ) func main() { @@ -44,7 +43,7 @@ func main() { usersRoutes := app.Party("/users") // GET: http://localhost:8080/users/help - usersRoutes.Get("/help", func(ctx context.Context) { + usersRoutes.Get("/help", func(ctx iris.Context) { ctx.Writef("GET / -- fetch all users\n") ctx.Writef("GET /$ID -- fetch a user by id\n") ctx.Writef("POST / -- create new user\n") @@ -53,32 +52,32 @@ func main() { }) // GET: http://localhost:8080/users - usersRoutes.Get("/", func(ctx context.Context) { + usersRoutes.Get("/", func(ctx iris.Context) { ctx.Writef("get all users") }) // GET: http://localhost:8080/users/42 // **/users/42 and /users/help works after iris version 7.0.5** - usersRoutes.Get("/{id:int}", func(ctx context.Context) { + usersRoutes.Get("/{id:int}", func(ctx iris.Context) { id, _ := ctx.Params().GetInt("id") ctx.Writef("get user by id: %d", id) }) // POST: http://localhost:8080/users - usersRoutes.Post("/", func(ctx context.Context) { + usersRoutes.Post("/", func(ctx iris.Context) { username, password := ctx.PostValue("username"), ctx.PostValue("password") ctx.Writef("create user for username= %s and password= %s", username, password) }) // PUT: http://localhost:8080/users - usersRoutes.Put("/{id:int}", func(ctx context.Context) { + usersRoutes.Put("/{id:int}", func(ctx iris.Context) { id, _ := ctx.Params().GetInt("id") // or .Get to get its string represatantion. username := ctx.PostValue("username") ctx.Writef("update user for id= %d and new username= %s", id, username) }) // DELETE: http://localhost:8080/users/42 - usersRoutes.Delete("/{id:int}", func(ctx context.Context) { + usersRoutes.Delete("/{id:int}", func(ctx iris.Context) { id, _ := ctx.Params().GetInt("id") ctx.Writef("delete user by id: %d", id) }) @@ -118,7 +117,7 @@ func main() { } } -func info(ctx context.Context) { +func info(ctx iris.Context) { method := ctx.Method() // the http method requested a server's resource. subdomain := ctx.Subdomain() // the subdomain, if any. diff --git a/_examples/routing/reverse/main.go b/_examples/routing/reverse/main.go index 4bc22eb2..7867be86 100644 --- a/_examples/routing/reverse/main.go +++ b/_examples/routing/reverse/main.go @@ -2,7 +2,6 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" "github.com/kataras/iris/core/router" ) @@ -12,7 +11,7 @@ func main() { // you normally don't need it because of the {{ urlpath "routename" "path" "values" "here"}} rv := router.NewRoutePathReverser(app) - myroute := app.Get("/anything/{anythingparameter:path}", func(ctx context.Context) { + myroute := app.Get("/anything/{anythingparameter:path}", func(ctx iris.Context) { paramValue := ctx.Params().Get("anythingparameter") ctx.Writef("The path after /anything is: %s", paramValue) }) @@ -20,13 +19,13 @@ func main() { myroute.Name = "myroute" // useful for links, although iris' view engine has the {{ urlpath "routename" "path values"}} already. - app.Get("/reverse_myroute", func(ctx context.Context) { + app.Get("/reverse_myroute", func(ctx iris.Context) { myrouteRequestPath := rv.Path(myroute.Name, "any/path") ctx.HTML("Should be /anything/any/path: " + myrouteRequestPath) }) // execute a route, similar to redirect but without redirect :) - app.Get("/execute_myroute", func(ctx context.Context) { + app.Get("/execute_myroute", func(ctx iris.Context) { ctx.Exec("GET", "/anything/any/path") // like it was called by the client. }) diff --git a/_examples/routing/route-state/main.go b/_examples/routing/route-state/main.go index 847e2d41..f85426f8 100644 --- a/_examples/routing/route-state/main.go +++ b/_examples/routing/route-state/main.go @@ -2,13 +2,12 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" ) func main() { app := iris.New() - none := app.None("/invisible/{username}", func(ctx context.Context) { + none := app.None("/invisible/{username}", func(ctx iris.Context) { ctx.Writef("Hello %s with method: %s", ctx.Values().GetString("username"), ctx.Method()) if from := ctx.Values().GetString("from"); from != "" { @@ -16,7 +15,7 @@ func main() { } }) - app.Get("/change", func(ctx context.Context) { + app.Get("/change", func(ctx iris.Context) { if none.IsOnline() { none.Method = iris.MethodNone @@ -28,7 +27,7 @@ func main() { app.RefreshRouter() }) - app.Get("/execute", func(ctx context.Context) { + app.Get("/execute", func(ctx iris.Context) { // same as navigating to "http://localhost:8080/invisible/iris" when /change has being invoked and route state changed // from "offline" to "online" ctx.Values().Set("from", "/execute") // values and session can be shared when calling Exec from a "foreign" context. diff --git a/_examples/sessions/database/boltdb/main.go b/_examples/sessions/database/boltdb/main.go index 7dd7ad30..ebac90f5 100644 --- a/_examples/sessions/database/boltdb/main.go +++ b/_examples/sessions/database/boltdb/main.go @@ -4,7 +4,6 @@ import ( "time" "github.com/kataras/iris" - "github.com/kataras/iris/context" "github.com/kataras/iris/sessions" "github.com/kataras/iris/sessions/sessiondb/boltdb" @@ -33,10 +32,10 @@ func main() { // the rest of the code stays the same. app := iris.New() - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.Writef("You should navigate to the /set, /get, /delete, /clear,/destroy instead") }) - app.Get("/set", func(ctx context.Context) { + app.Get("/set", func(ctx iris.Context) { s := sess.Start(ctx) //set session values s.Set("name", "iris") @@ -45,7 +44,7 @@ func main() { ctx.Writef("All ok session setted to: %s", s.GetString("name")) }) - app.Get("/set/{key}/{value}", func(ctx context.Context) { + app.Get("/set/{key}/{value}", func(ctx iris.Context) { key, value := ctx.Params().Get("key"), ctx.Params().Get("value") s := sess.Start(ctx) // set session values @@ -55,36 +54,36 @@ func main() { ctx.Writef("All ok session setted to: %s", s.GetString(key)) }) - app.Get("/get", func(ctx context.Context) { + app.Get("/get", func(ctx iris.Context) { // get a specific key, as string, if no found returns just an empty string name := sess.Start(ctx).GetString("name") ctx.Writef("The name on the /set was: %s", name) }) - app.Get("/get/{key}", func(ctx context.Context) { + app.Get("/get/{key}", func(ctx iris.Context) { // get a specific key, as string, if no found returns just an empty string name := sess.Start(ctx).GetString(ctx.Params().Get("key")) ctx.Writef("The name on the /set was: %s", name) }) - app.Get("/delete", func(ctx context.Context) { + app.Get("/delete", func(ctx iris.Context) { // delete a specific key sess.Start(ctx).Delete("name") }) - app.Get("/clear", func(ctx context.Context) { + app.Get("/clear", func(ctx iris.Context) { // removes all entries sess.Start(ctx).Clear() }) - app.Get("/destroy", func(ctx context.Context) { + app.Get("/destroy", func(ctx iris.Context) { //destroy, removes the entire session data and cookie sess.Destroy(ctx) }) - app.Get("/update", func(ctx context.Context) { + app.Get("/update", func(ctx iris.Context) { // updates expire date with a new date sess.ShiftExpiration(ctx) }) diff --git a/_examples/sessions/database/file/main.go b/_examples/sessions/database/file/main.go index 27a9bfca..5fce6bf9 100644 --- a/_examples/sessions/database/file/main.go +++ b/_examples/sessions/database/file/main.go @@ -4,7 +4,6 @@ import ( "time" "github.com/kataras/iris" - "github.com/kataras/iris/context" "github.com/kataras/iris/sessions" "github.com/kataras/iris/sessions/sessiondb/file" @@ -29,10 +28,10 @@ func main() { // the rest of the code stays the same. app := iris.New() - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.Writef("You should navigate to the /set, /get, /delete, /clear,/destroy instead") }) - app.Get("/set", func(ctx context.Context) { + app.Get("/set", func(ctx iris.Context) { s := sess.Start(ctx) //set session values s.Set("name", "iris") @@ -41,7 +40,7 @@ func main() { ctx.Writef("All ok session setted to: %s", s.GetString("name")) }) - app.Get("/set/{key}/{value}", func(ctx context.Context) { + app.Get("/set/{key}/{value}", func(ctx iris.Context) { key, value := ctx.Params().Get("key"), ctx.Params().Get("value") s := sess.Start(ctx) // set session values @@ -51,36 +50,36 @@ func main() { ctx.Writef("All ok session setted to: %s", s.GetString(key)) }) - app.Get("/get", func(ctx context.Context) { + app.Get("/get", func(ctx iris.Context) { // get a specific key, as string, if no found returns just an empty string name := sess.Start(ctx).GetString("name") ctx.Writef("The name on the /set was: %s", name) }) - app.Get("/get/{key}", func(ctx context.Context) { + app.Get("/get/{key}", func(ctx iris.Context) { // get a specific key, as string, if no found returns just an empty string name := sess.Start(ctx).GetString(ctx.Params().Get("key")) ctx.Writef("The name on the /set was: %s", name) }) - app.Get("/delete", func(ctx context.Context) { + app.Get("/delete", func(ctx iris.Context) { // delete a specific key sess.Start(ctx).Delete("name") }) - app.Get("/clear", func(ctx context.Context) { + app.Get("/clear", func(ctx iris.Context) { // removes all entries sess.Start(ctx).Clear() }) - app.Get("/destroy", func(ctx context.Context) { + app.Get("/destroy", func(ctx iris.Context) { //destroy, removes the entire session data and cookie sess.Destroy(ctx) }) - app.Get("/update", func(ctx context.Context) { + app.Get("/update", func(ctx iris.Context) { // updates expire date with a new date sess.ShiftExpiration(ctx) }) diff --git a/_examples/sessions/database/leveldb/main.go b/_examples/sessions/database/leveldb/main.go index 719eacb8..3eb21f91 100644 --- a/_examples/sessions/database/leveldb/main.go +++ b/_examples/sessions/database/leveldb/main.go @@ -4,7 +4,6 @@ import ( "time" "github.com/kataras/iris" - "github.com/kataras/iris/context" "github.com/kataras/iris/sessions" "github.com/kataras/iris/sessions/sessiondb/leveldb" @@ -34,10 +33,10 @@ func main() { // the rest of the code stays the same. app := iris.New() - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.Writef("You should navigate to the /set, /get, /delete, /clear,/destroy instead") }) - app.Get("/set", func(ctx context.Context) { + app.Get("/set", func(ctx iris.Context) { s := sess.Start(ctx) //set session values s.Set("name", "iris") @@ -46,7 +45,7 @@ func main() { ctx.Writef("All ok session setted to: %s", s.GetString("name")) }) - app.Get("/set/{key}/{value}", func(ctx context.Context) { + app.Get("/set/{key}/{value}", func(ctx iris.Context) { key, value := ctx.Params().Get("key"), ctx.Params().Get("value") s := sess.Start(ctx) // set session values @@ -56,36 +55,36 @@ func main() { ctx.Writef("All ok session setted to: %s", s.GetString(key)) }) - app.Get("/get", func(ctx context.Context) { + app.Get("/get", func(ctx iris.Context) { // get a specific key, as string, if no found returns just an empty string name := sess.Start(ctx).GetString("name") ctx.Writef("The name on the /set was: %s", name) }) - app.Get("/get/{key}", func(ctx context.Context) { + app.Get("/get/{key}", func(ctx iris.Context) { // get a specific key, as string, if no found returns just an empty string name := sess.Start(ctx).GetString(ctx.Params().Get("key")) ctx.Writef("The name on the /set was: %s", name) }) - app.Get("/delete", func(ctx context.Context) { + app.Get("/delete", func(ctx iris.Context) { // delete a specific key sess.Start(ctx).Delete("name") }) - app.Get("/clear", func(ctx context.Context) { + app.Get("/clear", func(ctx iris.Context) { // removes all entries sess.Start(ctx).Clear() }) - app.Get("/destroy", func(ctx context.Context) { + app.Get("/destroy", func(ctx iris.Context) { //destroy, removes the entire session data and cookie sess.Destroy(ctx) }) - app.Get("/update", func(ctx context.Context) { + app.Get("/update", func(ctx iris.Context) { // updates expire date with a new date sess.ShiftExpiration(ctx) }) diff --git a/_examples/sessions/database/redis/main.go b/_examples/sessions/database/redis/main.go index d49d5331..5ad8b080 100644 --- a/_examples/sessions/database/redis/main.go +++ b/_examples/sessions/database/redis/main.go @@ -4,7 +4,6 @@ import ( "time" "github.com/kataras/iris" - "github.com/kataras/iris/context" "github.com/kataras/iris/sessions" "github.com/kataras/iris/sessions/sessiondb/redis" @@ -40,10 +39,10 @@ func main() { // the rest of the code stays the same. app := iris.New() - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.Writef("You should navigate to the /set, /get, /delete, /clear,/destroy instead") }) - app.Get("/set", func(ctx context.Context) { + app.Get("/set", func(ctx iris.Context) { s := sess.Start(ctx) //set session values s.Set("name", "iris") @@ -52,29 +51,29 @@ func main() { ctx.Writef("All ok session setted to: %s", s.GetString("name")) }) - app.Get("/get", func(ctx context.Context) { + app.Get("/get", func(ctx iris.Context) { // get a specific key, as string, if no found returns just an empty string name := sess.Start(ctx).GetString("name") ctx.Writef("The name on the /set was: %s", name) }) - app.Get("/delete", func(ctx context.Context) { + app.Get("/delete", func(ctx iris.Context) { // delete a specific key sess.Start(ctx).Delete("name") }) - app.Get("/clear", func(ctx context.Context) { + app.Get("/clear", func(ctx iris.Context) { // removes all entries sess.Start(ctx).Clear() }) - app.Get("/destroy", func(ctx context.Context) { + app.Get("/destroy", func(ctx iris.Context) { //destroy, removes the entire session data and cookie sess.Destroy(ctx) }) - app.Get("/update", func(ctx context.Context) { + app.Get("/update", func(ctx iris.Context) { // updates expire date with a new date sess.ShiftExpiration(ctx) }) diff --git a/_examples/sessions/flash-messages/main.go b/_examples/sessions/flash-messages/main.go index d76854a8..662d289d 100644 --- a/_examples/sessions/flash-messages/main.go +++ b/_examples/sessions/flash-messages/main.go @@ -2,7 +2,6 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" "github.com/kataras/iris/sessions" ) @@ -11,13 +10,13 @@ func main() { app := iris.New() sess := sessions.New(sessions.Config{Cookie: "myappsessionid"}) - app.Get("/set", func(ctx context.Context) { + app.Get("/set", func(ctx iris.Context) { s := sess.Start(ctx) s.SetFlash("name", "iris") ctx.Writef("Message setted, is available for the next request") }) - app.Get("/get", func(ctx context.Context) { + app.Get("/get", func(ctx iris.Context) { s := sess.Start(ctx) name := s.GetFlashString("name") if name == "" { @@ -27,7 +26,7 @@ func main() { ctx.Writef("Hello %s", name) }) - app.Get("/test", func(ctx context.Context) { + app.Get("/test", func(ctx iris.Context) { s := sess.Start(ctx) name := s.GetFlashString("name") if name == "" { diff --git a/_examples/sessions/overview/main.go b/_examples/sessions/overview/main.go index fde18281..991c1d45 100644 --- a/_examples/sessions/overview/main.go +++ b/_examples/sessions/overview/main.go @@ -2,7 +2,6 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" "github.com/kataras/iris/sessions" ) @@ -12,7 +11,7 @@ var ( sess = sessions.New(sessions.Config{Cookie: cookieNameForSessionID}) ) -func secret(ctx context.Context) { +func secret(ctx iris.Context) { // Check if user is authenticated if auth, _ := sess.Start(ctx).GetBoolean("authenticated"); !auth { @@ -24,7 +23,7 @@ func secret(ctx context.Context) { ctx.WriteString("The cake is a lie!") } -func login(ctx context.Context) { +func login(ctx iris.Context) { session := sess.Start(ctx) // Authentication goes here @@ -34,7 +33,7 @@ func login(ctx context.Context) { session.Set("authenticated", true) } -func logout(ctx context.Context) { +func logout(ctx iris.Context) { session := sess.Start(ctx) // Revoke users authentication diff --git a/_examples/sessions/securecookie/main.go b/_examples/sessions/securecookie/main.go index ae256938..08ad111f 100644 --- a/_examples/sessions/securecookie/main.go +++ b/_examples/sessions/securecookie/main.go @@ -7,7 +7,6 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" "github.com/kataras/iris/sessions" @@ -30,10 +29,10 @@ func newApp() *iris.Application { Decode: secureCookie.Decode, }) - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.Writef("You should navigate to the /set, /get, /delete, /clear,/destroy instead") }) - app.Get("/set", func(ctx context.Context) { + app.Get("/set", func(ctx iris.Context) { //set session values s := mySessions.Start(ctx) @@ -43,7 +42,7 @@ func newApp() *iris.Application { ctx.Writef("All ok session setted to: %s", s.GetString("name")) }) - app.Get("/get", func(ctx context.Context) { + app.Get("/get", func(ctx iris.Context) { // get a specific key, as string, if no found returns just an empty string s := mySessions.Start(ctx) name := s.GetString("name") @@ -51,23 +50,23 @@ func newApp() *iris.Application { ctx.Writef("The name on the /set was: %s", name) }) - app.Get("/delete", func(ctx context.Context) { + app.Get("/delete", func(ctx iris.Context) { // delete a specific key s := mySessions.Start(ctx) s.Delete("name") }) - app.Get("/clear", func(ctx context.Context) { + app.Get("/clear", func(ctx iris.Context) { // removes all entries mySessions.Start(ctx).Clear() }) - app.Get("/update", func(ctx context.Context) { + app.Get("/update", func(ctx iris.Context) { // updates expire date with a new date mySessions.ShiftExpiration(ctx) }) - app.Get("/destroy", func(ctx context.Context) { + app.Get("/destroy", func(ctx iris.Context) { //destroy, removes the entire session data and cookie mySessions.Destroy(ctx) }) diff --git a/_examples/sessions/standalone/main.go b/_examples/sessions/standalone/main.go index 20a63d0f..4841f8f2 100644 --- a/_examples/sessions/standalone/main.go +++ b/_examples/sessions/standalone/main.go @@ -4,7 +4,6 @@ import ( "time" "github.com/kataras/iris" - "github.com/kataras/iris/context" "github.com/kataras/iris/sessions" ) @@ -31,10 +30,10 @@ func main() { // want to be crazy safe? Take a look at the "securecookie" example folder. }) - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.Writef("You should navigate to the /set, /get, /delete, /clear,/destroy instead") }) - app.Get("/set", func(ctx context.Context) { + app.Get("/set", func(ctx iris.Context) { //set session values. s := sess.Start(ctx) @@ -52,29 +51,29 @@ func main() { // Read more about muttable and immutable go types: https://stackoverflow.com/a/8021081 }) - app.Get("/get", func(ctx context.Context) { + app.Get("/get", func(ctx iris.Context) { // get a specific value, as string, if no found returns just an empty string name := sess.Start(ctx).GetString("name") ctx.Writef("The name on the /set was: %s", name) }) - app.Get("/delete", func(ctx context.Context) { + app.Get("/delete", func(ctx iris.Context) { // delete a specific key sess.Start(ctx).Delete("name") }) - app.Get("/clear", func(ctx context.Context) { + app.Get("/clear", func(ctx iris.Context) { // removes all entries sess.Start(ctx).Clear() }) - app.Get("/update", func(ctx context.Context) { + app.Get("/update", func(ctx iris.Context) { // updates expire date sess.ShiftExpiration(ctx) }) - app.Get("/destroy", func(ctx context.Context) { + app.Get("/destroy", func(ctx iris.Context) { //destroy, removes the entire session data and cookie sess.Destroy(ctx) @@ -91,7 +90,7 @@ func main() { // // Use `SetImmutable` consistently, it's slower than `Set`. // Read more about muttable and immutable go types: https://stackoverflow.com/a/8021081 - app.Get("/set_immutable", func(ctx context.Context) { + app.Get("/set_immutable", func(ctx iris.Context) { business := []businessModel{{Name: "Edward"}, {Name: "value 2"}} s := sess.Start(ctx) s.SetImmutable("businessEdit", business) @@ -103,7 +102,7 @@ func main() { }) - app.Get("/get_immutable", func(ctx context.Context) { + app.Get("/get_immutable", func(ctx iris.Context) { valSlice := sess.Start(ctx).Get("businessEdit") if valSlice == nil { ctx.HTML("please navigate to the /set_immutable first") diff --git a/_examples/subdomains/multi/main.go b/_examples/subdomains/multi/main.go index 4816b5bd..5878f5f3 100644 --- a/_examples/subdomains/multi/main.go +++ b/_examples/subdomains/multi/main.go @@ -2,7 +2,6 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" ) func main() { @@ -17,18 +16,18 @@ func main() { dashboard := app.Party("dashboard.") { - dashboard.Get("/", func(ctx context.Context) { + dashboard.Get("/", func(ctx iris.Context) { ctx.Writef("HEY FROM dashboard") }) } system := app.Party("system.") { - system.Get("/", func(ctx context.Context) { + system.Get("/", func(ctx iris.Context) { ctx.Writef("HEY FROM system") }) } - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.Writef("HEY FROM frontend /") }) // http://domain.local:80 diff --git a/_examples/subdomains/single/main.go b/_examples/subdomains/single/main.go index 50d5dbdc..2c70510d 100644 --- a/_examples/subdomains/single/main.go +++ b/_examples/subdomains/single/main.go @@ -3,7 +3,6 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" ) func main() { @@ -15,26 +14,26 @@ func main() { admin := app.Party("admin.") { // admin.mydomain.com - admin.Get("/", func(c context.Context) { + admin.Get("/", func(c iris.Context) { c.Writef("INDEX FROM admin.mydomain.com") }) // admin.mydomain.com/hey - admin.Get("/hey", func(c context.Context) { + admin.Get("/hey", func(c iris.Context) { c.Writef("HEY FROM admin.mydomain.com/hey") }) // admin.mydomain.com/hey2 - admin.Get("/hey2", func(c context.Context) { + admin.Get("/hey2", func(c iris.Context) { c.Writef("HEY SECOND FROM admin.mydomain.com/hey") }) } // mydomain.com/ - app.Get("/", func(c context.Context) { + app.Get("/", func(c iris.Context) { c.Writef("INDEX FROM no-subdomain hey") }) // mydomain.com/hey - app.Get("/hey", func(c context.Context) { + app.Get("/hey", func(c iris.Context) { c.Writef("HEY FROM no-subdomain hey") }) diff --git a/_examples/subdomains/wildcard/main.go b/_examples/subdomains/wildcard/main.go index 0a8f7131..2735ab5d 100644 --- a/_examples/subdomains/wildcard/main.go +++ b/_examples/subdomains/wildcard/main.go @@ -5,7 +5,6 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" ) // register a dynamic-wildcard subdomain to your server machine(dns/...) first, check ./hosts if you use windows. @@ -20,15 +19,15 @@ func main() { admin := app.Party("admin.") { // admin.mydomain.com - admin.Get("/", func(ctx context.Context) { + admin.Get("/", func(ctx iris.Context) { ctx.Writef("INDEX FROM admin.mydomain.com") }) // admin.mydomain.com/hey - admin.Get("/hey", func(ctx context.Context) { + admin.Get("/hey", func(ctx iris.Context) { ctx.Writef("HEY FROM admin.mydomain.com/hey") }) // admin.mydomain.com/hey2 - admin.Get("/hey2", func(ctx context.Context) { + admin.Get("/hey2", func(ctx iris.Context) { ctx.Writef("HEY SECOND FROM admin.mydomain.com/hey") }) }*/ @@ -43,11 +42,11 @@ func main() { dynamicSubdomains.Get("/something/{paramfirst}", dynamicSubdomainHandlerWithParam) } - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.Writef("Hello from mydomain.com path: %s", ctx.Path()) }) - app.Get("/hello", func(ctx context.Context) { + app.Get("/hello", func(ctx iris.Context) { ctx.Writef("Hello from mydomain.com path: %s", ctx.Path()) }) @@ -58,14 +57,14 @@ func main() { app.Run(iris.Addr("mydomain.com:8080")) // for beginners: look ../hosts file } -func dynamicSubdomainHandler(ctx context.Context) { +func dynamicSubdomainHandler(ctx iris.Context) { username := ctx.Subdomain() ctx.Writef("Hello from dynamic subdomain path: %s, here you can handle the route for dynamic subdomains, handle the user: %s", ctx.Path(), username) // if http://username4.mydomain.com:8080/ prints: // Hello from dynamic subdomain path: /, here you can handle the route for dynamic subdomains, handle the user: username4 } -func dynamicSubdomainHandlerWithParam(ctx context.Context) { +func dynamicSubdomainHandlerWithParam(ctx iris.Context) { username := ctx.Subdomain() ctx.Writef("Hello from dynamic subdomain path: %s, here you can handle the route for dynamic subdomains, handle the user: %s", ctx.Path(), username) ctx.Writef("The paramfirst is: %s", ctx.Params().Get("paramfirst")) diff --git a/_examples/subdomains/www/main.go b/_examples/subdomains/www/main.go index 0bc8c4f4..b80a28e3 100644 --- a/_examples/subdomains/www/main.go +++ b/_examples/subdomains/www/main.go @@ -2,7 +2,6 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" ) func newApp() *iris.Application { @@ -53,7 +52,7 @@ func main() { } } -func info(ctx context.Context) { +func info(ctx iris.Context) { method := ctx.Method() subdomain := ctx.Subdomain() path := ctx.Path() diff --git a/_examples/testing/httptest/main.go b/_examples/testing/httptest/main.go index c721fdaf..8aa1b020 100644 --- a/_examples/testing/httptest/main.go +++ b/_examples/testing/httptest/main.go @@ -2,7 +2,6 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" "github.com/kataras/iris/middleware/basicauth" ) @@ -15,7 +14,7 @@ func newApp() *iris.Application { authentication := basicauth.New(authConfig) - app.Get("/", func(ctx context.Context) { ctx.Redirect("/admin") }) + app.Get("/", func(ctx iris.Context) { ctx.Redirect("/admin") }) // to party @@ -33,7 +32,7 @@ func newApp() *iris.Application { return app } -func h(ctx context.Context) { +func h(ctx iris.Context) { username, password, _ := ctx.Request().BasicAuth() // third parameter it will be always true because the middleware // makes sure for that, otherwise this handler will not be executed. diff --git a/_examples/tutorial/mvc-from-scratch/README.md b/_examples/tutorial/mvc-from-scratch/README.md deleted file mode 100644 index f52344fa..00000000 --- a/_examples/tutorial/mvc-from-scratch/README.md +++ /dev/null @@ -1,130 +0,0 @@ -# Controllers from scratch - -This folder shows how [@kataras](https://github.com/kataras) started to develop -the MVC idea inside the Iris web framework itself. - -**Now** it has been enhanced and it's a **built'n** feature and can be used as: - -```go -package main - -import ( - "sync" - - "github.com/kataras/iris" - "github.com/kataras/iris/mvc" -) - -func main() { - app := iris.New() - app.RegisterView(iris.HTML("./views", ".html")) - - // when we have a path separated by spaces - // then the Controller is registered to all of them one by one. - // - // myDB is binded to the controller's `*DB` field: use only structs and pointers. - app.Controller("/profile /profile/browse /profile/{id:int} /profile/me", - new(ProfileController), myDB) // IMPORTANT - - app.Run(iris.Addr(":8080")) -} - -// UserModel our example model which will render on the template. -type UserModel struct { - ID int64 - Username string -} - -// DB is our example database. -type DB struct { - usersTable map[int64]UserModel - mu sync.RWMutex -} - -// GetUserByID imaginary database lookup based on user id. -func (db *DB) GetUserByID(id int64) (u UserModel, found bool) { - db.mu.RLock() - u, found = db.usersTable[id] - db.mu.RUnlock() - return -} - -var myDB = &DB{ - usersTable: map[int64]UserModel{ - 1: {1, "kataras"}, - 2: {2, "makis"}, - 42: {42, "jdoe"}, - }, -} - -// ProfileController our example user controller which controls -// the paths of "/profile" "/profile/{id:int}" and "/profile/me". -type ProfileController struct { - mvc.Controller // IMPORTANT - - User UserModel `iris:"model"` - // we will bind it but you can also tag it with`iris:"persistence"` - // and init the controller with manual &PorifleController{DB: myDB}. - DB *DB -} - -// Get method handles all "GET" HTTP Method requests of the controller's paths. -func (pc *ProfileController) Get() { // IMPORTANT - path := pc.Path - - // requested: /profile path - if path == "/profile" { - pc.Tmpl = "profile/index.html" - return - } - // requested: /profile/browse - // this exists only to proof the concept of changing the path: - // it will result to a redirection. - if path == "/profile/browse" { - pc.Path = "/profile" - return - } - - // requested: /profile/me path - if path == "/profile/me" { - pc.Tmpl = "profile/me.html" - return - } - - // requested: /profile/$ID - id, _ := pc.Params.GetInt64("id") - - user, found := pc.DB.GetUserByID(id) - if !found { - pc.Status = iris.StatusNotFound - pc.Tmpl = "profile/notfound.html" - pc.Data["ID"] = id - return - } - - pc.Tmpl = "profile/profile.html" - pc.User = user -} - -/* Can use more than one, the factory will make sure -that the correct http methods are being registered for each route -for this controller, uncomment these if you want: - -func (pc *ProfileController) Post() {} -func (pc *ProfileController) Put() {} -func (pc *ProfileController) Delete() {} -func (pc *ProfileController) Connect() {} -func (pc *ProfileController) Head() {} -func (pc *ProfileController) Patch() {} -func (pc *ProfileController) Options() {} -func (pc *ProfileController) Trace() {} -*/ - -/* -func (c *ProfileController) All() {} -// OR -func (c *ProfileController) Any() {} -*/ -``` - -Example can be found at: [_examples/mvc](https://github.com/kataras/iris/tree/master/_examples/mvc). \ No newline at end of file diff --git a/_examples/tutorial/mvc-from-scratch/controllers/controller.go b/_examples/tutorial/mvc-from-scratch/controllers/controller.go deleted file mode 100644 index 29c51161..00000000 --- a/_examples/tutorial/mvc-from-scratch/controllers/controller.go +++ /dev/null @@ -1,155 +0,0 @@ -package controllers - -import ( - "reflect" - "strings" - - "github.com/kataras/iris" - "github.com/kataras/iris/context" - "github.com/kataras/iris/core/router" -) - -type Controller struct { - // path params. - Params *context.RequestParams - - // view properties. - Layout string - Tmpl string - Data map[string]interface{} - - // give access to the request context itself. - Ctx context.Context -} - -// all lowercase, so user can see only the fields -// that are necessary to him/her. -func (b *Controller) init(ctx context.Context) { - b.Ctx = ctx - b.Params = ctx.Params() - b.Data = make(map[string]interface{}, 0) -} - -func (b *Controller) exec() { - if v := b.Tmpl; v != "" { - if l := b.Layout; l != "" { - b.Ctx.ViewLayout(l) - } - if d := b.Data; d != nil { - for key, value := range d { - b.Ctx.ViewData(key, value) - } - } - b.Ctx.View(v) - } -} - -// get the field name at compile-time, -// will help us to catch any unexpected results on future versions. -var baseControllerName = reflect.TypeOf(Controller{}).Name() - -func RegisterController(app *iris.Application, path string, c interface{}) { - typ := reflect.TypeOf(c) - - if typ.Kind() != reflect.Ptr { - typ = reflect.PtrTo(typ) - } - - elem := typ.Elem() - - // check if "c" has the "Controller" typeof `Controller` field. - b, has := elem.FieldByName(baseControllerName) - if !has { - panic("controller should have a field of Controller type") - } - - baseControllerFieldIndex := b.Index[0] - persistenceFields := make(map[int]reflect.Value, 0) - - if numField := elem.NumField(); numField > 1 { - val := reflect.Indirect(reflect.ValueOf(c)) - - for i := 0; i < numField; i++ { - f := elem.Field(i) - valF := val.Field(i) - // catch persistence data by tags, i.e: - // MyData string `iris:"persistence"` - // DB *DB `iris:"persistence"` - if t, ok := f.Tag.Lookup("iris"); ok { - if t == "persistence" { - persistenceFields[i] = reflect.ValueOf(valF.Interface()) - continue - } - } - - } - } - - // check if has Any() or All() - // if yes, then register all http methods and - // exit. - m, has := typ.MethodByName("Any") - if !has { - m, has = typ.MethodByName("All") - } - if has { - app.Any(path, - controllerToHandler(elem, persistenceFields, - baseControllerFieldIndex, m.Index)) - return - } - - // else search the entire controller - // for any compatible method function - // and register that. - for _, method := range router.AllMethods { - httpMethodFuncName := strings.Title(strings.ToLower(method)) - - m, has := typ.MethodByName(httpMethodFuncName) - if !has { - continue - } - - httpMethodIndex := m.Index - - app.Handle(method, path, - controllerToHandler(elem, persistenceFields, - baseControllerFieldIndex, httpMethodIndex)) - } - -} - -func controllerToHandler(elem reflect.Type, persistenceFields map[int]reflect.Value, - baseControllerFieldIndex, httpMethodIndex int) context.Handler { - return func(ctx context.Context) { - // create a new controller instance of that type(>ptr). - c := reflect.New(elem) - - // get the responsible method. - // Remember: - // To improve the performance - // we don't compare the ctx.Method()[HTTP Method] - // to the instance's Method, each handler is registered - // to a specific http method. - methodFunc := c.Method(httpMethodIndex) - - // get the Controller embedded field. - b, _ := c.Elem().Field(baseControllerFieldIndex).Addr().Interface().(*Controller) - - if len(persistenceFields) > 0 { - elem := c.Elem() - for index, value := range persistenceFields { - elem.Field(index).Set(value) - } - } - - // init the new controller instance. - b.init(ctx) - - // execute the responsible method for that handler. - methodFunc.Interface().(func())() - - // finally, execute the controller. - b.exec() - } -} diff --git a/_examples/tutorial/mvc-from-scratch/controllers/index.go b/_examples/tutorial/mvc-from-scratch/controllers/index.go deleted file mode 100644 index 3d9787f3..00000000 --- a/_examples/tutorial/mvc-from-scratch/controllers/index.go +++ /dev/null @@ -1,12 +0,0 @@ -package controllers - -// Index is our index example controller. -type Index struct { - Controller -} - -func (c *Index) Get() { - c.Tmpl = "index.html" - c.Data["title"] = "Index page" - c.Data["message"] = "Hello world!" -} diff --git a/_examples/tutorial/mvc-from-scratch/controllers/user.go b/_examples/tutorial/mvc-from-scratch/controllers/user.go deleted file mode 100644 index 88a65d55..00000000 --- a/_examples/tutorial/mvc-from-scratch/controllers/user.go +++ /dev/null @@ -1,57 +0,0 @@ -package controllers - -import ( - "time" - - "github.com/kataras/iris/_examples/tutorial/mvc-from-scratch/persistence" -) - -// User is our user example controller. -type User struct { - Controller - - // All fields that are tagged with iris:"persistence"` - // are being persistence and kept between the different requests, - // meaning that these data will not be reset-ed on each new request, - // they will be the same for all requests. - CreatedAt time.Time `iris:"persistence"` - Title string `iris:"persistence"` - DB *persistence.Database `iris:"persistence"` -} - -func NewUserController(db *persistence.Database) *User { - return &User{ - CreatedAt: time.Now(), - Title: "User page", - DB: db, - } -} - -// Get serves using the User controller when HTTP Method is "GET". -func (c *User) Get() { - c.Tmpl = "user/index.html" - c.Data["title"] = c.Title - c.Data["username"] = "kataras " + c.Params.Get("userid") - c.Data["connstring"] = c.DB.Connstring - c.Data["uptime"] = time.Now().Sub(c.CreatedAt).Seconds() -} - -/* Can use more than one, the factory will make sure -that the correct http methods are being registered for this -controller, uncommend these if you want: - -func (c *User) Post() {} -func (c *User) Put() {} -func (c *User) Delete() {} -func (c *User) Connect() {} -func (c *User) Head() {} -func (c *User) Patch() {} -func (c *User) Options() {} -func (c *User) Trace() {} -*/ - -/* -func (c *User) All() {} -// OR -func (c *User) Any() {} -*/ diff --git a/_examples/tutorial/mvc-from-scratch/main.go b/_examples/tutorial/mvc-from-scratch/main.go deleted file mode 100644 index 60cfaedb..00000000 --- a/_examples/tutorial/mvc-from-scratch/main.go +++ /dev/null @@ -1,24 +0,0 @@ -package main - -import ( - "github.com/kataras/iris/_examples/tutorial/mvc-from-scratch/controllers" - "github.com/kataras/iris/_examples/tutorial/mvc-from-scratch/persistence" - - "github.com/kataras/iris" -) - -func main() { - app := iris.New() - app.RegisterView(iris.HTML("./views", ".html")) - - db := persistence.OpenDatabase("a fake db") - - controllers.RegisterController(app, "/", new(controllers.Index)) - - controllers.RegisterController(app, "/user/{userid:int}", - controllers.NewUserController(db)) - - // http://localhost:8080/ - // http://localhost:8080/user/42 - app.Run(iris.Addr(":8080")) -} diff --git a/_examples/tutorial/mvc-from-scratch/models/user.go b/_examples/tutorial/mvc-from-scratch/models/user.go deleted file mode 100644 index ab09ede0..00000000 --- a/_examples/tutorial/mvc-from-scratch/models/user.go +++ /dev/null @@ -1,15 +0,0 @@ -package models - -import ( - "time" -) - -// User is an example model. -type User struct { - ID int64 - Username string - Firstname string - Lastname string - CreatedAt time.Time - UpdatedAt time.Time -} diff --git a/_examples/tutorial/mvc-from-scratch/persistence/database.go b/_examples/tutorial/mvc-from-scratch/persistence/database.go deleted file mode 100644 index 8de23178..00000000 --- a/_examples/tutorial/mvc-from-scratch/persistence/database.go +++ /dev/null @@ -1,10 +0,0 @@ -package persistence - -// Database is our imaginary storage. -type Database struct { - Connstring string -} - -func OpenDatabase(connstring string) *Database { - return &Database{Connstring: connstring} -} diff --git a/_examples/tutorial/mvc-from-scratch/views/index.html b/_examples/tutorial/mvc-from-scratch/views/index.html deleted file mode 100644 index 34826bf1..00000000 --- a/_examples/tutorial/mvc-from-scratch/views/index.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - {{.title}} - - - -

{{.message}}

- - - \ No newline at end of file diff --git a/_examples/tutorial/mvc-from-scratch/views/user/index.html b/_examples/tutorial/mvc-from-scratch/views/user/index.html deleted file mode 100644 index f5058ac5..00000000 --- a/_examples/tutorial/mvc-from-scratch/views/user/index.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - {{.title}} - - - -

Hello {{.username}}

- - - All fields inside a controller that are pointers or they tagged as `iris:"persistence"` are marked as persistence data, meaning - that they will not be reset-ed on each new request. -

Persistence data from *DB.Connstring: {{.connstring}}

-

Persistence data from CreatedAt `iris:"persistence"`: {{.uptime}} seconds

- - - \ No newline at end of file diff --git a/_examples/tutorial/online-visitors/main.go b/_examples/tutorial/online-visitors/main.go index f63026bd..6c7f6a55 100644 --- a/_examples/tutorial/online-visitors/main.go +++ b/_examples/tutorial/online-visitors/main.go @@ -4,7 +4,6 @@ import ( "sync/atomic" "github.com/kataras/iris" - "github.com/kataras/iris/context" "github.com/kataras/iris/websocket" ) @@ -26,12 +25,12 @@ func main() { // register static assets request path and system directory app.StaticWeb("/js", "./static/assets/js") - h := func(ctx context.Context) { + h := func(ctx iris.Context) { ctx.ViewData("", page{PageID: "index page"}) ctx.View("index.html") } - h2 := func(ctx context.Context) { + h2 := func(ctx iris.Context) { ctx.ViewData("", page{PageID: "other page"}) ctx.View("other.html") } diff --git a/_examples/tutorial/url-shortener/main.go b/_examples/tutorial/url-shortener/main.go index 0c234588..d232f833 100644 --- a/_examples/tutorial/url-shortener/main.go +++ b/_examples/tutorial/url-shortener/main.go @@ -13,7 +13,6 @@ import ( "html/template" "github.com/kataras/iris" - "github.com/kataras/iris/context" ) func main() { @@ -52,7 +51,7 @@ func newApp(db *DB) *iris.Application { // Serve static files (css) app.StaticWeb("/static", "./resources") - indexHandler := func(ctx context.Context) { + indexHandler := func(ctx iris.Context) { ctx.ViewData("URL_COUNT", db.Len()) ctx.View("index.html") } @@ -60,7 +59,7 @@ func newApp(db *DB) *iris.Application { // find and execute a short url by its key // used on http://localhost:8080/u/dsaoj41u321dsa - execShortURL := func(ctx context.Context, key string) { + execShortURL := func(ctx iris.Context, key string) { if key == "" { ctx.StatusCode(iris.StatusBadRequest) return @@ -75,11 +74,11 @@ func newApp(db *DB) *iris.Application { ctx.Redirect(value, iris.StatusTemporaryRedirect) } - app.Get("/u/{shortkey}", func(ctx context.Context) { + app.Get("/u/{shortkey}", func(ctx iris.Context) { execShortURL(ctx, ctx.Params().Get("shortkey")) }) - app.Post("/shorten", func(ctx context.Context) { + app.Post("/shorten", func(ctx iris.Context) { formValue := ctx.FormValue("url") if formValue == "" { ctx.ViewData("FORM_RESULT", "You need to a enter a URL") @@ -107,7 +106,7 @@ func newApp(db *DB) *iris.Application { indexHandler(ctx) // no redirect, we need the FORM_RESULT. }) - app.Post("/clear_cache", func(ctx context.Context) { + app.Post("/clear_cache", func(ctx iris.Context) { db.Clear() ctx.Redirect("/") }) diff --git a/_examples/view/context-view-data/main.go b/_examples/view/context-view-data/main.go index 3e008be7..732a1a3c 100644 --- a/_examples/view/context-view-data/main.go +++ b/_examples/view/context-view-data/main.go @@ -4,7 +4,6 @@ import ( "time" "github.com/kataras/iris" - "github.com/kataras/iris/context" ) const ( @@ -19,7 +18,7 @@ func main() { // set the view engine target to ./templates folder app.RegisterView(iris.HTML("./templates", ".html").Reload(true)) - app.Use(func(ctx context.Context) { + app.Use(func(ctx iris.Context) { // set the title, current time and a layout in order to be used if and when the next handler(s) calls the .Render function ctx.ViewData("Title", DefaultTitle) now := time.Now().Format(ctx.Application().ConfigurationReadOnly().GetTimeFormat()) @@ -29,14 +28,14 @@ func main() { ctx.Next() }) - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.ViewData("BodyMessage", "a sample text here... setted by the route handler") if err := ctx.View("index.html"); err != nil { ctx.Application().Logger().Infof(err.Error()) } }) - app.Get("/about", func(ctx context.Context) { + app.Get("/about", func(ctx iris.Context) { ctx.ViewData("Title", "My About Page") ctx.ViewData("BodyMessage", "about text here... setted by the route handler") diff --git a/_examples/view/embedding-templates-into-app/main.go b/_examples/view/embedding-templates-into-app/main.go index 8310e818..7c48a05c 100644 --- a/_examples/view/embedding-templates-into-app/main.go +++ b/_examples/view/embedding-templates-into-app/main.go @@ -2,7 +2,6 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" ) func main() { @@ -23,7 +22,7 @@ type page struct { Title, Name string } -func hi(ctx context.Context) { +func hi(ctx iris.Context) { ctx.ViewData("", page{Title: "Hi Page", Name: "iris"}) ctx.View("hi.html") } diff --git a/_examples/view/overview/main.go b/_examples/view/overview/main.go index af554bea..a5ffca0d 100644 --- a/_examples/view/overview/main.go +++ b/_examples/view/overview/main.go @@ -2,7 +2,6 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" ) func main() { @@ -21,7 +20,7 @@ func main() { // - {{ yield }} // - {{ current }} app.RegisterView(iris.HTML("./templates", ".html")) - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.ViewData("Name", "iris") // the .Name inside the ./templates/hi.html ctx.Gzip(true) // enable gzip for big files diff --git a/_examples/view/template_html_0/main.go b/_examples/view/template_html_0/main.go index 5b76c64e..efc997f0 100644 --- a/_examples/view/template_html_0/main.go +++ b/_examples/view/template_html_0/main.go @@ -2,7 +2,6 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" ) func main() { @@ -34,7 +33,7 @@ func main() { app.Run(iris.Addr(":8080"), iris.WithCharset("UTF-8")) // defaults to that but you can change it. } -func hi(ctx context.Context) { +func hi(ctx iris.Context) { ctx.ViewData("Title", "Hi Page") ctx.ViewData("Name", "iris") // {{.Name}} will render: iris // ctx.ViewData("", myCcustomStruct{}) diff --git a/_examples/view/template_html_1/main.go b/_examples/view/template_html_1/main.go index a4c32c8f..81bf5b5f 100644 --- a/_examples/view/template_html_1/main.go +++ b/_examples/view/template_html_1/main.go @@ -2,7 +2,6 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" ) type mypage struct { @@ -16,7 +15,7 @@ func main() { app.RegisterView(iris.HTML("./templates", ".html").Layout("layout.html")) // TIP: append .Reload(true) to reload the templates on each request. - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.Gzip(true) ctx.ViewData("", mypage{"My Page title", "Hello world!"}) ctx.View("mypage.html") diff --git a/_examples/view/template_html_2/main.go b/_examples/view/template_html_2/main.go index 46152c30..9418bd16 100644 --- a/_examples/view/template_html_2/main.go +++ b/_examples/view/template_html_2/main.go @@ -2,7 +2,6 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" ) func main() { @@ -16,7 +15,7 @@ func main() { app.RegisterView(tmpl) - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { if err := ctx.View("page1.html"); err != nil { ctx.StatusCode(iris.StatusInternalServerError) ctx.Writef(err.Error()) @@ -24,7 +23,7 @@ func main() { }) // remove the layout for a specific route - app.Get("/nolayout", func(ctx context.Context) { + app.Get("/nolayout", func(ctx iris.Context) { ctx.ViewLayout(iris.NoLayout) if err := ctx.View("page1.html"); err != nil { ctx.StatusCode(iris.StatusInternalServerError) @@ -35,10 +34,10 @@ func main() { // set a layout for a party, .Layout should be BEFORE any Get or other Handle party's method my := app.Party("/my").Layout("layouts/mylayout.html") { // both of these will use the layouts/mylayout.html as their layout. - my.Get("/", func(ctx context.Context) { + my.Get("/", func(ctx iris.Context) { ctx.View("page1.html") }) - my.Get("/other", func(ctx context.Context) { + my.Get("/other", func(ctx iris.Context) { ctx.View("page1.html") }) } diff --git a/_examples/view/template_html_3/main.go b/_examples/view/template_html_3/main.go index 88d22e16..82b192f3 100644 --- a/_examples/view/template_html_3/main.go +++ b/_examples/view/template_html_3/main.go @@ -3,7 +3,6 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" ) func main() { @@ -30,7 +29,7 @@ func main() { mypath6Route := app.Get("/mypath6/{paramfirst}/{paramsecond}/statichere/{paramThirdAfterStatic}", writePathHandler) mypath6Route.Name = "my-page6" - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { // for /mypath6... paramsAsArray := []string{"theParam1", "theParam2", "paramThirdAfterStatic"} ctx.ViewData("ParamsAsArray", paramsAsArray) @@ -39,7 +38,7 @@ func main() { } }) - app.Get("/redirect/{namedRoute}", func(ctx context.Context) { + app.Get("/redirect/{namedRoute}", func(ctx iris.Context) { routeName := ctx.Params().Get("namedRoute") r := app.GetRoute(routeName) if r == nil { @@ -63,6 +62,6 @@ func main() { } -func writePathHandler(ctx context.Context) { +func writePathHandler(ctx iris.Context) { ctx.Writef("Hello from %s.", ctx.Path()) } diff --git a/_examples/view/template_html_4/main.go b/_examples/view/template_html_4/main.go index 495d94e8..a15a4d18 100644 --- a/_examples/view/template_html_4/main.go +++ b/_examples/view/template_html_4/main.go @@ -3,7 +3,6 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" "github.com/kataras/iris/core/router" ) @@ -48,7 +47,7 @@ func main() { mypath6Route := subdomain.Get("/mypath6/{paramfirst}/{paramsecond}/staticParam/{paramThirdAfterStatic}", emptyHandler) mypath6Route.Name = "my-page6" - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { // for username5./mypath6... paramsAsArray := []string{"username5", "theParam1", "theParam2", "paramThirdAfterStatic"} ctx.ViewData("ParamsAsArray", paramsAsArray) @@ -61,7 +60,7 @@ func main() { app.Run(iris.Addr(host)) } -func emptyHandler(ctx context.Context) { +func emptyHandler(ctx iris.Context) { ctx.Writef("Hello from subdomain: %s , you're in path: %s", ctx.Subdomain(), ctx.Path()) } diff --git a/_examples/websocket/chat/main.go b/_examples/websocket/chat/main.go index 0ef81f8a..d3b33a0d 100644 --- a/_examples/websocket/chat/main.go +++ b/_examples/websocket/chat/main.go @@ -4,15 +4,13 @@ import ( "fmt" "github.com/kataras/iris" - "github.com/kataras/iris/context" - "github.com/kataras/iris/websocket" ) func main() { app := iris.New() - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.ServeFile("websockets.html", false) // second parameter: enable gzip? }) @@ -39,7 +37,7 @@ func setupWebsocket(app *iris.Application) { // serve the javascript built'n client-side library, // see weboskcets.html script tags, this path is used. - app.Any("/iris-ws.js", func(ctx context.Context) { + app.Any("/iris-ws.js", func(ctx iris.Context) { ctx.Write(websocket.ClientSource) }) } diff --git a/_examples/websocket/connectionlist/main.go b/_examples/websocket/connectionlist/main.go index 97097fe9..14c399a8 100644 --- a/_examples/websocket/connectionlist/main.go +++ b/_examples/websocket/connectionlist/main.go @@ -6,8 +6,6 @@ import ( "time" "github.com/kataras/iris" - "github.com/kataras/iris/context" - "github.com/kataras/iris/view" "github.com/kataras/iris/websocket" ) @@ -19,7 +17,7 @@ type clientPage struct { func main() { app := iris.New() - app.RegisterView(view.HTML("./templates", ".html")) // select the html engine to serve templates + app.RegisterView(iris.HTML("./templates", ".html")) // select the html engine to serve templates ws := websocket.New(websocket.Config{}) @@ -29,13 +27,13 @@ func main() { // serve the javascript built'n client-side library, // see weboskcets.html script tags, this path is used. - app.Any("/iris-ws.js", func(ctx context.Context) { + app.Any("/iris-ws.js", func(ctx iris.Context) { ctx.Write(websocket.ClientSource) }) app.StaticWeb("/js", "./static/js") // serve our custom javascript code - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.ViewData("", clientPage{"Client Page", "localhost:8080"}) ctx.View("client.html") }) diff --git a/_examples/websocket/native-messages/main.go b/_examples/websocket/native-messages/main.go index 48b804e7..254cb2a6 100644 --- a/_examples/websocket/native-messages/main.go +++ b/_examples/websocket/native-messages/main.go @@ -4,8 +4,6 @@ import ( "fmt" "github.com/kataras/iris" - "github.com/kataras/iris/context" - "github.com/kataras/iris/view" "github.com/kataras/iris/websocket" ) @@ -26,7 +24,7 @@ type clientPage struct { func main() { app := iris.New() - app.RegisterView(view.HTML("./templates", ".html")) // select the html engine to serve templates + app.RegisterView(iris.HTML("./templates", ".html")) // select the html engine to serve templates ws := websocket.New(websocket.Config{ // to enable binary messages (useful for protobuf): @@ -39,7 +37,7 @@ func main() { app.StaticWeb("/js", "./static/js") // serve our custom javascript code - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.ViewData("", clientPage{"Client Page", "localhost:8080"}) ctx.View("client.html") }) diff --git a/_examples/websocket/secure/main.go b/_examples/websocket/secure/main.go index 0a67134f..83f3d6ee 100644 --- a/_examples/websocket/secure/main.go +++ b/_examples/websocket/secure/main.go @@ -7,8 +7,6 @@ import ( "time" "github.com/kataras/iris" - "github.com/kataras/iris/context" - "github.com/kataras/iris/view" "github.com/kataras/iris/websocket" ) @@ -20,7 +18,7 @@ type clientPage struct { func main() { app := iris.New() - app.RegisterView(view.HTML("./templates", ".html")) // select the html engine to serve templates + app.RegisterView(iris.HTML("./templates", ".html")) // select the html engine to serve templates ws := websocket.New(websocket.Config{}) @@ -30,12 +28,12 @@ func main() { // serve the javascript built'n client-side library, // see weboskcets.html script tags, this path is used. - app.Any("/iris-ws.js", func(ctx context.Context) { + app.Any("/iris-ws.js", func(ctx iris.Context) { ctx.Write(websocket.ClientSource) }) app.StaticWeb("/js", "./static/js") - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { // send our custom javascript source file before client really asks for that // using the go v1.8's HTTP/2 Push. // Note that you have to listen using ListenTLS in order this to work. @@ -49,7 +47,7 @@ func main() { var myChatRoom = "room1" ws.OnConnection(func(c websocket.Connection) { - // Context returns the (upgraded) context.Context of this connection + // Context returns the (upgraded) iris.Context of this connection // avoid using it, you normally don't need it, // websocket has everything you need to authenticate the user BUT if it's necessary // then you use it to receive user information, for example: from headers. diff --git a/context.go b/context.go index 96d001a2..64cd0006 100644 --- a/context.go +++ b/context.go @@ -16,8 +16,6 @@ import ( // README.md: Hello World with Go 1.9 // core/host/supervisor.go // context.go -// _examples/hello-world/main_go19.go -// _examples/tutorial/mvc-from-scratch/README.md type ( // Context is the midle-man server's "object" for the clients. // diff --git a/doc.go b/doc.go index 8b2de6f8..fee4c586 100644 --- a/doc.go +++ b/doc.go @@ -39,7 +39,7 @@ Current Version Installation -The only requirement is the Go Programming Language, at least version 1.8 +The only requirement is the Go Programming Language, at least version 1.8 but 1.9 is highly recommended. $ go get -u github.com/kataras/iris @@ -49,10 +49,7 @@ Example code: package main - import ( - "github.com/kataras/iris" - "github.com/kataras/iris/context" - ) + import "github.com/kataras/iris" // User is just a bindable object structure. type User struct { @@ -72,7 +69,7 @@ Example code: app.RegisterView(iris.HTML("./views", ".html").Reload(true)) // Register custom handler for specific http errors. - app.OnErrorCode(iris.StatusInternalServerError, func(ctx context.Context) { + app.OnErrorCode(iris.StatusInternalServerError, func(ctx iris.Context) { // .Values are used to communicate between handlers, middleware. errMessage := ctx.Values().GetString("error") if errMessage != "" { @@ -83,22 +80,22 @@ Example code: ctx.Writef("(Unexpected) internal server error") }) - app.Use(func(ctx context.Context) { + app.Use(func(ctx iris.Context) { ctx.Application().Logger().Infof("Begin request for path: %s", ctx.Path()) ctx.Next() }) - // app.Done(func(ctx context.Context) {}) + // app.Done(func(ctx iris.Context) {}) // Method POST: http://localhost:8080/decode - app.Post("/decode", func(ctx context.Context) { + app.Post("/decode", func(ctx iris.Context) { var user User ctx.ReadJSON(&user) ctx.Writef("%s %s is %d years old and comes from %s", user.Firstname, user.Lastname, user.Age, user.City) }) // Method GET: http://localhost:8080/encode - app.Get("/encode", func(ctx context.Context) { + app.Get("/encode", func(ctx iris.Context) { doe := User{ Username: "Johndoe", Firstname: "John", @@ -125,7 +122,7 @@ Example code: app.Run(iris.Addr(":8080"), iris.WithCharset("UTF-8")) } - func logThisMiddleware(ctx context.Context) { + func logThisMiddleware(ctx iris.Context) { ctx.Application().Logger().Infof("Path: %s | IP: %s", ctx.Path(), ctx.RemoteAddr()) // .Next is required to move forward to the chain of handlers, @@ -133,7 +130,7 @@ Example code: ctx.Next() } - func profileByUsername(ctx context.Context) { + func profileByUsername(ctx iris.Context) { // .Params are used to get dynamic path parameters. username := ctx.Params().Get("username") ctx.ViewData("Username", username) @@ -142,7 +139,7 @@ Example code: ctx.View("users/profile.html") } - func getUserByID(ctx context.Context) { + func getUserByID(ctx iris.Context) { userID := ctx.Params().Get("id") // Or convert directly using: .Values().GetInt/GetInt64 etc... // your own db fetch here instead of user :=... user := User{Username: "username" + userID} @@ -150,7 +147,7 @@ Example code: ctx.XML(user) } - func createUser(ctx context.Context) { + func createUser(ctx iris.Context) { var user User err := ctx.ReadForm(&user) if err != nil { @@ -232,7 +229,6 @@ Example code: "github.com/valyala/tcplisten" "github.com/kataras/iris" - "github.com/kataras/iris/context" ) // $ go get github.com/valyala/tcplisten @@ -241,7 +237,7 @@ Example code: func main() { app := iris.New() - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.HTML("Hello World!") }) @@ -280,7 +276,6 @@ Example code: "time" "github.com/kataras/iris" - "github.com/kataras/iris/context" ) @@ -295,7 +290,7 @@ Example code: app.Shutdown(ctx) }) - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.HTML("

hi, I just exist in order to see if the server is closed

") }) @@ -350,14 +345,13 @@ Example Code: "time" "github.com/kataras/iris" - "github.com/kataras/iris/context" "github.com/kataras/iris/core/host" ) func main() { app := iris.New() - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.HTML("

Hello, try to refresh the page after ~10 secs

") }) @@ -406,7 +400,7 @@ Routing All HTTP methods are supported, developers can also register handlers for same paths for different methods. The first parameter is the HTTP Method, second parameter is the request path of the route, -third variadic parameter should contains one or more context.Handler executed +third variadic parameter should contains one or more iris.Handler executed by the registered order when a user requests for that specific resouce path from the server. Example code: @@ -414,14 +408,14 @@ Example code: app := iris.New() - app.Handle("GET", "/contact", func(ctx context.Context){ + app.Handle("GET", "/contact", func(ctx iris.Context) { ctx.HTML("

Hello from /contact

") }) In order to make things easier for the user, iris provides functions for all HTTP Methods. The first parameter is the request path of the route, -second variadic parameter should contains one or more context.Handler executed +second variadic parameter should contains one or more iris.Handler executed by the registered order when a user requests for that specific resouce path from the server. Example code: @@ -459,7 +453,7 @@ Example code: // register the route for all HTTP Methods app.Any("/", handler) - func handler(ctx context.Context){ + func handler(ctx iris.Context){ ctx.Writef("Hello from method: %s and path: %s", ctx.Method(), ctx.Path()) } @@ -497,11 +491,11 @@ Example code: // when 404 then render the template $templatedir/errors/404.html - app.OnErrorCode(iris.StatusNotFound, func(ctx context.Context){ + app.OnErrorCode(iris.StatusNotFound, func(ctx iris.Context){ ctx.View("errors/404.html") }) - app.OnErrorCode(500, func(ctx context.Context){ + app.OnErrorCode(500, func(ctx iris.Context){ // ... }) @@ -515,10 +509,7 @@ Example code: package main - import ( - "github.com/kataras/iris" - "github.com/kataras/iris/context" - ) + import "github.com/kataras/iris" func main() { app := iris.New() @@ -529,23 +520,23 @@ Example code: // GET -> HTTP Method // / -> Path - // func(ctx context.Context) -> The route's handler. + // func(ctx iris.Context) -> The route's handler. // // Third receiver should contains the route's handler(s), they are executed by order. - app.Handle("GET", "/", func(ctx context.Context) { + app.Handle("GET", "/", func(ctx iris.Context) { // navigate to the middle of $GOPATH/src/github.com/kataras/iris/context/context.go // to overview all context's method (there a lot of them, read that and you will learn how iris works too) ctx.HTML("Hello from " + ctx.Path()) // Hello from / }) - app.Get("/home", func(ctx context.Context) { + app.Get("/home", func(ctx iris.Context) { ctx.Writef(`Same as app.Handle("GET", "/", [...])`) }) app.Get("/donate", donateHandler, donateFinishHandler) // Pssst, don't forget dynamic-path example for more "magic"! - app.Get("/api/users/{userid:int min(1)}", func(ctx context.Context) { + app.Get("/api/users/{userid:int min(1)}", func(ctx iris.Context) { userID, err := ctx.Params().GetInt("userid") if err != nil { @@ -560,15 +551,15 @@ Example code: "user_id": userID, }) }) - // app.Post("/", func(ctx context.Context){}) -> for POST http method. - // app.Put("/", func(ctx context.Context){})-> for "PUT" http method. - // app.Delete("/", func(ctx context.Context){})-> for "DELETE" http method. - // app.Options("/", func(ctx context.Context){})-> for "OPTIONS" http method. - // app.Trace("/", func(ctx context.Context){})-> for "TRACE" http method. - // app.Head("/", func(ctx context.Context){})-> for "HEAD" http method. - // app.Connect("/", func(ctx context.Context){})-> for "CONNECT" http method. - // app.Patch("/", func(ctx context.Context){})-> for "PATCH" http method. - // app.Any("/", func(ctx context.Context){}) for all http methods. + // app.Post("/", func(ctx iris.Context){}) -> for POST http method. + // app.Put("/", func(ctx iris.Context){})-> for "PUT" http method. + // app.Delete("/", func(ctx iris.Context){})-> for "DELETE" http method. + // app.Options("/", func(ctx iris.Context){})-> for "OPTIONS" http method. + // app.Trace("/", func(ctx iris.Context){})-> for "TRACE" http method. + // app.Head("/", func(ctx iris.Context){})-> for "HEAD" http method. + // app.Connect("/", func(ctx iris.Context){})-> for "CONNECT" http method. + // app.Patch("/", func(ctx iris.Context){})-> for "PATCH" http method. + // app.Any("/", func(ctx iris.Context){}) for all http methods. // More than one route can contain the same path with a different http mapped method. // You can catch any route creation errors with: @@ -579,13 +570,13 @@ Example code: adminRoutes := app.Party("/admin", adminMiddleware) - adminRoutes.Done(func(ctx context.Context) { // executes always last if ctx.Next() + adminRoutes.Done(func(ctx iris.Context) { // executes always last if ctx.Next() ctx.Application().Logger().Infof("response sent to " + ctx.Path()) }) // adminRoutes.Layout("/views/layouts/admin.html") // set a view layout for these routes, see more at view examples. // GET: http://localhost:8080/admin - adminRoutes.Get("/", func(ctx context.Context) { + adminRoutes.Get("/", func(ctx iris.Context) { // [...] ctx.StatusCode(iris.StatusOK) // default is 200 == iris.StatusOK ctx.HTML("

Hello from admin/

") @@ -594,11 +585,11 @@ Example code: }) // GET: http://localhost:8080/admin/login - adminRoutes.Get("/login", func(ctx context.Context) { + adminRoutes.Get("/login", func(ctx iris.Context) { // [...] }) // POST: http://localhost:8080/admin/login - adminRoutes.Post("/login", func(ctx context.Context) { + adminRoutes.Post("/login", func(ctx iris.Context) { // [...] }) @@ -608,18 +599,18 @@ Example code: { // braces are optional, it's just type of style, to group the routes visually. // http://v1.localhost:8080 - v1.Get("/", func(ctx context.Context) { + v1.Get("/", func(ctx iris.Context) { ctx.HTML("Version 1 API. go to /api/users") }) usersAPI := v1.Party("/api/users") { // http://v1.localhost:8080/api/users - usersAPI.Get("/", func(ctx context.Context) { + usersAPI.Get("/", func(ctx iris.Context) { ctx.Writef("All users") }) // http://v1.localhost:8080/api/users/42 - usersAPI.Get("/{userid:int}", func(ctx context.Context) { + usersAPI.Get("/{userid:int}", func(ctx iris.Context) { ctx.Writef("user with id: %s", ctx.Params().Get("userid")) }) } @@ -628,7 +619,7 @@ Example code: // wildcard subdomains. wildcardSubdomain := app.Party("*.") { - wildcardSubdomain.Get("/", func(ctx context.Context) { + wildcardSubdomain.Get("/", func(ctx iris.Context) { ctx.Writef("Subdomain can be anything, now you're here from: %s", ctx.Subdomain()) }) } @@ -652,22 +643,22 @@ Example code: app.Run(iris.Addr(":8080")) } - func adminMiddleware(ctx context.Context) { + func adminMiddleware(ctx iris.Context) { // [...] ctx.Next() // to move to the next handler, or don't that if you have any auth logic. } - func donateHandler(ctx context.Context) { + func donateHandler(ctx iris.Context) { ctx.Writef("Just like an inline handler, but it can be " + "used by other package, anywhere in your project.") // let's pass a value to the next handler // Values is the way handlers(or middleware) are communicating between each other. - ctx.Values().Set("donate_url", "https://github.com/kataras/iris#buy-me-a-cup-of-coffee") + ctx.Values().Set("donate_url", "https://github.com/kataras/iris#-people") ctx.Next() // in order to execute the next handler in the chain, look donate route. } - func donateFinishHandler(ctx context.Context) { + func donateFinishHandler(ctx iris.Context) { // values can be any type of object so we could cast the value to a string // but iris provides an easy to do that, if donate_url is not defined, then it returns an empty string instead. donateURL := ctx.Values().GetString("donate_url") @@ -675,7 +666,7 @@ Example code: ctx.Writef("\n\nDonate sent(?).") } - func notFoundHandler(ctx context.Context) { + func notFoundHandler(ctx iris.Context) { ctx.HTML("Custom route for 404 not found http code, here you can render a view, html, json any valid response.") } @@ -806,7 +797,7 @@ the template file via `Data` field. Access to the template layout via the `Layout` field. -Access to the low-level `context.Context` via the `Ctx` field. +Access to the low-level `iris.Context` via the `Ctx` field. Get the relative request path by using the controller's name via `RelPath()`. @@ -873,11 +864,10 @@ we've seen static routes, group of routes, subdomains, wildcard subdomains, a sm with a single known paramete and custom http errors, now it's time to see wildcard parameters and macros. iris, like net/http std package registers route's handlers -by a Handler, the iris' type of handler is just a func(ctx context.Context) +by a Handler, the iris' type of handler is just a func(ctx iris.Context) where context comes from github.com/kataras/iris/context. -Until go 1.9 you will have to import that package too, after go 1.9 this will be not be necessary. -iris has the easiest and the most powerful routing process you have ever meet. +Iris has the easiest and the most powerful routing process you have ever meet. At the same time, iris has its own interpeter(yes like a programming language) @@ -959,7 +949,7 @@ Example code: // you can use the "string" type which is valid for a single path parameter that can be anything. - app.Get("/username/{name}", func(ctx context.Context) { + app.Get("/username/{name}", func(ctx iris.Context) { ctx.Writef("Hello %s", ctx.Params().Get("name")) }) // type is missing = {name:string} @@ -983,7 +973,7 @@ Example code: // http://localhost:8080/profile/id>=1 // this will throw 404 even if it's found as route on : /profile/0, /profile/blabla, /profile/-1 // macro parameter functions are optional of course. - app.Get("/profile/{id:int min(1)}", func(ctx context.Context) { + app.Get("/profile/{id:int min(1)}", func(ctx iris.Context) { // second parameter is the error but it will always nil because we use macros, // the validaton already happened. id, _ := ctx.Params().GetInt("id") @@ -991,7 +981,7 @@ Example code: }) // to change the error code per route's macro evaluator: - app.Get("/profile/{id:int min(1)}/friends/{friendid:int min(1) else 504}", func(ctx context.Context) { + app.Get("/profile/{id:int min(1)}/friends/{friendid:int min(1) else 504}", func(ctx iris.Context) { id, _ := ctx.Params().GetInt("id") friendid, _ := ctx.Params().GetInt("friendid") ctx.Writef("Hello id: %d looking for friend id: ", id, friendid) @@ -999,7 +989,7 @@ Example code: // http://localhost:8080/game/a-zA-Z/level/0-9 // remember, alphabetical is lowercase or uppercase letters only. - app.Get("/game/{name:alphabetical}/level/{level:int}", func(ctx context.Context) { + app.Get("/game/{name:alphabetical}/level/{level:int}", func(ctx iris.Context) { ctx.Writef("name: %s | level: %s", ctx.Params().Get("name"), ctx.Params().Get("level")) }) @@ -1007,18 +997,18 @@ Example code: // which its value is only lowercase letters. // http://localhost:8080/lowercase/anylowercase - app.Get("/lowercase/{name:string regexp(^[a-z]+)}", func(ctx context.Context) { + app.Get("/lowercase/{name:string regexp(^[a-z]+)}", func(ctx iris.Context) { ctx.Writef("name should be only lowercase, otherwise this handler will never executed: %s", ctx.Params().Get("name")) }) // http://localhost:8080/single_file/app.js - app.Get("/single_file/{myfile:file}", func(ctx context.Context) { + app.Get("/single_file/{myfile:file}", func(ctx iris.Context) { ctx.Writef("file type validates if the parameter value has a form of a file name, got: %s", ctx.Params().Get("myfile")) }) // http://localhost:8080/myfiles/any/directory/here/ // this is the only macro type that accepts any number of path segments. - app.Get("/myfiles/{directory:path}", func(ctx context.Context) { + app.Get("/myfiles/{directory:path}", func(ctx iris.Context) { ctx.Writef("path type accepts any number of path segments, path after /myfiles/ is: %s", ctx.Params().Get("directory")) }) @@ -1121,10 +1111,7 @@ Example code: package main - import ( - "github.com/kataras/iris" - "github.com/kataras/iris/context" - ) + import "github.com/kataras/iris" func main() { app := iris.New() @@ -1135,7 +1122,7 @@ Example code: // app.Favicon("./static/favicons/ion_32_32.ico", "/favicon_48_48.ico") // This will serve the ./static/favicons/ion_32_32.ico to: localhost:8080/favicon_48_48.ico - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.HTML(` press here to see the favicon.ico. At some browsers like chrome, it should be visible at the top-left side of the browser's window, because some browsers make requests to the /favicon.ico automatically, @@ -1158,7 +1145,7 @@ Example code: // globally // before any routes, appends the middleware to all routes - app.Use(func(ctx context.Context){ + app.Use(func(ctx iris.Context){ // ... any code here ctx.Next() // in order to continue to the next handler, @@ -1184,7 +1171,7 @@ Example code: // per wildcard, dynamic subdomain dynamicSub := app.Party(".*", firstMiddleware, secondMiddleware) - dynamicSub.Get("/", func(ctx context.Context){ + dynamicSub.Get("/", func(ctx iris.Context){ ctx.Writef("Hello from subdomain: "+ ctx.Subdomain()) }) @@ -1201,7 +1188,6 @@ Example code: "github.com/rs/cors" "github.com/kataras/iris" - "github.com/kataras/iris/context" ) func main() { @@ -1226,7 +1212,7 @@ Example code: app.Run(iris.Addr(":8080")) } - func h(ctx context.Context) { + func h(ctx iris.Context) { ctx.Application().Logger().Infof(ctx.Path()) ctx.Writef("Hello from %s", ctx.Path()) } @@ -1236,7 +1222,7 @@ View Engine iris supports 5 template engines out-of-the-box, developers can still use any external golang template engine, -as `context.ResponseWriter()` is an `io.Writer`. +as `context/context#ResponseWriter()` is an `io.Writer`. All of these five template engines have common features with common API, like Layout, Template Funcs, Party-specific layout, partial rendering and more. @@ -1261,10 +1247,7 @@ Example code: package main - import ( - "github.com/kataras/iris" - "github.com/kataras/iris/context" - ) + import "github.com/kataras/iris" func main() { app := iris.New() // defaults to these @@ -1295,7 +1278,7 @@ Example code: app.Run(iris.Addr(":8080"), iris.WithCharset("UTF-8")) // defaults to that but you can change it. } - func hi(ctx context.Context) { + func hi(ctx iris.Context) { ctx.ViewData("Title", "Hi Page") ctx.ViewData("Name", "iris") // {{.Name}} will render: iris // ctx.ViewData("", myCcustomStruct{}) @@ -1312,10 +1295,7 @@ Example code: package main - import ( - "github.com/kataras/iris" - "github.com/kataras/iris/context" - ) + import "github.com/kataras/iris" func main() { app := iris.New() @@ -1335,7 +1315,7 @@ Example code: Title, Name string } - func hi(ctx context.Context) { + func hi(ctx iris.Context) { ctx.ViewData("", page{Title: "Hi Page", Name: "iris"}) ctx.View("hi.html") } @@ -1388,7 +1368,6 @@ Example code: import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" "github.com/kataras/iris/sessions" ) @@ -1398,7 +1377,7 @@ Example code: sess = sessions.New(sessions.Config{Cookie: cookieNameForSessionID}) ) - func secret(ctx context.Context) { + func secret(ctx iris.Context) { // Check if user is authenticated if auth, _ := sess.Start(ctx).GetBoolean("authenticated"); !auth { @@ -1410,7 +1389,7 @@ Example code: ctx.WriteString("The cake is a lie!") } - func login(ctx context.Context) { + func login(ctx iris.Context) { session := sess.Start(ctx) // Authentication goes here @@ -1420,7 +1399,7 @@ Example code: session.Set("authenticated", true) } - func logout(ctx context.Context) { + func logout(ctx iris.Context) { session := sess.Start(ctx) // Revoke users authentication @@ -1464,7 +1443,6 @@ Example Code: "time" "github.com/kataras/iris" - "github.com/kataras/iris/context" "github.com/kataras/iris/sessions" "github.com/kataras/iris/sessions/sessiondb/boltdb" // <- IMPORTANT @@ -1493,10 +1471,10 @@ Example Code: // the rest of the code stays the same. app := iris.New() - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.Writef("You should navigate to the /set, /get, /delete, /clear,/destroy instead") }) - app.Get("/set", func(ctx context.Context) { + app.Get("/set", func(ctx iris.Context) { s := sess.Start(ctx) //set session values s.Set("name", "iris") @@ -1505,7 +1483,7 @@ Example Code: ctx.Writef("All ok session setted to: %s", s.GetString("name")) }) - app.Get("/set/{key}/{value}", func(ctx context.Context) { + app.Get("/set/{key}/{value}", func(ctx iris.Context) { key, value := ctx.Params().Get("key"), ctx.Params().Get("value") s := sess.Start(ctx) // set session values @@ -1515,36 +1493,36 @@ Example Code: ctx.Writef("All ok session setted to: %s", s.GetString(key)) }) - app.Get("/get", func(ctx context.Context) { + app.Get("/get", func(ctx iris.Context) { // get a specific key, as string, if no found returns just an empty string name := sess.Start(ctx).GetString("name") ctx.Writef("The name on the /set was: %s", name) }) - app.Get("/get/{key}", func(ctx context.Context) { + app.Get("/get/{key}", func(ctx iris.Context) { // get a specific key, as string, if no found returns just an empty string name := sess.Start(ctx).GetString(ctx.Params().Get("key")) ctx.Writef("The name on the /set was: %s", name) }) - app.Get("/delete", func(ctx context.Context) { + app.Get("/delete", func(ctx iris.Context) { // delete a specific key sess.Start(ctx).Delete("name") }) - app.Get("/clear", func(ctx context.Context) { + app.Get("/clear", func(ctx iris.Context) { // removes all entries sess.Start(ctx).Clear() }) - app.Get("/destroy", func(ctx context.Context) { + app.Get("/destroy", func(ctx iris.Context) { //destroy, removes the entire session data and cookie sess.Destroy(ctx) }) - app.Get("/update", func(ctx context.Context) { + app.Get("/update", func(ctx iris.Context) { // updates expire date with a new date sess.ShiftExpiration(ctx) }) @@ -1571,7 +1549,6 @@ Example Server Code: "fmt" "github.com/kataras/iris" - "github.com/kataras/iris/context" "github.com/kataras/iris/websocket" ) @@ -1579,7 +1556,7 @@ Example Server Code: func main() { app := iris.New() - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.ServeFile("websockets.html", false) // second parameter: enable gzip? }) @@ -1606,7 +1583,7 @@ Example Server Code: // serve the javascript built'n client-side library, // see weboskcets.html script tags, this path is used. - app.Any("/iris-ws.js", func(ctx context.Context) { + app.Any("/iris-ws.js", func(ctx iris.Context) { ctx.Write(websocket.ClientSource) }) } diff --git a/typescript/_examples/editor/main.go b/typescript/_examples/editor/main.go index 53ef1ed5..59bfb4e4 100644 --- a/typescript/_examples/editor/main.go +++ b/typescript/_examples/editor/main.go @@ -2,7 +2,6 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" "github.com/kataras/iris/typescript/editor" ) @@ -13,7 +12,7 @@ func main() { // when you edit a typescript file from the alm-tools // it compiles it to javascript, have fun! - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.ServeFile("./www/index.html", false) }) diff --git a/typescript/_examples/typescript/main.go b/typescript/_examples/typescript/main.go index a4289974..a42a2b92 100644 --- a/typescript/_examples/typescript/main.go +++ b/typescript/_examples/typescript/main.go @@ -2,7 +2,6 @@ package main import ( "github.com/kataras/iris" - "github.com/kataras/iris/context" "github.com/kataras/iris/typescript" ) @@ -17,7 +16,7 @@ func main() { app.StaticWeb("/scripts", "./www") // serve the scripts - app.Get("/", func(ctx context.Context) { + app.Get("/", func(ctx iris.Context) { ctx.ServeFile("./www/index.html", false) })