Permalink
Browse files

organize examples

  • Loading branch information...
kataras committed Oct 22, 2017
1 parent 14823ae commit c2ef49009c938cec834a4b0ac069851778f9f0b8
Showing with 1,707 additions and 804 deletions.
  1. +8 −4 README.md
  2. +2 −2 convert-handlers/negroni-like/main.go
  3. +2 −2 convert-handlers/nethttp/main.go
  4. +45 −0 convert-handlers/real-usecase-raven/wrapping-the-router/main.go
  5. +57 −0 convert-handlers/real-usecase-raven/writing-middleware/main.go
  6. +1 −1 http-listening/iris-configurator-and-host-configurator/main.go
  7. +1 −1 http_responsewriter/quicktemplate/controllers/execute_template.go
  8. +1 −1 http_responsewriter/quicktemplate/controllers/hello.go
  9. +1 −1 http_responsewriter/quicktemplate/controllers/index.go
  10. +1 −1 http_responsewriter/quicktemplate/main.go
  11. +0 −111 mvc/controller-with-model-and-view/main.go
  12. +0 −13 mvc/controller-with-model-and-view/views/profile/index.html
  13. +0 −13 mvc/controller-with-model-and-view/views/profile/me.html
  14. +0 −13 mvc/controller-with-model-and-view/views/profile/notfound.html
  15. +0 −13 mvc/controller-with-model-and-view/views/profile/profile.html
  16. +31 −9 mvc/hello-world/main.go
  17. +0 −20 mvc/login/database/database.go
  18. +41 −0 mvc/login/datamodels/user.go
  19. +31 −0 mvc/login/datasource/users.go
  20. BIN mvc/login/folder_structure.png
  21. +48 −20 mvc/login/main.go
  22. +173 −0 mvc/login/repositories/user_repository.go
  23. +125 −0 mvc/login/services/user_service.go
  24. +189 −0 mvc/login/web/controllers/user_controller.go
  25. +101 −0 mvc/login/web/controllers/users_controller.go
  26. 0 mvc/{using-method-result → login/web}/middleware/basicauth.go
  27. 0 mvc/login/{ → web}/public/css/site.css
  28. +55 −0 mvc/login/web/viewmodels/README.md
  29. +15 −0 mvc/login/web/views/shared/error.html
  30. 0 mvc/login/{ → web}/views/shared/layout.html
  31. 0 mvc/login/{ → web}/views/user/login.html
  32. 0 mvc/login/{ → web}/views/user/me.html
  33. 0 mvc/login/{ → web}/views/user/register.html
  34. +1 −0 mvc/overview/datamodels/README.md
  35. +18 −0 mvc/overview/datamodels/movie.go
  36. +1 −0 mvc/overview/datasource/README.md
  37. +2 −2 mvc/{using-method-result → overview}/datasource/movies.go
  38. BIN mvc/overview/folder_structure.png
  39. +13 −9 mvc/{using-method-result → overview}/main.go
  40. +20 −0 mvc/overview/models/README.md
  41. +3 −0 mvc/overview/repositories/README.md
  42. +175 −0 mvc/overview/repositories/movie_repository.go
  43. +3 −0 mvc/overview/services/README.md
  44. +65 −0 mvc/overview/services/movie_service.go
  45. +1 −1 mvc/{using-method-result → overview/web}/controllers/hello_controller.go
  46. +20 −15 mvc/{using-method-result → overview/web}/controllers/movie_controller.go
  47. +12 −0 mvc/overview/web/middleware/basicauth.go
  48. +55 −0 mvc/overview/web/viewmodels/README.md
  49. +1 −1 mvc/{using-method-result → overview/web}/views/hello/index.html
  50. +1 −1 mvc/{using-method-result → overview/web}/views/hello/name.html
  51. +50 −12 mvc/session-controller/main.go
  52. BIN mvc/using-method-result/folder_structure.png
  53. +0 −41 mvc/using-method-result/models/movie.go
  54. +0 −206 mvc/using-method-result/services/movie_service.go
  55. 0 structuring/{handler-based → bootstrap}/bootstrap/bootstrapper.go
  56. BIN structuring/bootstrap/folder_structure.png
  57. +20 −0 structuring/bootstrap/main.go
  58. +1 −1 structuring/{handler-based → bootstrap}/main_test.go
  59. +1 −1 structuring/{handler-based → bootstrap}/middleware/identity/identity.go
  60. BIN structuring/{handler-based → bootstrap}/public/favicon.ico
  61. 0 structuring/{handler-based → bootstrap}/routes/follower.go
  62. 0 structuring/{handler-based → bootstrap}/routes/following.go
  63. 0 structuring/{handler-based → bootstrap}/routes/index.go
  64. 0 structuring/{handler-based → bootstrap}/routes/like.go
  65. +1 −1 structuring/{handler-based → bootstrap}/routes/routes.go
  66. 0 structuring/{handler-based → bootstrap}/views/index.html
  67. 0 structuring/{handler-based → bootstrap}/views/shared/error.html
  68. 0 structuring/{handler-based → bootstrap}/views/shared/layout.html
  69. +0 −20 structuring/handler-based/main.go
  70. BIN structuring/login-mvc-single-responsibility-package/folder_structure.png
  71. +43 −0 structuring/login-mvc-single-responsibility-package/main.go
  72. +61 −0 structuring/login-mvc-single-responsibility-package/public/css/site.css
  73. 0 {mvc/login → structuring/login-mvc-single-responsibility-package}/user/auth.go
  74. 0 {mvc/login → structuring/login-mvc-single-responsibility-package}/user/controller.go
  75. 0 {mvc/login → structuring/login-mvc-single-responsibility-package}/user/datasource.go
  76. 0 {mvc/login → structuring/login-mvc-single-responsibility-package}/user/model.go
  77. 0 {mvc/login → structuring/login-mvc-single-responsibility-package}/views/shared/error.html
  78. +12 −0 structuring/login-mvc-single-responsibility-package/views/shared/layout.html
  79. +11 −0 structuring/login-mvc-single-responsibility-package/views/user/login.html
  80. +3 −0 structuring/login-mvc-single-responsibility-package/views/user/me.html
  81. 0 {mvc/login → structuring/login-mvc-single-responsibility-package}/views/user/notfound.html
  82. +14 −0 structuring/login-mvc-single-responsibility-package/views/user/register.html
  83. +1 −0 structuring/login-mvc/README.md
  84. +1 −0 structuring/mvc-plus-repository-and-service-layers/README.md
  85. +0 −144 structuring/mvc/app/app.go
  86. +0 −13 structuring/mvc/app/controllers/follower/controller.go
  87. +0 −13 structuring/mvc/app/controllers/following/controller.go
  88. +0 −14 structuring/mvc/app/controllers/index/controller.go
  89. +0 −13 structuring/mvc/app/controllers/like/controller.go
  90. +0 −1 structuring/mvc/app/views/index.html
  91. +0 −5 structuring/mvc/app/views/shared/error.html
  92. +0 −23 structuring/mvc/app/views/shared/layout.html
  93. +0 −15 structuring/mvc/main.go
  94. BIN structuring/mvc/public/favicon.ico
  95. +3 −3 tutorial/caddy/README.md
  96. +1 −1 tutorial/dropzonejs/README_PART2.md
  97. +2 −1 tutorial/dropzonejs/src/main.go
  98. +1 −1 tutorial/url-shortener/main.go
  99. +83 −10 view/embedding-templates-into-app/bindata.go
  100. BIN view/embedding-templates-into-app/embedding-templates-into-app.exe
  101. +45 −11 view/embedding-templates-into-app/main.go
  102. +12 −0 view/embedding-templates-into-app/templates/layouts/layout.html
  103. +12 −0 view/embedding-templates-into-app/templates/layouts/mylayout.html
  104. +7 −0 view/embedding-templates-into-app/templates/page1.html
  105. +3 −0 view/embedding-templates-into-app/templates/partials/page1_partial1.html
