1 Star 0 Fork 0

hh/iris

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.go 1.86 KB
一键复制 编辑 原始数据 按行查看 历史
// 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)
// Serve 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,
)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/w1229748769/iris.git
git@gitee.com:w1229748769/iris.git
w1229748769
iris
iris
v10.6.6

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385