master
zggsong 2 years ago
parent ca9eb1a124
commit add9c45a4f

6
.gitignore vendored

@ -18,4 +18,8 @@
# vendor/
# Go workspace file
go.work
go.work
.DS_Store
.idea

@ -1,5 +1,5 @@
server:
port: 1016
port: 8080
datasource:
host: 127.0.0.1
port: 3306

@ -13,7 +13,7 @@ func init() {
workDir, _ := os.Getwd()
viper.SetConfigName("application")
viper.SetConfigType("yml")
viper.AddConfigPath(workDir + "\\config")
viper.AddConfigPath(workDir + "/config")
err := viper.ReadInConfig()
if err != nil {
panic("读取配置文件失败, error=" + err.Error())
@ -27,7 +27,7 @@ func main() {
r = router.CollectRoute(r)
port := viper.GetString("server.port")
if port != "" {
panic(r.Run("127.0.0.1:" + port))
panic(r.Run(":" + port))
}
panic(r.Run("127.0.0.1:8080"))
panic(r.Run(":8080"))
}

@ -17,7 +17,7 @@ func AuthMiddleWare() gin.HandlerFunc {
// 验证token
if tokenString == "" || !strings.HasPrefix(tokenString, "Bearer ") {
c.JSON(http.StatusUnauthorized, gin.H{
c.JSON(http.StatusOK, gin.H{
"code": http.StatusUnauthorized,
"message": "请求未授权",
})
@ -29,7 +29,7 @@ func AuthMiddleWare() gin.HandlerFunc {
token, claims, err := common.ParseToken(tokenString)
if err != nil || !token.Valid {
c.JSON(http.StatusUnauthorized, gin.H{
c.JSON(http.StatusOK, gin.H{
"code": http.StatusUnauthorized,
"message": "请求未授权",
})
@ -44,7 +44,7 @@ func AuthMiddleWare() gin.HandlerFunc {
// 用户不存在
if user.ID == 0 {
c.JSON(http.StatusUnauthorized, gin.H{
c.JSON(http.StatusOK, gin.H{
"code": http.StatusUnauthorized,
"message": "请求未授权",
})

@ -19,5 +19,5 @@ func Success(ctx *gin.Context, data gin.H, msg string) {
}
func Fail(ctx *gin.Context, data gin.H, msg string) {
Response(ctx, http.StatusBadRequest, 400, data, msg)
Response(ctx, http.StatusOK, 400, data, msg)
}

@ -7,8 +7,8 @@ import (
)
func CollectRoute(r *gin.Engine) *gin.Engine {
r.POST("/api/auth/register", controller.Register)
r.POST("/api/auth/login", controller.Login)
r.GET("/api/auth/info", middleware.AuthMiddleWare(), controller.Info) // 认证中间件保护info接口
r.POST("/auth/register", controller.Register)
r.POST("/auth/login", controller.Login)
r.GET("/auth/info", middleware.AuthMiddleWare(), controller.Info) // 认证中间件保护info接口
return r
}

Loading…
Cancel
Save