Permalink
Browse files

Update examples for the latest v10.5.0

  • Loading branch information...
kataras committed Mar 24, 2018
1 parent 0f96927 commit 1ef890737f106deef68d97c36df37268a6b068fe
Showing with 21,189 additions and 88 deletions.
  1. +1 −0 README.md
  2. +39 −0 cache/client-side/main.go
  3. +5 −0 cache/simple/main.go
  4. +1 −1 experimental-handlers/casbin/middleware/main_test.go
  5. +1 −3 experimental-handlers/casbin/wrapper/main_test.go
  6. +3 −3 experimental-handlers/csrf/main.go
  7. +2 −1 file-server/embedding-files-into-app/main.go
  8. +20 −0 file-server/embedding-files-into-app/main_test.go
  9. +7,225 −0 file-server/embedding-gziped-files-into-app/assets/css/bootstrap.min.css
  10. BIN file-server/embedding-gziped-files-into-app/assets/favicon.ico
  11. +9,190 −0 file-server/embedding-gziped-files-into-app/assets/js/jquery-2.1.1.js
  12. +3,774 −0 file-server/embedding-gziped-files-into-app/bindata_gzip.go
  13. +35 −0 file-server/embedding-gziped-files-into-app/main.go
  14. +106 −0 file-server/embedding-gziped-files-into-app/main_test.go
  15. +1 −1 file-server/single-page-application/basic/main.go
  16. +0 −3 file-server/single-page-application/basic/main_test.go
  17. +1 −1 file-server/single-page-application/embedded-single-page-application/main.go
  18. +12 −0 file-server/single-page-application/embedded-single-page-application/main_test.go
  19. +2 −2 http-listening/README.md
  20. +65 −0 http_request/read-custom-per-type/main.go
  21. +17 −0 http_request/read-custom-per-type/main_test.go
  22. +73 −0 http_request/read-custom-via-unmarshaler/main.go
  23. +17 −0 http_request/read-custom-via-unmarshaler/main_test.go
  24. +5 −0 http_request/read-form/main.go
  25. +28 −6 http_request/read-json/main.go
  26. +50 −0 http_request/read-xml/main.go
  27. +18 −0 http_request/read-xml/main_test.go
  28. +18 −18 http_responsewriter/herotemplate/app.go
  29. +1 −1 miscellaneous/recover/main.go
  30. +1 −0 mvc/README.md
  31. +1 −1 mvc/basic/main.go
  32. +1 −1 mvc/login/web/controllers/user_controller.go
  33. +1 −1 mvc/login/web/viewmodels/README.md
  34. +45 −0 mvc/middleware/main.go
  35. +105 −0 mvc/middleware/per-method/main.go
  36. +1 −1 mvc/overview/models/README.md
  37. +1 −1 mvc/overview/web/viewmodels/README.md
  38. +1 −1 mvc/websocket/main.go
  39. +14 −8 routing/README.md
  40. +20 −1 routing/dynamic-path/main.go
  41. +8 −0 routing/main.go
  42. +9 −0 routing/main_test.go
  43. +4 −1 routing/reverse/main.go
  44. +18 −5 routing/writing-a-middleware/globally/main.go
  45. +33 −0 routing/writing-a-middleware/per-route/main.go
  46. +2 −1 structuring/bootstrap/bootstrap/bootstrapper.go
  47. +4 −0 subdomains/redirect/hosts
  48. +73 −0 subdomains/redirect/main.go
  49. +30 −0 subdomains/redirect/main_test.go
  50. +27 −10 subdomains/www/main.go
  51. +1 −1 subdomains/www/main_test.go
  52. +3 −3 tutorial/caddy/README.md
  53. +3 −7 tutorial/online-visitors/main.go
  54. +1 −1 tutorial/url-shortener/main.go
  55. +1 −1 tutorial/url-shortener/store.go
  56. +1 −3 view/overview/main.go
  57. +6 −0 view/template_html_4/main.go
  58. +14 −0 view/template_html_4/templates/page.html
  59. +43 −0 view/write-to/main.go
  60. +1 −0 view/write-to/views/email/simple.html
  61. +6 −0 view/write-to/views/shared/email.html
