package main

import (
	"fmt"
	"os"

	"122.51.31.227/go-course/go18/book/v3/config"
	"122.51.31.227/go-course/go18/book/v3/exception"
	"122.51.31.227/go-course/go18/book/v3/handlers"
	"github.com/gin-gonic/gin"
)

func main() {
	// 加载配置
	path := os.Getenv("CONFIG_PATH")
	if path == "" {
		path = "application.yaml"
	}
	config.LoadConfigFromYaml(path)

	server := gin.New()
	server.Use(gin.Logger(), exception.Recovery())

	handlers.Book.Registry(server)

	ac := config.C().Application
	// 启动服务
	if err := server.Run(fmt.Sprintf("%s:%d", ac.Host, ac.Port)); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}
