Permalink
Browse files

Update to 8.3.2 and add MVC examples.

  • Loading branch information...
kataras committed Aug 22, 2017
1 parent b06969e commit 4366f68d7df1971a8b206808e26e47d90a2b53b8
Showing with 11,315 additions and 60 deletions.
  1. +1 −22 .gitignore
  2. +9 −3 README.md
  3. +2 −2 configuration/functional/main.go
  4. +1 −0 file-server/basic/assets/index.html
  5. +11 −0 file-server/basic/main.go
  6. +12 −4 hello-world/main.go
  7. +9 −0 hello-world/main_go19.go
  8. +2 −0 http-listening/iris-configurator-and-host-configurator/README.md
  9. +31 −0 http-listening/iris-configurator-and-host-configurator/counter/configurator.go
  10. +14 −0 http-listening/iris-configurator-and-host-configurator/main.go
  11. +53 −0 http-listening/notify-on-shutdown/main.go
  12. +45 −0 miscellaneous/recaptcha/main.go
  13. +112 −0 mvc/controller-with-model-and-view/main.go
  14. +13 −0 mvc/controller-with-model-and-view/views/profile/index.html
  15. +13 −0 mvc/controller-with-model-and-view/views/profile/me.html
  16. +13 −0 mvc/controller-with-model-and-view/views/profile/notfound.html
  17. +13 −0 mvc/controller-with-model-and-view/views/profile/profile.html
  18. +105 −0 mvc/hello-world/main.go
  19. +47 −0 mvc/session-controller/main.go
  20. +75 −0 orm/xorm/main.go
  21. +2 −1 overview/main.go
  22. +16 −5 routing/custom-context/method-overriding/main.go
  23. +13 −3 routing/dynamic-path/root-wildcard/main.go
  24. +4 −1 routing/reverse/main.go
  25. +93 −0 sessions/database/boltdb/main.go
  26. +89 −0 sessions/database/file/main.go
  27. +94 −0 sessions/database/leveldb/main.go
  28. +25 −16 sessions/database/{ → redis}/main.go
  29. +1 −1 sessions/securecookie/main.go
  30. +2 −1 sessions/standalone/main.go
  31. +1 −1 view/template_html_3/main.go
  32. +44 −0 websocket/third-party-socketio/main.go
  33. +38 −0 websocket/third-party-socketio/public/index.html
  34. +10,309 −0 websocket/third-party-socketio/public/jquery-1.11.1.js
  35. +3 −0 websocket/third-party-socketio/public/socket.io-1.3.7.js
