Permalink
Browse files

sync from kataras/iris/_examples

  • Loading branch information...
kataras committed Dec 22, 2017
1 parent 18f2985 commit ebc5bd8a3797dc336a5e8d3c551ce7761e0d3669
Showing with 956 additions and 139 deletions.
  1. +2 −0 .gitattributes
  2. +2 −2 README.md
  3. +6 −7 apidoc/yaag/main.go
  4. +0 −6 authentication/README.md
  5. +1 −1 cache/simple/main.go
  6. +55 −0 experimental-handlers/csrf/main.go
  7. +4 −0 experimental-handlers/csrf/views/user/signup.html
  8. +46 −0 experimental-handlers/jwt/main.go
  9. +3 −3 file-server/embedding-files-into-app/bindata.go
  10. +3 −3 file-server/embedding-files-into-app/main_test.go
  11. +285 −0 file-server/single-page-application/embedded-single-page-application-with-other-routes/bindata.go
  12. +55 −0 file-server/single-page-application/embedded-single-page-application-with-other-routes/main.go
  13. +1 −0 file-server/single-page-application/embedded-single-page-application-with-other-routes/public/app.js
  14. +3 −0 ...er/single-page-application/embedded-single-page-application-with-other-routes/public/css/main.css
  15. +14 −0 ...rver/single-page-application/embedded-single-page-application-with-other-routes/public/index.html
  16. +7 −1 file-server/single-page-application/embedded-single-page-application/main.go
  17. +3 −4 file-server/single-page-application/embedded-single-page-application/main_test.go
  18. +1 −1 http-listening/iris-configurator-and-host-configurator/main.go
  19. +26 −0 http_responsewriter/hero/README.md
  20. +55 −0 http_responsewriter/hero/app.go
  21. +11 −0 http_responsewriter/hero/template/index.html
  22. +3 −0 http_responsewriter/hero/template/index.html.go
  23. +3 −0 http_responsewriter/hero/template/user.html
  24. +3 −0 http_responsewriter/hero/template/user.html.go
  25. +11 −0 http_responsewriter/hero/template/userlist.html
  26. +41 −0 http_responsewriter/hero/template/userlist.html.go
  27. +11 −0 http_responsewriter/hero/template/userlistwriter.html
  28. +44 −0 http_responsewriter/hero/template/userlistwriter.html.go
  29. +1 −1 http_responsewriter/quicktemplate/controllers/execute_template.go
  30. +1 −1 http_responsewriter/quicktemplate/controllers/hello.go
  31. +1 −1 http_responsewriter/quicktemplate/controllers/index.go
  32. +1 −1 http_responsewriter/quicktemplate/main.go
  33. +21 −0 http_responsewriter/write-gzip/main.go
  34. +1 −0 miscellaneous/i18n/locales/locale_multi_first_el-GR.ini
  35. +1 −0 miscellaneous/i18n/locales/locale_multi_first_en-US.ini
  36. +1 −0 miscellaneous/i18n/locales/locale_multi_second_el-GR.ini
  37. +1 −0 miscellaneous/i18n/locales/locale_multi_second_en-US.ini
  38. +27 −3 miscellaneous/i18n/main.go
  39. +24 −4 miscellaneous/i18n/main_test.go
  40. +44 −0 miscellaneous/recaptcha/custom_form/main.go
  41. +22 −26 miscellaneous/recaptcha/main.go
  42. +1 −1 mvc/login/datasource/users.go
  43. +5 −5 mvc/login/main.go
  44. +2 −1 mvc/login/repositories/user_repository.go
  45. +2 −2 mvc/login/services/user_service.go
  46. +2 −2 mvc/login/web/controllers/user_controller.go
  47. +2 −2 mvc/login/web/controllers/users_controller.go
  48. +1 −1 mvc/login/web/viewmodels/README.md
  49. +1 −1 mvc/overview/datasource/movies.go
  50. +5 −5 mvc/overview/main.go
  51. +1 −1 mvc/overview/models/README.md
  52. +2 −1 mvc/overview/repositories/movie_repository.go
  53. +2 −2 mvc/overview/services/movie_service.go
  54. +2 −2 mvc/overview/web/controllers/movie_controller.go
  55. +1 −1 mvc/overview/web/viewmodels/README.md
  56. +6 −7 overview/main.go
  57. +22 −0 overview/views/user/create_verification.html
  58. +7 −0 overview/views/user/profile.html
  59. +1 −0 routing/main.go
  60. +4 −6 sessions/database/badger/main.go
  61. +0 −2 sessions/database/boltdb/main.go
  62. +6 −6 sessions/database/file/main.go
  63. +0 −3 sessions/database/leveldb/main.go
  64. +0 −2 sessions/database/redis/main.go
  65. +7 −0 structuring/bootstrap/bootstrap/bootstrapper.go
  66. +8 −9 structuring/bootstrap/main.go
  67. +1 −0 structuring/bootstrap/main_test.go
  68. +1 −1 structuring/bootstrap/middleware/identity/identity.go
  69. +1 −1 structuring/bootstrap/routes/routes.go
  70. +1 −1 structuring/login-mvc-single-responsibility-package/main.go
  71. +3 −3 tutorial/caddy/README.md
  72. +2 −2 tutorial/dropzonejs/README.md
  73. +2 −2 tutorial/dropzonejs/README_PART2.md
  74. +8 −0 tutorial/dropzonejs/meta.yml
  75. +1 −1 tutorial/url-shortener/main.go
  76. +1 −1 websocket/connectionlist/main.go
