Parcourir la source

日志文件修改

huangyan il y a 3 mois
Parent
commit
9f74b94ab9

+ 1 - 1
Makefile

@@ -1,4 +1,4 @@
-BINARY_NAME := cc-officialweb
+BINARY_NAME := Panel_development
 GOOS := linux
 GOARCH := amd64
 

+ 1 - 1
app/controller/componentClassify.go

@@ -16,7 +16,7 @@ var ComponentClassify service.ComponentClassify = &model.ComponentClassify{}
 func GetComponentClassify(c *gin.Context) {
 	classify, err := ComponentClassify.GetComponentClassify()
 	if err != nil {
-		e.ResponseWithMsg(c, e.ERROR, err.Error())
+		e.ResponseWithMsg(c, e.ERROR, "获取分类失败")
 	} else {
 		e.ResponseSuccess(c, classify)
 	}

+ 5 - 5
app/controller/pageManage.go

@@ -12,7 +12,7 @@ import (
 
 var PageManage service.Page = &model.PageManage{}
 
-// GetPageManage 获取页面管理
+// GetPageManage 获取页面
 func GetPageManage(c *gin.Context) {
 	var page unity.QueryPageParams
 	uid := unity.GetUId(c)
@@ -46,7 +46,7 @@ func GetPageManage(c *gin.Context) {
 	e.ResPonsePage(c, result, total, page)
 }
 
-// GetPageManageById 获取页面详情
+// GetPageManageById 获取页面
 func GetPageManageById(c *gin.Context) {
 	uid := unity.GetUId(c)
 	s := c.Query("id")
@@ -77,7 +77,7 @@ func GetPageManageById(c *gin.Context) {
 	e.ResponseSuccess(c, byId)
 }
 
-// AddPageManage 添加页面管理
+// AddPageManage 添加页面
 func AddPageManage(c *gin.Context) {
 	var page model.PageManage
 	if err := c.ShouldBindJSON(&page); err != nil {
@@ -104,7 +104,7 @@ func AddPageManage(c *gin.Context) {
 	e.ResponseSuccess(c, add)
 }
 
-// UpdatePageManage 更新页面管理
+// UpdatePageManage 更新页面
 func UpdatePageManage(c *gin.Context) {
 	uid := unity.GetUId(c)
 	s := c.Query("id")
@@ -148,7 +148,7 @@ func UpdatePageManage(c *gin.Context) {
 	e.ResponseSuccess(c, nil)
 }
 
-// DeletePageManage 删除页面管理
+// DeletePageManage 删除页面
 func DeletePageManage(c *gin.Context) {
 	uid := unity.GetUId(c)
 	s := c.Query("id")

+ 3 - 1
app/middleware/admin_middleware.go

@@ -5,13 +5,15 @@ import (
 	"Panel_development/nats"
 	"github.com/bytedance/sonic"
 	"github.com/gin-gonic/gin"
+	"strings"
 	"time"
 )
 
 func AdminMiddleware() gin.HandlerFunc {
 	return func(c *gin.Context) {
 		header := c.GetHeader("Authorization")
-		request, err := nats.Nats.Request("login_token_validation", []byte(header), 3*time.Second)
+		split := strings.Split(header, ":")
+		request, err := nats.Nats.Request("login_token_validation", []byte(split[1]), 3*time.Second)
 		if err != nil {
 			e.ResponseWithMsg(c, e.TokenIsInvalid, e.TokenIsInvalid.GetMsg())
 		} else {

+ 9 - 1
app/middleware/login_middleware.go

@@ -5,6 +5,7 @@ import (
 	"Panel_development/nats"
 	"github.com/bytedance/sonic"
 	"github.com/gin-gonic/gin"
+	"strings"
 	"time"
 )
 
@@ -17,9 +18,16 @@ type UserResponse struct {
 func LoginMiddleware() gin.HandlerFunc {
 	return func(c *gin.Context) {
 		header := c.GetHeader("Authorization")
-		request, err := nats.Nats.Request("login_token_validation", []byte(header), 3*time.Second)
+		split := strings.Split(header, ":")
+		if len(split) != 2 {
+			e.ResponseWithMsg(c, e.TokenIsInvalid, e.TokenIsInvalid.GetMsg())
+			c.Abort()
+			return
+		}
+		request, err := nats.Nats.Request("login_token_validation", []byte(split[1]), 3*time.Second)
 		if err != nil {
 			e.ResponseWithMsg(c, e.TokenIsInvalid, e.TokenIsInvalid.GetMsg())
+			c.Abort()
 		} else {
 			var response UserResponse
 			sonic.Unmarshal(request.Data, &response)

+ 3 - 3
app/router.go

@@ -3,17 +3,17 @@ package app
 import (
 	middlewares "Panel_development/app/middleware"
 	"Panel_development/app/routers"
-	"Panel_development/global"
+	"Panel_development/configs"
 	"github.com/gin-gonic/gin"
 )
 
 func InitRouter() error {
 	engine := gin.New()
 	engine.Use(middlewares.LoginMiddleware())
-	gin.SetMode(global.ServerSetting.Mode)
+	gin.SetMode(configs.Config.GetString("server.mode"))
 	routers.AdminRouter(engine)
 	routers.ComponentClassRouter(engine)
 	routers.ComponentListRouter(engine)
 	routers.PageManageRouter(engine)
-	return engine.Run(global.ServerSetting.Port)
+	return engine.Run(configs.Config.GetString("server.port"))
 }

+ 1 - 1
configs/config.yaml → config.yaml

@@ -39,7 +39,7 @@ redis:
   password: ""
   db: 0
 nats:
-  NatsServer_Url: "nats://127.0.0.0:4222"
+  url: "nats://127.0.0.0:4222"
 swag:
   # 将环境变量 NAME_OF_ENV_VARIABLE设置为任意值,则 /swagger/*any 返回404响应
   enable: "NAME_OF_ENV_VARIABLE"

+ 25 - 0
configs/config.go

@@ -0,0 +1,25 @@
+package configs
+
+import (
+	"github.com/spf13/viper"
+	"os"
+)
+
+var Config *viper.Viper
+
+func init() {
+	Config = viper.New()
+	dir, _ := os.Getwd()
+
+	_, err := os.Stat(dir + "/config.yaml")
+	if err != nil {
+		panic(any("配置文件不存在,请检查配置文件!"))
+	}
+
+	Config.SetConfigName("config")
+	Config.SetConfigType("yaml")
+	Config.AddConfigPath(dir)
+	if err := Config.ReadInConfig(); err != nil {
+		panic(any(err.Error()))
+	}
+}

+ 0 - 46
configs/setting.go

@@ -1,46 +0,0 @@
-package global
-
-import "github.com/spf13/viper"
-
-type Settings struct {
-	vp *viper.Viper
-}
-
-var sections = make(map[string]interface{})
-
-// NewSetting 读取配置
-func NewSetting() (*Settings, error) {
-	vp := viper.New()
-	vp.SetConfigName("config")
-	vp.AddConfigPath("configs")
-	vp.SetConfigType("yaml")
-	err := vp.ReadInConfig()
-	if err != nil {
-		return nil, err
-	}
-	s := &Settings{vp}
-	return s, nil
-}
-
-// ReadSection 读取指定的一段
-func (s *Settings) ReadSection(k string, v interface{}) error {
-	err := s.vp.UnmarshalKey(k, v)
-	if err != nil {
-		return err
-	}
-	if _, ok := sections[k]; !ok {
-		sections[k] = v
-	}
-	return nil
-}
-
-// ReloadAllSection 重新加载
-func (s *Settings) ReloadAllSection() error {
-	for k, v := range sections {
-		err := s.ReadSection(k, v)
-		if err != nil {
-			return err
-		}
-	}
-	return nil
-}

+ 6 - 5
global/db.go

@@ -1,6 +1,7 @@
 package global
 
 import (
+	"Panel_development/configs"
 	"fmt"
 	"gorm.io/driver/mysql"
 	"gorm.io/gorm"
@@ -14,11 +15,11 @@ var (
 func SetupDBLink() error {
 	var err error
 	dsn := fmt.Sprintf("%s:%s@tcp(%s)/%s?%s",
-		DatabaseSetting.UserName,
-		DatabaseSetting.Password,
-		DatabaseSetting.Host,
-		DatabaseSetting.Db,
-		DatabaseSetting.OtherParams,
+		configs.Config.GetString("database.userName"),
+		configs.Config.GetString("database.password"),
+		configs.Config.GetString("database.host"),
+		configs.Config.GetString("database.db"),
+		configs.Config.GetString("database.otherParams"),
 	)
 	DBLink, err = gorm.Open(mysql.Open(dsn), &gorm.Config{
 		DisableForeignKeyConstraintWhenMigrating: true,

+ 2 - 1
global/redis.go

@@ -1,6 +1,7 @@
 package global
 
 import (
+	"Panel_development/configs"
 	"Panel_development/simple_zap"
 	"context"
 	"fmt"
@@ -11,7 +12,7 @@ var Rdb *redis.Client
 
 func SetupRedisLink() {
 	Rdb = redis.NewClient(&redis.Options{
-		Addr:     RedisSetting.Addr,
+		Addr:     configs.Config.GetString("redis.addr"),
 		Password: "",
 		DB:       0,
 	})

+ 0 - 76
global/setting.go

@@ -1,76 +0,0 @@
-package global
-
-import (
-	global "Panel_development/configs"
-)
-
-// DatabaseSettingS 数据库配置
-type DatabaseSettingS struct {
-	Dialect         string `json:"dialect"`
-	Host            string `json:"host"`
-	Port            string `json:"port"`
-	UserName        string `json:"userName"`
-	Password        string `json:"password"`
-	Db              string `json:"db"`
-	OtherParams     string `json:"otherParams"`
-	MaxIdleConn     int    `json:"max_idle_conn"`
-	MaxOpenConn     int    `json:"max_open_conn"`
-	ConnMaxLifetime string `json:"conn_max_lifetime"`
-}
-
-// Nats 配置
-type Nats struct {
-	NatsServerUrl string `json:"NatsServer_Url"`
-}
-
-// Jwt 配置
-type Jwt struct {
-	Secret        string `json:"secret"`
-	RefreshExpire int    `json:"refresh_expire"`
-	Issuer        string `json:"issuer"`
-}
-
-// ServerSettingS 服务器配置
-type ServerSettingS struct {
-	Mode                string `json:"mode"`
-	Port                string `json:"port"`
-	InsecureServingInfo string `json:"insecure_serving_info"`
-}
-type SubMail struct {
-	Appid     string `json:"appid"`
-	Signature string `json:"signature"`
-}
-type Redis struct {
-	Addr     string `json:"addr"`
-	Password string `json:"password"`
-	DB       int    `json:"db"`
-}
-type Swagger struct {
-	Enable string `json:"enable"`
-}
-
-var (
-	DatabaseSetting *DatabaseSettingS
-	NatsSetting     *Nats
-	JwtSetting      *Jwt
-	ServerSetting   *ServerSettingS
-	SubMailSetting  *SubMail
-	RedisSetting    *Redis
-	SwaggerSetting  *Swagger
-)
-
-// SetupSetting 读取配置到全局变量
-func SetupSetting() error {
-	s, err := global.NewSetting()
-	err = s.ReadSection("Database", &DatabaseSetting)
-	err = s.ReadSection("Nats", &NatsSetting)
-	err = s.ReadSection("Jwt", &JwtSetting)
-	err = s.ReadSection("Server", &ServerSetting)
-	err = s.ReadSection("SubMail", &SubMailSetting)
-	err = s.ReadSection("Redis", &RedisSetting)
-	err = s.ReadSection("Swagger", &SwaggerSetting)
-	if err != nil {
-		return err
-	}
-	return nil
-}

BIN
go_build_Panel_development_linux__linux


+ 43 - 0
log/app.log

@@ -0,0 +1,43 @@
+{"level":"info","time":"2024-06-09T14:17:51.963+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-09T14:34:09.038+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-09T15:36:36.153+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"warn","time":"2024-06-11T09:11:17.175+0800","lineNum":"nats/Nats.go:18","func":"Panel_development/nats.SetupNats","message":"dial tcp 127.0.0.1:4222: connectex: No connection could be made because the target machine actively refused it.nats 连接失败"}
+{"level":"info","time":"2024-06-11T09:11:44.385+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T09:20:01.956+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T09:21:58.818+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T09:29:12.313+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T09:33:01.929+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T09:33:56.526+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T09:39:26.171+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T09:42:59.228+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T09:44:48.918+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T09:47:22.807+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T09:48:27.639+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T09:55:00.755+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T10:21:36.314+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T10:24:13.959+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T10:25:41.250+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T10:32:22.716+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T10:33:20.578+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T10:42:27.485+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T10:45:05.676+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T11:10:09.143+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T11:18:41.285+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T11:29:31.595+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T11:37:24.438+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T11:40:24.832+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T11:43:03.220+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T11:43:53.481+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T11:50:53.691+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T13:48:56.881+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T14:05:40.921+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T14:07:34.413+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T14:21:25.133+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T14:25:28.319+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T14:27:39.357+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T14:28:55.608+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"info","time":"2024-06-11T14:49:10.913+0800","lineNum":"nats/Nats.go:21","func":"Panel_development/nats.SetupNats","message":"<nil>nats 连接成功"}
+{"level":"warn","time":"2024-08-22T10:24:28.470+0800","lineNum":"nats/Nats.go:16","func":"Panel_development/nats.SetupNats","message":"dial tcp 127.0.0.1:4222: connectex: No connection could be made because the target machine actively refused it.nats 连接失败"}
+{"level":"warn","time":"2024-08-22T22:25:00.984+0800","lineNum":"nats/Nats.go:16","func":"Panel_development/nats.SetupNats","message":"dial tcp 127.0.0.0:4222: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.nats 连接失败"}
+{"level":"warn","time":"2024-08-22T22:27:14.793+0800","lineNum":"nats/Nats.go:18","func":"Panel_development/nats.SetupNats","message":"dial tcp 127.0.0.0:4222: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.nats 连接失败"}
+{"level":"warn","time":"2024-08-22T22:28:46.811+0800","lineNum":"nats/Nats.go:18","func":"Panel_development/nats.SetupNats","message":"dial tcp 127.0.0.0:4222: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.nats 连接失败"}

+ 5 - 5
main.go

@@ -11,11 +11,11 @@ import (
 )
 
 func init() {
-	err := global.SetupSetting()
-	if err != nil {
-		simple_zap.WithCtx(context.Background()).Sugar().Warn(err, "配置文件读取失败")
-	}
-	err = global.SetupDBLink()
+	//err := global.SetupSetting()
+	//if err != nil {
+	//	simple_zap.WithCtx(context.Background()).Sugar().Warn(err, "配置文件读取失败")
+	//}
+	err := global.SetupDBLink()
 	if err != nil {
 		simple_zap.WithCtx(context.Background()).Sugar().Warn(err, "数据库连接失败")
 	}

+ 4 - 2
nats/Nats.go

@@ -1,9 +1,10 @@
 package nats
 
 import (
-	"Panel_development/global"
+	"Panel_development/configs"
 	"Panel_development/simple_zap"
 	"context"
+	"fmt"
 	"github.com/nats-io/nats.go"
 )
 
@@ -11,7 +12,8 @@ var Nats *nats.Conn
 
 func SetupNats() {
 	var err error
-	Nats, err = nats.Connect(global.NatsSetting.NatsServerUrl)
+	fmt.Println(configs.Config.GetString("nats.url"))
+	Nats, err = nats.Connect(configs.Config.GetString("nats.NatsServer_Url"))
 	if err != nil {
 		simple_zap.WithCtx(context.Background()).Sugar().Warn(err, "nats 连接失败")
 		panic(err)