@@ -1,22 +1 @@
.project
.idea
.git
.settings
.vscode/*
.atom-build.json
iris.test.exe
cpu_test.out
mem_test.out
cover_test.out
block_test.out
heap_test.out
cpu_test.txt
cover_profile_test.txt
build.bat
*.o
*.a
*.so
build.bat
ab
*.exe
letsencrypt.cache
.vscode
@@ -15,6 +15,7 @@ It doesn't contains "best ways" neither explains all its features. It's just a s
* [Glimpse](overview/main.go)
* [Tutorial: Online Visitors](tutorial/online-visitors/main.go)
* [Tutorial: URL Shortener using BoltDB](tutorial/url-shortener/main.go)
* [Tutorial: How to turn your Android Device into a fully featured Web Server (**MUST**)](https://twitter.com/ThePracticalDev/status/892022594031017988)
* [HTTP Listening](http-listening)
* [Common, with address](http-listening/listen-addr/main.go)
* [UNIX socket file](http-listening/listen-unix/main.go)
@@ -40,7 +41,11 @@ It doesn't contains "best ways" neither explains all its features. It's just a s
* [Root level wildcard path](routing/dynamic-path/root-wildcard/main.go)
* [Reverse routing](routing/reverse/main.go)
* [Custom wrapper](routing/custom-wrapper/main.go)
* [Route State](routing/route-state/main.go)
* [Route State](routing/route-state/main.go)
* [MVC](mvc)
* [Hello world](mvc/hello-world/main.go)
* [Session Controller](mvc/session-controller/main.go)
* [A simple but featured Controller with model and views](mvc/controller-with-model-and-view)
* [Custom Context](routing/custom-context)
* [Method Overriding](routing/custom-context/method-overriding/main.go)
* [New Implementation](routing/custom-context/new-implementation/main.go)
@@ -121,8 +126,9 @@ It doesn't contains "best ways" neither explains all its features. It's just a s
> Examples are tested using Windows 7, Ubuntu 16.04 with [LiteIDE](https://github.com/visualfc/liteide).
## Run
[Download the examples](https://github.com/iris-contrib/examples/archive/master.zip) and paste them to your `$GOPATH/src/github.com/iris-contrib/examples`.
```sh
```bash
$ cd $GOPATH/src/github.com/iris-contrib/examples/overview
$ go run main.go
```
@@ -133,4 +139,4 @@ $ go run main.go
## Su, 04 June 2017
This repository is just a minor of the github.com/kataras/iris/[version or master]/_examples folder.
This repository is just a minor of the https://github.com/kataras/iris/master/_examples folder.
@@ -16,9 +16,9 @@ func main() {
// Prefix: "With", code editors will help you navigate through all
// configuration options without even a glitch to the documentation.
app.Run(iris.Addr(":8080"), iris.WithoutBanner, iris.WithCharset("UTF-8"))
app.Run(iris.Addr(":8080"), iris.WithoutStartupLog, iris.WithCharset("UTF-8"))
// or before run:
// app.Configure(iris.WithoutBanner, iris.WithCharset("UTF-8"))
// app.Configure(iris.WithoutStartupLog, iris.WithCharset("UTF-8"))
// app.Run(iris.Addr(":8080"))
}
@@ -0,0 +1 @@
<h1>Hello index</h1>
@@ -9,6 +9,17 @@ func main() {
app.Favicon("./assets/favicon.ico")
// enable gzip, optionally:
// if used before the `StaticXXX` handlers then
// the content byte range feature is gone.
// recommend: turn off for large files especially
// when server has low memory,
// turn on for medium-sized files
// or for large-sized files if they are zipped already,
// i.e "zippedDir/file.gz"
//
// app.Use(iris.Gzip)
// first parameter is the request path
// second is the system directory
//
@@ -1,19 +1,27 @@
// +build go.1.8
// +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"
)
func main() {
app := iris.Default()
app := iris.New()
// Optionally, add two built'n handlers
// that can recover from any http-relative panics
// and log the requests to the terminal.
app.Use(recover.New())
app.Use(logger.New())
// Method: GET
// Resource: http://localhost:8080/
app.Handle("GET", "/", func(ctx context.Context) {
ctx.HTML("<b>Hello world!</b>")
ctx.HTML("<b>Welcome!</b>")
})
// same as app.Handle("GET", "/ping", [...])
@@ -32,5 +40,5 @@ func main() {
// http://localhost:8080
// http://localhost:8080/ping
// http://localhost:8080/hello
app.Run(iris.Addr(":8080"))
app.Run(iris.Addr(":8080"), iris.WithoutServerError(iris.ErrServerClosed))
}
@@ -6,7 +6,16 @@ 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
@@ -0,0 +1,2 @@
A silly example for this issue: https://github.com/kataras/iris/issues/688#issuecomment-318828259.
However it seems useful and therefore is being included in the examples for everyone else.
@@ -0,0 +1,31 @@
package counter
import (
"time"
"github.com/kataras/iris"
"github.com/kataras/iris/context"
"github.com/kataras/iris/core/host"
)
func Configurator(app *iris.Application) {
counterValue := 0
go func() {
ticker := time.NewTicker(time.Second)
for range ticker.C {
counterValue++
}
app.ConfigureHost(func(h *host.Supervisor) { // <- HERE: IMPORTANT
h.RegisterOnShutdown(func() {
ticker.Stop()
})
}) // 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) {
ctx.Writef("Counter value = %d", counterValue)
})
}
@@ -0,0 +1,14 @@
package main
import (
"github.com/kataras/iris/_examples/http-listening/iris-configurator-and-host-configurator/counter"
"github.com/kataras/iris"
)
func main() {
app := iris.New()
app.Configure(counter.Configurator)
app.Run(iris.Addr(":8080"))
}
@@ -0,0 +1,53 @@
package main
import (
stdContext "context"
"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) {
ctx.HTML("<h1>Hello, try to refresh the page after ~10 secs</h1>")
})
// app.ConfigureHost(configureHost) -> or pass "configureHost" as `app.Addr` argument, same result.
app.Logger().Info("Wait 10 seconds and check your terminal again")
// simulate a shutdown action here...
go func() {
<-time.After(10 * time.Second)
timeout := 5 * time.Second
ctx, cancel := stdContext.WithTimeout(stdContext.Background(), timeout)
defer cancel()
// close all hosts, this will notify the callback we had register
// inside the `configureHost` func.
app.Shutdown(ctx)
}()
// start the server as usual, the only difference is that
// we're adding a second (optional) function
// to configure the just-created host supervisor.
//
// http://localhost:8080
// wait 10 seconds and check your terminal.
app.Run(iris.Addr(":8080", configureHost), iris.WithoutServerError(iris.ErrServerClosed))
}
func configureHost(su *host.Supervisor) {
// here we have full access to the host that will be created
// inside the `app.Run` function or `NewHost`.
//
// we're registering a shutdown "event" callback here:
su.RegisterOnShutdown(func() {
println("server is closed")
})
// su.RegisterOnError
// su.RegisterOnServe
}
@@ -0,0 +1,45 @@
package main
import (
"fmt"
"github.com/kataras/iris"
"github.com/kataras/iris/context"
"github.com/kataras/iris/middleware/recaptcha"
)
// publicDataSiteKey and secretKey and should be obtained by https://www.google.com/recaptcha.
const (
publicDataSiteKey = ""
secretKey = ""
)
func main() {
app := iris.New()
r := recaptcha.New(secretKey)
app.Get("/comment", showRecaptchaForm)
// pass the middleware before the main handler or use the `recaptcha.SiteVerify`.
app.Post("/comment", r, postComment)
app.Run(iris.Addr(":8080"))
}
var htmlForm = `<form action="/comment" method="POST">
<script src="https://www.google.com/recaptcha/api.js"></script>
<div class="g-recaptcha" data-sitekey="%s"></div>
<input type="submit" name="button" value="Verify">
</form>`
func showRecaptchaForm(ctx context.Context) {
contents := fmt.Sprintf(htmlForm, publicDataSiteKey)
ctx.HTML(contents)
}
func postComment(ctx context.Context) {
// [...]
ctx.JSON(context.Map{"success": true})
}
Oops, something went wrong.

0 comments on commit 4366f68

Please sign in to comment.