package main

import (
	"iris-demo/library/config"
	"iris-demo/router"
	"iris-demo/router/middleware"

	_ "iris-demo/docs"

	"github.com/iris-contrib/swagger/v12"
	"github.com/iris-contrib/swagger/v12/swaggerFiles"
	"github.com/kataras/iris/v12"
)

// swagger middleware for Iris
// swagger embed files
// @title GAdmin Golang API
// @version 1.0
// @host localhost:8199
// @BasePath /
func main() {
	app := iris.New()

	app.Use(middleware.MiddlewareMock)
	app.Use(middleware.MiddlewareTrace)
	app.Use(middleware.MiddlewareAuth)
	app.Use(middleware.MiddlewareBefore)
	app.Use(middleware.MiddlewareEnd)
	app.Use(middleware.MiddlewareAfter)

	/* casbinMiddleware, err := casbin.NewEnforcer("./config/casbinmodel.conf", "./config/casbinpolicy.csv")
	if err != nil {
		logger.Errorf("casbin Error: %v", err.Error())
	}
	app.Use(casbinMiddleware.ServeHTTP) */

	router.Register(app)       // system
	router.GenRegister(app)    // auto generated
	router.CustomRegister(app) // custom

	// swagger配置方法二：默认文档
	app.Get("/swagger/*any", swagger.WrapHandler(swaggerFiles.Handler))

	app.Run(iris.Addr(config.Config.GetString("server.Address")), iris.WithoutServerError(iris.ErrServerClosed))
}