@@ -90,6 +90,7 @@ It doesn't contains "best ways" neither explains all its features. It's just a s
* [Favicon](file-server/favicon/main.go)
* [Basic](file-server/basic/main.go)
* [Embedding Files Into App Executable File](file-server/embedding-files-into-app/main.go)
* [Embedding Gziped Files Into App Executable File](file-server/embedding-gziped-files-into-app/main.go) **NEW**
* [Send/Force-Download Files](file-server/send-files/main.go)
* [Single Page Applications](file-server/single-page-application)
* [Single Page Application](file-server/single-page-application/basic/main.go)
@@ -0,0 +1,39 @@
// Package main shows how you can use the `WriteWithExpiration`
// based on the "modtime", if it's newer than the request header then
// it will refresh the contents, otherwise will let the client (99.9% the browser)
// to handle the cache mechanism, it's faster than iris.Cache because server-side
// has nothing to do and no need to store the responses in the memory.
package main
import (
"time"
"github.com/kataras/iris"
)
const refreshEvery = 10 * time.Second
func main() {
app := iris.New()
app.Use(iris.Cache304(refreshEvery))
// same as:
// app.Use(func(ctx iris.Context) {
// now := time.Now()
// if modified, err := ctx.CheckIfModifiedSince(now.Add(-refresh)); !modified && err == nil {
// ctx.WriteNotModified()
// return
// }
// ctx.SetLastModified(now)
// ctx.Next()
// })
app.Get("/", greet)
app.Run(iris.Addr(":8080"))
}
func greet(ctx iris.Context) {
ctx.Header("X-Custom", "my custom header")
ctx.Writef("Hello World! %s", time.Now())
}
@@ -73,3 +73,8 @@ func writeMarkdown(ctx iris.Context) {
ctx.Markdown(markdownContents)
}
/* Note that `StaticWeb` does use the browser's disk caching by-default
therefore, register the cache handler AFTER any StaticWeb calls,
for a faster solution that server doesn't need to keep track of the response
navigate to https://github.com/kataras/iris/blob/master/_examples/cache/client-side/main.go */
@@ -9,7 +9,7 @@ import (
func TestCasbinMiddleware(t *testing.T) {
app := newApp()
e := httptest.New(t, app, httptest.Debug(true))
e := httptest.New(t, app, httptest.Debug(false))
type ttcasbin struct {
username string
@@ -9,7 +9,7 @@ import (
func TestCasbinWrapper(t *testing.T) {
app := newApp()
e := httptest.New(t, app, httptest.Debug(true))
e := httptest.New(t, app)
type ttcasbin struct {
username string
@@ -43,7 +43,6 @@ func TestCasbinWrapper(t *testing.T) {
check(e, tt.method, tt.path, tt.username, tt.status)
}
println("ADMIN ROLES")
ttAdmin := []ttcasbin{
{"cathrin", "/dataset1/item", "GET", 200},
{"cathrin", "/dataset1/item", "POST", 200},
@@ -57,7 +56,6 @@ func TestCasbinWrapper(t *testing.T) {
check(e, tt.method, tt.path, tt.username, tt.status)
}
println("ADMIN ROLE FOR cathrin DELETED")
Enforcer.DeleteRolesForUser("cathrin")
ttAdminDeleted := []ttcasbin{
@@ -39,12 +39,12 @@ func main() {
}
func getSignupForm(ctx iris.Context) {
// views/signup.html just needs a {{ .csrfField }} template tag for
// views/user/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")
ctx.View("user/signup.html")
// We could also retrieve the token directly from csrf.Token(r) and
// We could also retrieve the token directly from csrf.Token(ctx) 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.
@@ -10,7 +10,8 @@ import (
// $ go build
// $ ./embedding-files-into-app
// "physical" files are not used, you can delete the "assets" folder and run the example.
//
// See `file-server/embedding-gziped-files-into-app` example as well.
func newApp() *iris.Application {
app := iris.New()
@@ -12,6 +12,24 @@ import (
type resource string
// content types that are used in the ./assets,
// we could use the detectContentType that iris do but it's better
// to do it manually so we can test if that returns the correct result on embedding files.
func (r resource) contentType() string {
switch filepath.Ext(r.String()) {
case ".js":
return "application/javascript"
case ".css":
return "text/css"
case ".ico":
return "image/x-icon"
case ".html":
return "text/html"
default:
return "text/plain"
}
}
func (r resource) String() string {
return string(r)
}
@@ -34,6 +52,7 @@ func (r resource) loadFromBase(dir string) string {
}
result := string(b)
if runtime.GOOS != "windows" {
result = strings.Replace(result, "\n", "\r\n", -1)
}
@@ -65,6 +84,7 @@ func TestEmbeddingFilesIntoApp(t *testing.T) {
e.GET(url).Expect().
Status(httptest.StatusOK).
ContentType(u.contentType(), app.ConfigurationReadOnly().GetCharset()).
Body().Equal(contents)
}
}
Oops, something went wrong.

0 comments on commit 1ef8907

Please sign in to comment.