Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 409cb53e8c | |||
| 404957f16a | |||
| 3d6871138a | |||
| f7d8988415 | |||
| 820d7a5c63 | |||
| 3038c6c22c |
10
conf/new.go
10
conf/new.go
@@ -111,11 +111,11 @@ func InitLoggerConf(cfg *LogConf) *LogConf {
|
|||||||
return &LogConf{
|
return &LogConf{
|
||||||
Name: strings.ToLower(vars.ServiceKey),
|
Name: strings.ToLower(vars.ServiceKey),
|
||||||
Level: vars.LogLevel(vars.DEBUG),
|
Level: vars.LogLevel(vars.DEBUG),
|
||||||
Dir: cfg.Dir,
|
Dir: "./logs/",
|
||||||
Endpoint: cfg.Endpoint,
|
Endpoint: "",
|
||||||
Console: cfg.Console,
|
Console: true,
|
||||||
File: cfg.File,
|
File: true,
|
||||||
Remote: cfg.Remote,
|
Remote: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cfg
|
return cfg
|
||||||
|
|||||||
@@ -133,3 +133,13 @@ func NewPostgres(dsn []string, options *types.SqlOptions) (gormDb *gorm.DB, err
|
|||||||
|
|
||||||
return gormDb, nil
|
return gormDb, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AppendMigrate 调用此函数后,会在数据库初始化时自动迁移表结构
|
||||||
|
//
|
||||||
|
// - table: 需要自动迁移的表
|
||||||
|
func AppendMigrate(table any) {
|
||||||
|
if MigrateTables == nil {
|
||||||
|
MigrateTables = make([]any, 0)
|
||||||
|
}
|
||||||
|
MigrateTables = append(MigrateTables, table)
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
|
|
||||||
// HTTP请求头相关错误码,起始码:1000
|
// HTTP请求头相关错误码,起始码:1000
|
||||||
var (
|
var (
|
||||||
|
AllErrors = make(map[int]string)
|
||||||
ErrHeaderRequestId = NewError(1001, "Header Request-Id Not Found") // 请求ID头缺失
|
ErrHeaderRequestId = NewError(1001, "Header Request-Id Not Found") // 请求ID头缺失
|
||||||
ErrHeaderAuthorization = NewError(1002, "Header Authorization Not Found") // 授权头缺失
|
ErrHeaderAuthorization = NewError(1002, "Header Authorization Not Found") // 授权头缺失
|
||||||
ErrHeaderSecretKey = NewError(1003, "Header Secret-Key Not Found") // 密钥头缺失
|
ErrHeaderSecretKey = NewError(1003, "Header Secret-Key Not Found") // 密钥头缺失
|
||||||
@@ -81,6 +82,7 @@ var (
|
|||||||
// code: 错误码
|
// code: 错误码
|
||||||
// msg: 错误消息
|
// msg: 错误消息
|
||||||
func NewError(code int, msg string) error {
|
func NewError(code int, msg string) error {
|
||||||
|
AllErrors[code] = msg
|
||||||
return status.New(codes.Code(code), msg).Err()
|
return status.New(codes.Code(code), msg).Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,6 +90,7 @@ func NewError(code int, msg string) error {
|
|||||||
// code: 错误码
|
// code: 错误码
|
||||||
// msg: 错误消息
|
// msg: 错误消息
|
||||||
func ErrFatal(code int, msg string) error {
|
func ErrFatal(code int, msg string) error {
|
||||||
|
AllErrors[code] = msg
|
||||||
return status.New(codes.Code(code), msg).Err()
|
return status.New(codes.Code(code), msg).Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,5 +98,6 @@ func ErrFatal(code int, msg string) error {
|
|||||||
// code: 错误码
|
// code: 错误码
|
||||||
// msg: 错误消息,会自动转换为大写
|
// msg: 错误消息,会自动转换为大写
|
||||||
func ErrNotFound(code int, msg string) error {
|
func ErrNotFound(code int, msg string) error {
|
||||||
|
AllErrors[code] = strings.ToUpper(msg)
|
||||||
return status.New(codes.Code(code), strings.ToUpper(msg)).Err()
|
return status.New(codes.Code(code), strings.ToUpper(msg)).Err()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user