2017-10-09 14:26:46 +02:00
|
|
|
// file: main.go
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-10-12 02:51:06 +02:00
|
|
|
"github.com/kataras/iris/_examples/mvc/overview/datasource"
|
|
|
|
"github.com/kataras/iris/_examples/mvc/overview/repositories"
|
|
|
|
"github.com/kataras/iris/_examples/mvc/overview/services"
|
|
|
|
"github.com/kataras/iris/_examples/mvc/overview/web/controllers"
|
|
|
|
"github.com/kataras/iris/_examples/mvc/overview/web/middleware"
|
2017-10-09 14:26:46 +02:00
|
|
|
|
|
|
|
"github.com/kataras/iris"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
app := iris.New()
|
2017-10-10 03:46:32 +02:00
|
|
|
|
2017-10-09 14:26:46 +02:00
|
|
|
// Load the template files.
|
2017-10-12 02:51:06 +02:00
|
|
|
app.RegisterView(iris.HTML("./web/views", ".html"))
|
2017-10-09 14:26:46 +02:00
|
|
|
|
|
|
|
// Register our controllers.
|
|
|
|
app.Controller("/hello", new(controllers.HelloController))
|
2017-10-10 03:46:32 +02:00
|
|
|
|
2017-10-12 02:51:06 +02:00
|
|
|
// 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 controller.
|
|
|
|
movieService := services.NewMovieService(repo)
|
2017-10-10 03:46:32 +02:00
|
|
|
|
|
|
|
app.Controller("/movies", new(controllers.MovieController),
|
2017-10-12 02:51:06 +02:00
|
|
|
// Bind the "movieService" to the MovieController's Service (interface) field.
|
|
|
|
movieService,
|
2017-10-10 03:46:32 +02:00
|
|
|
// Add the basic authentication(admin:password) middleware
|
|
|
|
// for the /movies based requests.
|
|
|
|
middleware.BasicAuth)
|
2017-10-09 14:26:46 +02:00
|
|
|
|
|
|
|
// Start the web server at localhost:8080
|
|
|
|
// http://localhost:8080/hello
|
|
|
|
// http://localhost:8080/hello/iris
|
2017-10-12 02:51:06 +02:00
|
|
|
// http://localhost:8080/movies
|
2017-10-09 14:26:46 +02:00
|
|
|
// http://localhost:8080/movies/1
|
|
|
|
app.Run(
|
|
|
|
iris.Addr("localhost:8080"),
|
|
|
|
iris.WithoutVersionChecker,
|
|
|
|
iris.WithoutServerError(iris.ErrServerClosed),
|
|
|
|
iris.WithOptimizations, // enables faster json serialization and more
|
|
|
|
)
|
|
|
|
}
|