Skip to content

Detached #86

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

Open
wants to merge 60 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
fc6dd8e
refactor🎨: 注释暂不使用的定义
wenjianzhang Nov 25, 2022
cac45d4
refactor🎨: 升级casbin依赖版本
wenjianzhang Nov 27, 2022
c3a2a63
refactor🎨: 修改casbin数据表sys_casbin_rule至casbin_rule 和casbin保持一致
wenjianzhang Nov 27, 2022
6ebc088
refactor🎨: 添加casbin排除数据表
wenjianzhang Nov 27, 2022
548da5f
refactor🎨: 添加casbin排除数据表
wenjianzhang Nov 27, 2022
cba89b7
refactor🎨: 添加casbin排除数据表
wenjianzhang Nov 27, 2022
e3c14cb
refactor🎨: 添加casbin排除数据表
wenjianzhang Nov 27, 2022
2725784
refactor🎨: 添加casbin排除数据表
wenjianzhang Nov 27, 2022
251a1b8
refactor🎨: 删除Application中的JwtSecret无效属性,此属性已经变更到Jwt下Secret
wenjianzhang Dec 1, 2022
91c6894
refactor🎨: 指出不等于语法
wenjianzhang Dec 1, 2022
4124c7c
refactor🎨: 提交程序启动前钩子
wenjianzhang Dec 21, 2022
ed8a8a8
refactor🎨: config租户支持
wenjianzhang Mar 7, 2023
419e92b
refactor🎨: config租户支持
wenjianzhang Mar 7, 2023
9c9d0cc
perf👌: update log default
wenjianzhang May 14, 2023
eae7ff9
perf👌: update package
wenjianzhang May 14, 2023
82cfbad
perf👌: update package
wenjianzhang May 14, 2023
139ec39
perf👌: update package
wenjianzhang May 14, 2023
7b96fbf
perf👌: update logger
wenjianzhang May 14, 2023
3dc3681
perf👌: Add app to runtime
wenjianzhang Aug 1, 2023
53d8d21
perf👌: Upgrade gin
wenjianzhang Aug 1, 2023
28a1958
refactor🎨: 更新gomod
wenjianzhang Nov 2, 2023
2ba178d
refactor🎨: 添加日志文件保留时间控制
wenjianzhang Nov 3, 2023
1a2a521
refactor🎨: 添加日志文件保留时间控制
wenjianzhang Nov 3, 2023
f05b293
refactor🎨: redis依赖升级
wenjianzhang Nov 3, 2023
e06921a
refactor🎨: redis依赖升级
wenjianzhang Nov 3, 2023
7771f9b
refactor🎨: redis依赖升级
wenjianzhang Nov 3, 2023
2a50dca
refactor🎨: redis依赖升级
wenjianzhang Nov 3, 2023
dde72b0
refactor🎨: redis依赖升级
wenjianzhang Nov 3, 2023
dc27e05
refactor🎨: update log
wenjianzhang Nov 3, 2023
87e7fd7
refactor🎨: 依赖升级
wenjianzhang Nov 3, 2023
c3acc48
refactor🎨: 依赖升级
wenjianzhang Nov 3, 2023
b6b9f8f
refactor🎨: 依赖升级
wenjianzhang Nov 3, 2023
2449cb6
refactor🎨: 依赖升级
wenjianzhang Nov 3, 2023
15be27e
refactor🎨: 依赖升级
wenjianzhang Nov 3, 2023
244738d
refactor🎨: 添加log保留天数设置
wenjianzhang Nov 3, 2023
6b9b9aa
refactor🎨: 依赖升级
wenjianzhang Nov 3, 2023
7fbaf8e
refactor🎨: 依赖升级1.21
wenjianzhang Nov 3, 2023
12c7096
refactor🎨: redis升级
wenjianzhang Nov 3, 2023
5ffef87
refactor🎨: 安全依赖升级
wenjianzhang Nov 3, 2023
ed33214
refactor🎨: 格式化TODO
wenjianzhang Nov 3, 2023
856c36d
refactor🎨: 调整core版本
wenjianzhang Nov 3, 2023
7e56a5d
refactor🎨: 调整zap版本
wenjianzhang Nov 3, 2023
51f695c
fix🐛: 注释未使用定义
wenjianzhang Nov 3, 2023
b8dcc94
refactor🎨: 调整core版本
wenjianzhang Nov 3, 2023
a186c68
Merge remote-tracking branch 'origin/up' into up
wenjianzhang Nov 3, 2023
110915f
refactor🎨: 调整log版本
wenjianzhang Nov 3, 2023
8c06ea1
refactor🎨: 调整验证码模块
wenjianzhang Nov 3, 2023
0314b1f
refactor🎨: 调整默认文件大小以MB为单位
wenjianzhang Nov 3, 2023
03736a0
refactor🎨: 调整默认文件大小以MB为单位
wenjianzhang Nov 3, 2023
82b086d
refactor🎨: 调整默认文件大小以MB为单位
wenjianzhang Nov 3, 2023
2d9e40e
refactor🎨: 升级日志组件gomod
wenjianzhang Nov 3, 2023
84418ed
refactor🎨: 升级sdk gomod
wenjianzhang Nov 3, 2023
1f91355
log update
wenjianzhang Dec 18, 2023
0be61a4
Merge branch 'dev' into up
wenjianzhang Dec 18, 2023
a2e7e75
refactor🎨: 更新gorm日志样式
wenjianzhang Dec 27, 2023
797ba96
refactor🎨: 更新NewSheet 返回值忽略
wenjianzhang Dec 27, 2023
435d380
refactor🎨: 更新依赖库版本github.com/mojocn/base64Captcha 1.3.5》1.3.6
wenjianzhang Dec 27, 2023
099aab3
refactor🎨: 更新uuid 和redis 依赖库
wenjianzhang Jan 3, 2024
c1dec45
refactor🎨: 追加新的验证码返回参数
wenjianzhang Jan 3, 2024
eef1341
登陆流程增加2fa支持
AmosCrypto Jan 24, 2025
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 config/reader/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"errors"
"time"

