Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复命名空间冲突 #3

Merged
merged 5 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aes/aes.go → aesHelper/aes.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package aes
package aesHelper

import (
"bytes"
Expand Down
119 changes: 0 additions & 119 deletions fetch.go

This file was deleted.

2 changes: 1 addition & 1 deletion minio/minio.go → minioHelper/minio.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package minio
package minioHelper

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion minio/service.go → minioHelper/service.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package minio
package minioHelper

import (
"context"
Expand Down
8 changes: 4 additions & 4 deletions redis/redis.go → redisHelper/redis.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package redis
package redisHelper

import (
Redis "github.com/go-redis/redis/v8"
"github.com/go-redis/redis/v8"
)

// InfoConfig Redis 配置
Expand All @@ -13,8 +13,8 @@ type InfoConfig struct {
}

// Init 初始化 Redis 客户端
func Init(info *InfoConfig) *Redis.Client {
client := Redis.NewClient(&Redis.Options{
func Init(info *InfoConfig) *redis.Client {
client := redis.NewClient(&redis.Options{
Addr: info.Host + ":" + info.Port,
Password: info.Password,
DB: info.DB,
Expand Down
6 changes: 3 additions & 3 deletions session/session.go → sessionHelper/session.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package session
package sessionHelper

import (
"fmt"
Expand All @@ -7,14 +7,14 @@ import (
"github.com/gin-contrib/sessions"
sessionRedis "github.com/gin-contrib/sessions/redis"
"github.com/gin-gonic/gin"
"github.com/zjutjh/WeJH-SDK/redis"
"github.com/zjutjh/WeJH-SDK/redisHelper"
)

// InfoConfig 会话配置
type InfoConfig struct {
Name string
SecretKey string
RedisConfig *redis.InfoConfig
RedisConfig *redisHelper.InfoConfig
}

// Init 使用 Redis 初始化会话管理
Expand Down
6 changes: 3 additions & 3 deletions wechat/wechat.go → wechatHelper/wechat.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wechat
package wechatHelper

import (
"context"
Expand All @@ -7,14 +7,14 @@ import (
"github.com/silenceper/wechat/v2/cache"
"github.com/silenceper/wechat/v2/miniprogram"
miniConfig "github.com/silenceper/wechat/v2/miniprogram/config"
"github.com/zjutjh/WeJH-SDK/redis"
"github.com/zjutjh/WeJH-SDK/redisHelper"
)

// InfoConfig 微信小程序配置
type InfoConfig struct {
AppId string
AppSecret string
RedisConfig *redis.InfoConfig
RedisConfig *redisHelper.InfoConfig
}

// Init 使用 Redis 初始化微信小程序
Expand Down
27 changes: 19 additions & 8 deletions zap/zap.go → zapHelper/zap.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,28 @@ const (
WriterAll = "all"
)

// GetDefaultConfig 返回默认的日志配置
func GetDefaultConfig() *InfoConfig {
return &InfoConfig{
ConsoleLevel: "info",
DisableStacktrace: false,
LogCompress: false,
LogMaxAge: 7,
LogMaxSize: 10,
LoggerDir: "./logs",
Name: "default",
StacktraceLevel: "error",
Writer: WriterAll,
}
}

// Init 初始化 Zap 日志记录器
// 初始化后使用 zap.L() 或 zap.S() 使用全局日志记录器
func Init(cfg *InfoConfig) error {
func Init(cfg *InfoConfig) (*zap.Logger, error) {
cfg.LoggerDir = strings.TrimRight(cfg.LoggerDir, "/ ") // 去除尾部斜杠和空格

// 创建日志目录
if err := os.MkdirAll(cfg.LoggerDir, 0750); err != nil {
return err
return nil, err
}
encoder := createEncoder()

Expand All @@ -69,11 +83,8 @@ func Init(cfg *InfoConfig) error {
})))
}

logger := zap.New(combinedCore, options...) // 创建新的 zap 日志记录器
zap.ReplaceGlobals(logger) // 替换全局日志记录器

zap.L().Info("Logger initialized")
return nil
logger := zap.New(combinedCore, options...) // 创建新的日志记录器
return logger, nil
}

// GetZapLevel 返回日志级别
Expand Down
Loading