@@ -0,0 +1,2 @@
*.go linguist-language=Go
* text=auto
@@ -53,7 +53,7 @@ It doesn't contains "best ways" neither explains all its features. It's just a s
* [Hello world](mvc/hello-world/main.go)
* [Session Controller](mvc/session-controller/main.go)
* [Overview - Plus Repository and Service layers](mvc/overview/main.go)
* [Login showcase - Plus Repository and Service layers](mvc/login/main.go) (mvc/using-method-result)
* [Login showcase - Plus Repository and Service layers](mvc/login/main.go)
* [Custom Context](routing/custom-context)
* [Method Overriding](routing/custom-context/method-overriding/main.go)
* [New Implementation](routing/custom-context/new-implementation/main.go)
@@ -83,7 +83,7 @@ It doesn't contains "best ways" neither explains all its features. It's just a s
* [Basic](file-server/basic/main.go)
* [Embedding Files Into App Executable File](file-server/embedding-files-into-app/main.go)
* [Send/Force-Download Files](file-server/send-files/main.go)
* [Single Page Applications](file-server/single-page/application)
* [Single Page Applications](file-server/single-page-application)
* [Single Page Application](file-server/single-page-application/basic/main.go)
* [Embedded Single Page Application](file-server/single-page-application/embedded-single-page-application/main.go)
* [How to Read from *http.Request`](http_reqest)
@@ -2,7 +2,6 @@ package main
import (
"github.com/kataras/iris"
"github.com/kataras/iris/context"
"github.com/betacraft/yaag/irisyaag"
"github.com/betacraft/yaag/yaag"
@@ -27,21 +26,21 @@ func main() {
})
app.Use(irisyaag.New()) // <- IMPORTANT, register the middleware.
app.Get("/json", func(ctx context.Context) {
ctx.JSON(context.Map{"result": "Hello World!"})
app.Get("/json", func(ctx iris.Context) {
ctx.JSON(iris.Map{"result": "Hello World!"})
})
app.Get("/plain", func(ctx context.Context) {
app.Get("/plain", func(ctx iris.Context) {
ctx.Text("Hello World!")
})
app.Get("/xml", func(ctx context.Context) {
app.Get("/xml", func(ctx iris.Context) {
ctx.XML(myXML{Result: "Hello World!"})
})
app.Get("/complex", func(ctx context.Context) {
app.Get("/complex", func(ctx iris.Context) {
value := ctx.URLParam("key")
ctx.JSON(context.Map{"value": value})
ctx.JSON(iris.Map{"value": value})
})
// Run our HTTP Server.

This file was deleted.

Oops, something went wrong.
@@ -58,7 +58,7 @@ All features of Sundown are supported, including:
// Cache is a good and a must-feature on static content, i.e "about page" or for a whole blog site.
func main() {
app := iris.New()
app.Logger().SetLevel("debug")
app.Get("/", cache.Handler(10*time.Second), writeMarkdown)
// saves its content on the first request and serves it instead of re-calculating the content.
// After 10 seconds it will be cleared and resetted.
@@ -0,0 +1,55 @@
// This middleware provides Cross-Site Request Forgery
// protection.
//
// It securely generates a masked (unique-per-request) token that
// can be embedded in the HTTP response (e.g. form field or HTTP header).
// The original (unmasked) token is stored in the session, which is inaccessible
// by an attacker (provided you are using HTTPS). Subsequent requests are
// expected to include this token, which is compared against the session token.
// Requests that do not provide a matching token are served with a HTTP 403
// 'Forbidden' error response.
package main
// $ go get -u github.com/iris-contrib/middleware/...
import (
"github.com/kataras/iris"
"github.com/iris-contrib/middleware/csrf"
)
func main() {
app := iris.New()
app.RegisterView(iris.HTML("./views", ".html"))
// Note that the authentication key provided should be 32 bytes
// long and persist across application restarts.
protect := csrf.Protect([]byte("9AB0F421E53A477C084477AEA06096F5"),
csrf.Secure(false)) // Defaults to true, but pass `false` while no https (devmode).
users := app.Party("/user", protect)
{
users.Get("/signup", getSignupForm)
// // POST requests without a valid token will return a HTTP 403 Forbidden.
users.Post("/signup", postSignupForm)
}
// GET: http://localhost:8080/user/signup
// POST: http://localhost:8080/user/signup
app.Run(iris.Addr(":8080"))
}
func getSignupForm(ctx iris.Context) {
// views/signup.html just needs a {{ .csrfField }} template tag for
// csrf.TemplateField to inject the CSRF token into. Easy!
ctx.ViewData(csrf.TemplateTag, csrf.TemplateField(ctx))
ctx.View("views/user/signup.html")
// We could also retrieve the token directly from csrf.Token(r) and
// set it in the request header - ctx.GetHeader("X-CSRF-Token", token)
// This is useful if you're sending JSON to clients or a front-end JavaScript
// framework.
}
func postSignupForm(ctx iris.Context) {
ctx.Writef("You're welcome mate!")
}
@@ -0,0 +1,4 @@
<form method="POST" action="/user/signup">
{{ .csrfField }}
<button type="submit">Procceed</button>
</form>
@@ -0,0 +1,46 @@
// iris provides some basic middleware, most for your learning courve.
// You can use any net/http compatible middleware with iris.FromStd wrapper.
//
// JWT net/http video tutorial for golang newcomers: https://www.youtube.com/watch?v=dgJFeqeXVKw
//
// This middleware is the only one cloned from external source: https://github.com/auth0/go-jwt-middleware
// (because it used "context" to define the user but we don't need that so a simple iris.FromStd wouldn't work as expected.)
package main
// $ go get -u github.com/dgrijalva/jwt-go
// $ go run main.go
import (
"github.com/kataras/iris"
"github.com/dgrijalva/jwt-go"
jwtmiddleware "github.com/iris-contrib/middleware/jwt"
)
func myHandler(ctx iris.Context) {
user := ctx.Values().Get("jwt").(*jwt.Token)
ctx.Writef("This is an authenticated request\n")
ctx.Writef("Claim content:\n")
ctx.Writef("%s", user.Signature)
}
func main() {
app := iris.New()
jwtHandler := jwtmiddleware.New(jwtmiddleware.Config{
ValidationKeyGetter: func(token *jwt.Token) (interface{}, error) {
return []byte("My Secret"), nil
},
// When set, the middleware verifies that tokens are signed with the specific signing algorithm
// If the signing method is not constant the ValidationKeyGetter callback can be used to implement additional checks
// Important to avoid security issues described here: https://auth0.com/blog/2015/03/31/critical-vulnerabilities-in-json-web-token-libraries/
SigningMethod: jwt.SigningMethodHS256,
})
app.Use(jwtHandler.Serve)
app.Get("/ping", myHandler)
app.Run(iris.Addr("localhost:3001"))
} // don't forget to look ../jwt_test.go to seee how to set your own custom claims

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -34,9 +34,9 @@ func (r resource) loadFromBase(dir string) string {
}
result := string(b)
if runtime.GOOS != "windows" {
result = strings.Replace(result, "\n", "\r\n", -1)
}
//if runtime.GOOS != "windows" {
// result = strings.Replace(result, "\n", "\r\n", -1)
//}
return result
}
Oops, something went wrong.

0 comments on commit ebc5bd8

Please sign in to comment.