update
This commit is contained in:
@@ -42,14 +42,17 @@ type Config struct {
|
||||
Prod bool `mapstructure:"prod"` // 是否正式
|
||||
} `mapstructure:"app"`
|
||||
DB struct {
|
||||
Driver string `mapstructure:"driver"` // 数据库类型
|
||||
Host string `mapstructure:"host"` // 数据库地址
|
||||
Port int `mapstructure:"port"` // 数据库端口
|
||||
Username string `mapstructure:"username"` // 数据库用户
|
||||
Password string `mapstructure:"password"` // 数据库密码
|
||||
DBName string `mapstructure:"db_name"` // 数据库名称
|
||||
MaxOpenConns int `mapstructure:"max_open_conns"` // 数据库名称
|
||||
MaxIdleConns int `mapstructure:"max_idle_conns"` // 数据库名称
|
||||
Driver string `mapstructure:"driver"` // 数据库类型
|
||||
Host string `mapstructure:"host"` // 数据库地址
|
||||
Port int `mapstructure:"port"` // 数据库端口
|
||||
Username string `mapstructure:"username"` // 数据库用户
|
||||
Password string `mapstructure:"password"` // 数据库密码
|
||||
DBName string `mapstructure:"db_name"` // 数据库名称
|
||||
MaxIdleConns int `mapstructure:"max_idle_conns"` // 最大空闲连接数
|
||||
MaxOpenConns int `mapstructure:"max_open_conns"` // 最大打开连接数
|
||||
ConnMaxLifetime time.Duration `mapstructure:"conn_max_lifetime"` // 连接最大存活时间
|
||||
ConnMaxIdleTime time.Duration `mapstructure:"conn_max_idle_time"` // 连接最大空闲时间
|
||||
LogMode bool `mapstructure:"log_mode"` // 是否开启日志
|
||||
} `mapstructure:"db"`
|
||||
Redis struct {
|
||||
Host string `mapstructure:"host"` // redis地址
|
||||
|
||||
@@ -25,10 +25,10 @@ type PostgreSQLOptions struct {
|
||||
|
||||
// DSN return DSN from PostgreSQLOptions.
|
||||
func (o *PostgreSQLOptions) DSN() string {
|
||||
splited := strings.Split(o.Addr, ":")
|
||||
host, port := splited[0], "5432"
|
||||
if len(splited) > 1 {
|
||||
port = splited[1]
|
||||
split := strings.Split(o.Addr, ":")
|
||||
host, port := split[0], "5432"
|
||||
if len(split) > 1 {
|
||||
port = split[1]
|
||||
}
|
||||
|
||||
return fmt.Sprintf(`user=%s password=%s host=%s port=%s dbname=%s sslmode=disable TimeZone=Asia/Shanghai`,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"time"
|
||||
@@ -18,19 +19,24 @@ func Audit(sess session.Manager, auditLogService v1.AuditLogService, log *logger
|
||||
return func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
start := time.Now()
|
||||
|
||||
// 提前获取用户信息(同步操作)
|
||||
user, err := sess.GetUser(r.Context(), know.StoreName)
|
||||
if err != nil {
|
||||
log.Error("获取用户会话失败", err)
|
||||
next.ServeHTTP(w, r) // 继续处理请求
|
||||
return
|
||||
}
|
||||
|
||||
defer func() {
|
||||
go func() {
|
||||
ctx := r.Context()
|
||||
user, err := sess.GetUser(ctx, know.StoreName)
|
||||
if err != nil {
|
||||
log.Error(err.Error(), err)
|
||||
if user.ID == 0 {
|
||||
log.Error("用户信息为空", errors.New("scs get user is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
if user.ID == 0 {
|
||||
log.Error("scs get user is empty", errors.New("scs get user is empty"))
|
||||
return
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
defer cancel()
|
||||
|
||||
al := systemmodel.NewAuditLog(r, user.Email, user.OS, user.Browser, start, time.Now())
|
||||
if err := auditLogService.Create(ctx, al); err != nil {
|
||||
|
||||
@@ -17,6 +17,7 @@ var publicRoutes = map[string]bool{
|
||||
"/upload/file": true,
|
||||
"/upload/multi_files": true,
|
||||
"/pear.json": true,
|
||||
"/logout": true,
|
||||
}
|
||||
|
||||
func Authorize(
|
||||
|
||||
@@ -57,5 +57,9 @@ func Methods() map[string]any {
|
||||
return string(b)
|
||||
}
|
||||
|
||||
res["add"] = func(n1, n2 int64) int64 {
|
||||
return n1 + n2
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user