|
|
@@ -1,35 +1,23 @@
|
|
|
package main
|
|
|
|
|
|
import (
|
|
|
- "net/http"
|
|
|
- "strings"
|
|
|
+ "fmt"
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
+ "github.com/runningwater/gohub/bootstrap"
|
|
|
)
|
|
|
|
|
|
func main() {
|
|
|
+ // 设置 Gin 模式为开发模式
|
|
|
+ gin.SetMode(gin.DebugMode)
|
|
|
+
|
|
|
r:= gin.New()
|
|
|
|
|
|
- r.Use(gin.Logger(), gin.Recovery())
|
|
|
+ // 初始化路由绑定
|
|
|
+ bootstrap.SetupRoute(r)
|
|
|
|
|
|
- r.GET("/", func(c *gin.Context) {
|
|
|
- c.JSON(http.StatusOK, gin.H{
|
|
|
- "message": "hell",
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- // 处理 404 请求
|
|
|
- r.NoRoute(func(c *gin.Context) {
|
|
|
- acceptString := c.Request.Header.Get("Accept")
|
|
|
- if strings.Contains(acceptString, "text/html") {
|
|
|
- c.String(http.StatusNotFound, "页面返回 404, Not Found")
|
|
|
- }else {
|
|
|
- c.JSON(http.StatusNotFound, gin.H{
|
|
|
- "error_code": 404,
|
|
|
- "error_message": "404 Not Found",
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
-
|
|
|
- r.Run(":8080")
|
|
|
+ err := r.Run(":8080")
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("启动失败", err.Error())
|
|
|
+ }
|
|
|
}
|