go17/book/main.go

43 lines
1.0 KiB
Go
Raw Normal View History

2024-11-16 17:22:21 +08:00
package main
import (
"fmt"
2024-11-16 18:11:24 +08:00
"log"
2024-11-16 17:22:21 +08:00
"os"
2024-11-16 18:11:24 +08:00
"github.com/gin-gonic/gin"
2025-05-07 11:06:40 +08:00
book "gitlab.com/go-course-project/go17/book/api"
// user "gitlab.com/go-course-project/go17/user/api"
// comment "gitlab.com/go-course-project/go17/comment/api"
// token "gitlab.com/go-course-project/go17/token/api"
2024-11-16 17:22:21 +08:00
"gitlab.com/go-course-project/go17/book/config"
)
2024-11-16 18:11:24 +08:00
// 规定好风格: JSON Restful Api
2024-11-16 17:22:21 +08:00
func main() {
// 从配置文件中加载配置
// 加载配置
path := os.Getenv("CONFIG_PATH")
if path == "" {
path = "application.yaml"
}
2024-11-16 18:11:24 +08:00
if err := config.LoadConfigFromYaml(path); err != nil {
fmt.Printf("加载配置错误: %s\n", err)
os.Exit(1)
}
2024-11-16 17:22:21 +08:00
// 访问加载后的配置
conf := config.Get()
2024-11-16 18:11:24 +08:00
// gin Engine, 它包装了http server
server := gin.Default()
2025-05-07 11:06:40 +08:00
book.NewBookApiHandler().Registry(server)
// user.NewUserApiHandler().Registry(server)
// comment.NewCommentApiHandler().Registry(server)
// token.NewTokenApiHandler().Registry(server)
2024-11-16 18:11:24 +08:00
if err := server.Run(conf.App.Address()); err != nil {
log.Println(err)
}
}