2024-11-09 14:59:27 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"yitao/config"
|
|
|
|
"yitao/controller"
|
|
|
|
_ "yitao/docs"
|
|
|
|
"yitao/model"
|
|
|
|
"yitao/service"
|
|
|
|
"yitao/util"
|
|
|
|
"yitao/validate"
|
|
|
|
|
|
|
|
"github.com/iris-contrib/swagger"
|
|
|
|
"github.com/iris-contrib/swagger/swaggerFiles"
|
|
|
|
"github.com/kataras/iris/v12"
|
|
|
|
)
|
|
|
|
|
|
|
|
// @title Yitao Backend API
|
|
|
|
// @version 1.0
|
|
|
|
// @description Yitao Backend API.
|
|
|
|
// @termsOfService http://swagger.io/terms/
|
|
|
|
|
|
|
|
// @contact.name API Support
|
|
|
|
// @contact.url http://www.swagger.io/support
|
|
|
|
// @contact.email support@swagger.io
|
|
|
|
|
|
|
|
// @license.name Apache 2.0
|
|
|
|
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
|
|
|
|
|
|
|
|
// @host localhost:5001
|
|
|
|
// @BasePath /api
|
|
|
|
func main() {
|
|
|
|
app := iris.New()
|
|
|
|
|
|
|
|
swaggerUI := swagger.Handler(swaggerFiles.Handler,
|
|
|
|
swagger.URL("/swagger/swagger.json"),
|
|
|
|
swagger.DeepLinking(true),
|
|
|
|
swagger.Prefix("/swagger"),
|
|
|
|
)
|
|
|
|
|
|
|
|
// Register on http://localhost:5001/swagger
|
|
|
|
app.Get("/swagger", swaggerUI)
|
|
|
|
// And the wildcard one for index.html, *.js, *.css and e.t.c.
|
|
|
|
app.Get("/swagger/{any:path}", swaggerUI)
|
|
|
|
|
2024-11-14 21:52:10 +08:00
|
|
|
// 将网站静态根目录设置为 ./public
|
|
|
|
app.HandleDir("/", "./public")
|
|
|
|
|
2024-11-09 14:59:27 +08:00
|
|
|
conf := config.LoadConfig()
|
|
|
|
|
|
|
|
// init util
|
|
|
|
util.Init(&conf)
|
|
|
|
|
|
|
|
// connect to Database - NexusPHP`s MySQL
|
|
|
|
model.ConnectToDb(conf.DB)
|
|
|
|
model.ConnectToRedis(conf.RDB)
|
|
|
|
|
|
|
|
// init service
|
|
|
|
serv := service.InitService()
|
|
|
|
|
|
|
|
validate.InitValidator()
|
|
|
|
|
|
|
|
// load router
|
|
|
|
controller.LoadRouter(app, serv)
|
|
|
|
|
|
|
|
app.Run(
|
|
|
|
iris.Addr("0.0.0.0:5001"),
|
|
|
|
)
|
|
|
|
}
|