@@ -16,6 +16,11 @@ It doesn't contains "best ways" neither explains all its features. It's just a s
* [Tutorial: Online Visitors](tutorial/online-visitors/main.go)
* [Tutorial: URL Shortener using BoltDB](tutorial/url-shortener/main.go)
* [Tutorial: DropzoneJS + Go: How to build a file upload form](tutorial/dropzonejs/main.go)
* [Structuring](structuring)
* [Bootstrapper](structuring/bootstrap/bootstrap.main.go)
* [MVC with Repository and Service layer Overview](mvc/overview/main.go)
* [Login (MVC with Single Responsibility package)](structuring/login-mvc-single-responsible-package/main.go)
* [Login (MVC with Datamodels, Datasource, Repository and Service layer)](mvc/login/main.go)
* [HTTP Listening](http-listening)
* [Common, with address](http-listening/listen-addr/main.go)
* [UNIX socket file](http-listening/listen-unix/main.go)
@@ -45,9 +50,8 @@ It doesn't contains "best ways" neither explains all its features. It's just a s
* [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/main.go)
* [Login showcase](mvc/login/main.go)
* [Render using the method result (plus Service-oriented design)](mvc/using-method-result)
* [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)
* [Custom Context](routing/custom-context)
* [Method Overriding](routing/custom-context/method-overriding/main.go)
* [New Implementation](routing/custom-context/new-implementation/main.go)
@@ -79,7 +83,7 @@ It doesn't contains "best ways" neither explains all its features. It's just a s
* [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)
* [Embedded Single Page Application](file-server/single-page-application/embedded-single-page-application/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)
* [Bind JSON](http_request/read-json/main.go)
* [Bind Form](http_request/read-form/main.go)
@@ -8,8 +8,8 @@ import (
func main() {
app := iris.New()
ionMiddleware := iris.FromStd(negronilikeTestMiddleware)
app.Use(ionMiddleware)
irisMiddleware := iris.FromStd(negronilikeTestMiddleware)
app.Use(irisMiddleware)
// Method GET: http://localhost:8080/
app.Get("/", func(ctx iris.Context) {
@@ -8,8 +8,8 @@ import (
func main() {
app := iris.New()
ionMiddleware := iris.FromStd(nativeTestMiddleware)
app.Use(ionMiddleware)
irisMiddleware := iris.FromStd(nativeTestMiddleware)
app.Use(irisMiddleware)
// Method GET: http://localhost:8080/
app.Get("/", func(ctx iris.Context) {
@@ -0,0 +1,45 @@
package main
import (
"errors"
"fmt"
"net/http"
"runtime/debug"
"github.com/kataras/iris"
"github.com/getsentry/raven-go"
)
// https://docs.sentry.io/clients/go/integrations/http/
func init() {
raven.SetDSN("https://<key>:<secret>@sentry.io/<project>")
}
func main() {
app := iris.New()
app.Get("/", func(ctx iris.Context) {
ctx.Writef("Hi")
})
// Example for WrapRouter is already here:
// https://github.com/kataras/iris/blob/master/_examples/routing/custom-wrapper/main.go#L53
app.WrapRouter(func(w http.ResponseWriter, r *http.Request, irisRouter http.HandlerFunc) {
// Exactly the same source code:
// https://github.com/getsentry/raven-go/blob/379f8d0a68ca237cf8893a1cdfd4f574125e2c51/http.go#L70
defer func() {
if rval := recover(); rval != nil {
debug.PrintStack()
rvalStr := fmt.Sprint(rval)
packet := raven.NewPacket(rvalStr, raven.NewException(errors.New(rvalStr), raven.NewStacktrace(2, 3, nil)), raven.NewHttp(r))
raven.Capture(packet, nil)
w.WriteHeader(http.StatusInternalServerError)
}
}()
irisRouter(w, r)
})
app.Run(iris.Addr(":8080"))
}
@@ -0,0 +1,57 @@
package main
import (
"errors"
"fmt"
"runtime/debug"
"github.com/kataras/iris"
"github.com/getsentry/raven-go"
)
// At this example you will see how to convert any net/http middleware
// that has the form of `(HandlerFunc) HandlerFunc`.
// If the `raven.RecoveryHandler` had the form of
// `(http.HandlerFunc)` or `(http.HandlerFunc, next http.HandlerFunc)`
// you could just use the `irisMiddleware := iris.FromStd(nativeHandler)`
// but it doesn't, however as you already know Iris can work with net/http directly
// because of the `ctx.ResponseWriter()` and `ctx.Request()` are the original
// http.ResponseWriter and *http.Request.
// (this one is a big advantage, as a result you can use Iris for ever :)).
//
// The source code of the native middleware does not change at all.
// https://github.com/getsentry/raven-go/blob/379f8d0a68ca237cf8893a1cdfd4f574125e2c51/http.go#L70
// The only addition is the Line 18 and Line 39 (instead of handler(w,r))
// and you have a new iris middleware ready to use!
func irisRavenMiddleware(ctx iris.Context) {
w, r := ctx.ResponseWriter(), ctx.Request()
defer func() {
if rval := recover(); rval != nil {
debug.PrintStack()
rvalStr := fmt.Sprint(rval)
packet := raven.NewPacket(rvalStr, raven.NewException(errors.New(rvalStr), raven.NewStacktrace(2, 3, nil)), raven.NewHttp(r))
raven.Capture(packet, nil)
w.WriteHeader(iris.StatusInternalServerError)
}
}()
ctx.Next()
}
// https://docs.sentry.io/clients/go/integrations/http/
func init() {
raven.SetDSN("https://<key>:<secret>@sentry.io/<project>")
}
func main() {
app := iris.New()
app.Use(irisRavenMiddleware)
app.Get("/", func(ctx iris.Context) {
ctx.Writef("Hi")
})
app.Run(iris.Addr(":8080"))
}
@@ -1,7 +1,7 @@
package main
import (
"github.com/kataras/iris/_examples/http-listening/iris-configurator-and-host-configurator/counter"
"github.com/iris-contrib/examples/http-listening/iris-configurator-and-host-configurator/counter"
"github.com/kataras/iris"
)
@@ -1,7 +1,7 @@
package controllers
import (
"github.com/kataras/iris/_examples/http_responsewriter/quicktemplate/templates"
"github.com/iris-contrib/examples/http_responsewriter/quicktemplate/templates"
"github.com/kataras/iris"
)
@@ -1,7 +1,7 @@
package controllers
import (
"github.com/kataras/iris/_examples/http_responsewriter/quicktemplate/templates"
"github.com/iris-contrib/examples/http_responsewriter/quicktemplate/templates"
"github.com/kataras/iris"
)
@@ -1,7 +1,7 @@
package controllers
import (
"github.com/kataras/iris/_examples/http_responsewriter/quicktemplate/templates"
"github.com/iris-contrib/examples/http_responsewriter/quicktemplate/templates"
"github.com/kataras/iris"
)
@@ -1,7 +1,7 @@
package main
import (
"github.com/kataras/iris/_examples/http_responsewriter/quicktemplate/controllers"
"github.com/iris-contrib/examples/http_responsewriter/quicktemplate/controllers"
"github.com/kataras/iris"
)

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit c2ef490

Please sign in to comment.