"dario.cat/mergo"
"github.com/go-admin-team/go-admin-core/config/encoder"
"github.com/go-admin-team/go-admin-core/config/encoder/json"
"github.com/go-admin-team/go-admin-core/config/reader"
"github.com/go-admin-team/go-admin-core/config/source"
"github.com/imdario/mergo"
)

const readerTyp = "json"
Expand Down
19 changes: 10 additions & 9 deletions config/source/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"strings"
"time"

"dario.cat/mergo"
"github.com/go-admin-team/go-admin-core/config/source"
"github.com/imdario/mergo"
)

var (
Expand Down Expand Up @@ -117,15 +117,16 @@ func (e *env) String() string {
// Underscores are delimiters for nesting, and all keys are lowercased.
//
// Example:
// "DATABASE_SERVER_HOST=localhost" will convert to
//
// {
// "database": {
// "server": {
// "host": "localhost"
// }
// }
// }
// "DATABASE_SERVER_HOST=localhost" will convert to
//
// {
// "database": {
// "server": {
// "host": "localhost"
// }
// }
// }
func NewSource(opts ...source.Option) source.Source {
options := source.NewOptions(opts...)

Expand Down
15 changes: 8 additions & 7 deletions config/source/flag/flag.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package flag

import (
"dario.cat/mergo"
"errors"
"flag"
"github.com/go-admin-team/go-admin-core/config/source"
"github.com/imdario/mergo"
"strings"
"time"
)
Expand Down Expand Up @@ -89,13 +89,14 @@ func (fs *flagsrc) String() string {
// Hyphens are delimiters for nesting, and all keys are lowercased.
//
// Example:
// dbhost := flag.String("database-host", "localhost", "the db host name")
//
// {
// "database": {
// "host": "localhost"
// }
// }
// dbhost := flag.String("database-host", "localhost", "the db host name")
//
// {
// "database": {
// "host": "localhost"
// }
// }
func NewSource(opts ...source.Option) source.Source {
return &flagsrc{opts: source.NewOptions(opts...)}
}
34 changes: 32 additions & 2 deletions debug/writer/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
// 用于文件名称格式
const timeFormat = "2006-01-02"

const MB = 1024 * 1024

// FileWriter 文件写入结构体
type FileWriter struct {
file *os.File
Expand Down Expand Up @@ -78,16 +80,44 @@ func (p *FileWriter) write() {
func (p *FileWriter) checkFile() {
info, _ := p.file.Stat()
if strings.Index(p.file.Name(), time.Now().Format(timeFormat)) < 0 ||
(p.opts.cap > 0 && uint(info.Size()) > p.opts.cap) {
(p.opts.cap > 0 && uint(info.Size()) > p.opts.cap*MB) {
//生成新文件
if uint(info.Size()) > p.opts.cap {
if uint(info.Size()) > p.opts.cap*MB {
p.num++
} else {
p.num = 0
}
filename := p.getFilename()
_ = p.file.Close()
p.file, _ = os.OpenFile(filename, os.O_WRONLY|os.O_APPEND|os.O_CREATE|os.O_SYNC, 0600)

dir := filepath.Dir(p.file.Name())
files, err := os.ReadDir(dir)
if err != nil {
fmt.Println("Error reading log directory:", err)
return
}

for _, file := range files {
if !file.IsDir() && strings.HasSuffix(file.Name(), p.opts.suffix) {
filePath := filepath.Join(dir, file.Name())
fileInfo, err := file.Info()
if err != nil {
fmt.Println("Error get Info file:", err)
break
}
fileModTime := fileInfo.ModTime()
daysSinceMod := uint(time.Since(fileModTime).Hours() / 24)
if daysSinceMod > p.opts.daysToKeep {
err := os.Remove(filePath)
if err != nil {
fmt.Println("Error deleting file:", err)
} else {
fmt.Println("Deleted file:", filePath)
}
}
}
}
}
}

Expand Down
23 changes: 16 additions & 7 deletions debug/writer/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,31 @@ package writer

// Options 可配置参数
type Options struct {
path string
suffix string //文件扩展名
cap uint
path string //文件路径
suffix string //文件扩展名
daysToKeep uint //保存天数
cap uint //文件大小
}

func setDefault() Options {
return Options{
path: "/tmp/go-admin",
suffix: "log",
path: "/tmp/go-admin",
suffix: "log",
daysToKeep: 7,
}
}

// Option set options
type Option func(*Options)

// WithPath set path
// WithPath 设置文件路径
func WithPath(s string) Option {
return func(o *Options) {
o.path = s
}
}

// WithSuffix set suffix
// WithSuffix 设置文件扩展名
func WithSuffix(s string) Option {
return func(o *Options) {
o.suffix = s
Expand All @@ -44,3 +46,10 @@ func WithCap(n uint) Option {
o.cap = n
}
}

// WithDaysToKeep 设置文件保留天数
func WithDaysToKeep(n uint) Option {
return func(o *Options) {
o.daysToKeep = n
}
}
104 changes: 57 additions & 47 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,84 +1,94 @@
module github.com/go-admin-team/go-admin-core

go 1.18
go 1.21

require (
github.com/BurntSushi/toml v0.3.1
github.com/bitly/go-simplejson v0.5.0
github.com/bsm/redislock v0.8.2
github.com/fsnotify/fsnotify v1.4.9
dario.cat/mergo v1.0.0
github.com/BurntSushi/toml v1.3.2
github.com/bitly/go-simplejson v0.5.1
github.com/bsm/redislock v0.9.4
github.com/fsnotify/fsnotify v1.7.0
github.com/ghodss/yaml v1.0.0
github.com/gin-gonic/gin v1.7.7
github.com/gin-gonic/gin v1.9.1
github.com/go-admin-team/redisqueue/v2 v2.0.0
github.com/go-redis/redis/v9 v9.0.0-rc.1
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
github.com/google/uuid v1.3.0
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
github.com/google/uuid v1.5.0
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/imdario/mergo v0.3.9
github.com/json-iterator/go v1.1.11
github.com/nsqio/go-nsq v1.0.8
github.com/json-iterator/go v1.1.12
github.com/nsqio/go-nsq v1.1.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.11.0
github.com/prometheus/client_golang v1.17.0
github.com/redis/go-redis/v9 v9.3.1
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
github.com/smartystreets/goconvey v1.6.4
github.com/spf13/cast v1.3.1
github.com/xuri/excelize/v2 v2.6.1
golang.org/x/crypto v0.0.0-20220817201139-bc19a97f63c8
google.golang.org/grpc v1.29.1
google.golang.org/protobuf v1.28.0
gorm.io/driver/mysql v1.4.4
gorm.io/gorm v1.24.2
gorm.io/plugin/dbresolver v1.3.0
github.com/smartystreets/goconvey v1.8.1
github.com/spf13/cast v1.5.1
github.com/xuri/excelize/v2 v2.8.0
golang.org/x/crypto v0.14.0
google.golang.org/grpc v1.59.0
google.golang.org/protobuf v1.31.0
gorm.io/driver/mysql v1.5.2
gorm.io/gorm v1.25.5
gorm.io/plugin/dbresolver v1.4.7
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/bytedance/sonic v1.10.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/fatih/color v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/git-chglog/git-chglog v0.0.0-20190611050339-63a4e637021f // indirect
github.com/go-playground/locales v0.13.0 // indirect
github.com/go-playground/universal-translator v0.17.0 // indirect
github.com/go-playground/validator/v10 v10.4.1 // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
github.com/go-sql-driver/mysql v1.7.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 // indirect
github.com/gopherjs/gopherjs v1.17.2 // indirect
github.com/imdario/mergo v0.3.7 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/jtolds/gls v4.20.0+incompatible // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/leodido/go-urn v1.2.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mattn/go-colorable v0.1.7 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/goveralls v0.0.2 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/opentracing/opentracing-go v1.1.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.26.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.1 // indirect
github.com/richardlehane/mscfb v1.0.4 // indirect
github.com/richardlehane/msoleps v1.0.3 // indirect
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d // indirect
github.com/smarty/assertions v1.15.0 // indirect
github.com/tsuyoshiwada/go-gitcmd v0.0.0-20180205145712-5f1f5f9475df // indirect
github.com/ugorji/go/codec v1.1.7 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/urfave/cli v1.20.0 // indirect
github.com/xuri/efp v0.0.0-20220603152613-6918739fd470 // indirect
github.com/xuri/nfp v0.0.0-20220409054826-5e722a1d9e22 // indirect
golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9 // indirect
golang.org/x/net v0.0.0-20220812174116-3211cb980234 // indirect
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.12 // indirect
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect
github.com/xuri/efp v0.0.0-20230802181842-ad255f2331ca // indirect
github.com/xuri/nfp v0.0.0-20230819163627-dc951e3ffe1a // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/image v0.11.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/tools v0.7.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
gopkg.in/AlecAivazis/survey.v1 v1.8.5 // indirect
gopkg.in/kyokomi/emoji.v1 v1.5.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
16 changes: 8 additions & 8 deletions logger/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (l *defaultLogger) logf(level Level, format string, v ...interface{}) {
fields := copyFields(l.opts.Fields)
l.RUnlock()

fields["level"] = level.String()
//fields["level"] = level.String()

if _, file, line, ok := runtime.Caller(l.opts.CallerSkipCount); ok && level.String() == "error" {
fields["file"] = fmt.Sprintf("%s:%d", logCallerfilePath(file), line)
Expand Down Expand Up @@ -134,16 +134,16 @@ func (l *defaultLogger) logf(level Level, format string, v ...interface{}) {
if l.opts.Name != "" {
name = "[" + l.opts.Name + "]"
}
t := rec.Timestamp.Format("2006-01-02 15:04:05.000Z0700")
//fmt.Printf("%s\n", t)
//fmt.Printf("%s\n", name)
//fmt.Printf("%s\n", metadata)
//fmt.Printf("%v\n", rec.Message)
timeFormat := "2006-01-02 15:04:05"
if l.opts.TimeFormat != "" {
timeFormat = l.opts.TimeFormat
}
t := rec.Timestamp.Format(timeFormat)
logStr := ""
if name == "" {
logStr = fmt.Sprintf("%s %s %v\n", t, metadata, rec.Message)
logStr = fmt.Sprintf("%s %s %s %v\n", t, level.String(), metadata, rec.Message)
} else {
logStr = fmt.Sprintf("%s %s %s %v\n", name, t, metadata, rec.Message)
logStr = fmt.Sprintf("%s %s %s %s %v\n", name, t, level.String(), metadata, rec.Message)
}
_, err := l.opts.Out.Write([]byte(logStr))
if err != nil {
Expand Down
15 changes: 15 additions & 0 deletions logger/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type Options struct {
Context context.Context
// Name logger name
Name string
// Timestamp.Format
TimeFormat string
}

// WithFields set default fields for the logger
Expand All @@ -29,6 +31,12 @@ func WithFields(fields map[string]interface{}) Option {
}
}

func RemoveFieldByKey(key string) Option {
return func(args *Options) {
delete(args.Fields, key)
}
}

// WithLevel set default level for the logger
func WithLevel(level Level) Option {
return func(args *Options) {
Expand Down Expand Up @@ -57,6 +65,13 @@ func WithName(name string) Option {
}
}

// WithTimeFormat set time format for logger eg. 2006-01-02 15:04:05.000Z0700
func WithTimeFormat(TimeFormat string) Option {
return func(args *Options) {
args.TimeFormat = TimeFormat
}
}

func SetOption(k, v interface{}) Option {
return func(o *Options) {
if o.Context == nil {
Expand Down
Loading