mirror of
https://github.com/kataras/iris.git
synced 2025-12-21 03:47:04 +00:00
create a new package, name it as hero, I was thinking super or superb but hero is better name for what it does - the goal is to split the new 'mvc handlers' from the mvc system because they are not the same, users should know that they can use these type of rich binded handlers without controllers as well, like a normal handler and that I implemented here, the old files exist on the mvc package but will be removed at the next commit, I have to decide if we want type aliases for Result or no
Former-commit-id: cb775edc72bedc88aeab4c5a6de6bfc6bd56fae2
This commit is contained in:
60
_examples/hero/overview/main.go
Normal file
60
_examples/hero/overview/main.go
Normal file
@@ -0,0 +1,60 @@
|
||||
// file: main.go
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris/_examples/hero/overview/datasource"
|
||||
"github.com/kataras/iris/_examples/hero/overview/repositories"
|
||||
"github.com/kataras/iris/_examples/hero/overview/services"
|
||||
"github.com/kataras/iris/_examples/hero/overview/web/middleware"
|
||||
"github.com/kataras/iris/_examples/hero/overview/web/routes"
|
||||
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/hero"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
app.Logger().SetLevel("debug")
|
||||
|
||||
// Load the template files.
|
||||
app.RegisterView(iris.HTML("./web/views", ".html"))
|
||||
|
||||
// Create our movie repository with some (memory) data from the datasource.
|
||||
repo := repositories.NewMovieRepository(datasource.Movies)
|
||||
// Create our movie service, we will bind it to the movie app's dependencies.
|
||||
movieService := services.NewMovieService(repo)
|
||||
hero.Register(movieService)
|
||||
|
||||
// Register our routes with hero handlers.
|
||||
app.PartyFunc("/hello", func(r iris.Party) {
|
||||
r.Get("/", hero.Handler(routes.Hello))
|
||||
r.Get("/{name}", hero.Handler(routes.HelloName))
|
||||
})
|
||||
|
||||
app.PartyFunc("/movies", func(r iris.Party) {
|
||||
// Add the basic authentication(admin:password) middleware
|
||||
// for the /movies based requests.
|
||||
r.Use(middleware.BasicAuth)
|
||||
|
||||
r.Get("/", hero.Handler(routes.Movies))
|
||||
r.Get("/{id:long}", hero.Handler(routes.MovieByID))
|
||||
r.Put("/{id:long}", hero.Handler(routes.UpdateMovieByID))
|
||||
r.Delete("/{id:long}", hero.Handler(routes.DeleteMovieByID))
|
||||
})
|
||||
|
||||
// http://localhost:8080/hello
|
||||
// http://localhost:8080/hello/iris
|
||||
// http://localhost:8080/movies
|
||||
// http://localhost:8080/movies/1
|
||||
app.Run(
|
||||
// Start the web server at localhost:8080
|
||||
iris.Addr("localhost:8080"),
|
||||
// disables updates:
|
||||
iris.WithoutVersionChecker,
|
||||
// skip err server closed when CTRL/CMD+C pressed:
|
||||
iris.WithoutServerError(iris.ErrServerClosed),
|
||||
// enables faster json serialization and more:
|
||||
iris.WithOptimizations,
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user