新增复合案例管理,包括模型定义、服务层逻辑及相关API接口
This commit is contained in:
parent
4a14eb3ef0
commit
e246f2fc06
46
activities/openai.go
Normal file
46
activities/openai.go
Normal file
@ -0,0 +1,46 @@
|
||||
package activities
|
||||
|
||||
import (
|
||||
"beacon/pkg/openai"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type OpenAI struct {
|
||||
}
|
||||
|
||||
func (s OpenAI) Create(ctx *gin.Context) {
|
||||
file, err := ctx.FormFile("file")
|
||||
if err != nil {
|
||||
zap.L().Info(fmt.Sprintf("获取文件失败:%s", err.Error()))
|
||||
ctx.JSON(http.StatusBadRequest, gin.H{"message": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
//err, data := openai.GetGeminiAICaptcha(file)
|
||||
//if err != nil {
|
||||
// ctx.JSON(http.StatusOK, gin.H{
|
||||
// "message": "success",
|
||||
// "data": err.Error(),
|
||||
// })
|
||||
// return
|
||||
//}
|
||||
|
||||
err, data := openai.GetOllamaAICaptcha(file)
|
||||
if err != nil {
|
||||
zap.L().Info(fmt.Sprintf("GetOllamaAICaptcha %s", err.Error()))
|
||||
ctx.JSON(http.StatusOK, gin.H{
|
||||
"message": "success",
|
||||
"data": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, gin.H{
|
||||
"message": "success",
|
||||
"data": data,
|
||||
})
|
||||
}
|
192
config/default.go
Executable file
192
config/default.go
Executable file
@ -0,0 +1,192 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"github.com/spf13/viper"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Conf 定义全局的变量
|
||||
var Conf = new(SrvConfig)
|
||||
|
||||
// var ConfLock = new(sync.RWMutex) // 配置读写锁,高并发情况下保证获取的是最新的配置
|
||||
|
||||
// viper.GetXxx()读取的方式
|
||||
// 注意:
|
||||
// Viper使用的是 `mapstructure`
|
||||
|
||||
// SrvConfig 服务配置
|
||||
type SrvConfig struct {
|
||||
Name string `mapstructure:"name"`
|
||||
Mode string `mapstructure:"mode"`
|
||||
Version string `mapstructure:"version"`
|
||||
|
||||
IP string `mapstructure:"ip"`
|
||||
Port int `mapstructure:"port"`
|
||||
|
||||
Pid string `mapstructure:"pid"`
|
||||
|
||||
*LogConfig `mapstructure:"log"`
|
||||
*OCRConfig `mapstructure:"ocr"`
|
||||
*MinIoConfig `mapstructure:"minio"`
|
||||
*OpenCVConfig `mapstructure:"opencv"`
|
||||
*MySQLConfig `mapstructure:"mysql"`
|
||||
*SnowflakeConfig `mapstructure:"snowflake"`
|
||||
*GrpcConfig `mapstructure:"grpc"`
|
||||
*ApolloConfig `mapstructure:"apollo"`
|
||||
*Registrar `mapstructure:"registrar"`
|
||||
*RcloneConfig `mapstructure:"rclone"`
|
||||
*OpenAI `mapstructure:"openai"`
|
||||
}
|
||||
|
||||
type LogConfig struct {
|
||||
Level string `mapstructure:"level"`
|
||||
Filename string `mapstructure:"filename"`
|
||||
FilenameErr string `mapstructure:"filename_err"`
|
||||
MaxSize int `mapstructure:"max_size"`
|
||||
MaxAge int `mapstructure:"max_age"`
|
||||
MaxBackups int `mapstructure:"max_backups"`
|
||||
}
|
||||
|
||||
type ApolloConfig struct {
|
||||
AppID string `mapstructure:"app_id"`
|
||||
Cluster string `mapstructure:"cluster"` // 环境
|
||||
NameSpaceNames []string `mapstructure:"name_spaceNames"`
|
||||
MetaAddr string `mapstructure:"meta_addr"` // 配置中心地址
|
||||
AccesskeySecret string `mapstructure:"access_key_secret"`
|
||||
}
|
||||
|
||||
type OCRConfig struct {
|
||||
URL string `mapstructure:"url"`
|
||||
Det bool `mapstructure:"det"`
|
||||
Rec bool `mapstructure:"rec"`
|
||||
Mode int `mapstructure:"mode"`
|
||||
Addr string `mapstructure:"addr"`
|
||||
}
|
||||
|
||||
type MinIoConfig struct {
|
||||
Endpoint string `mapstructure:"endpoint"`
|
||||
AccessKeyId string `mapstructure:"access_key_id"`
|
||||
SecretAccessKey string `mapstructure:"secret_access_key"`
|
||||
Secure bool `mapstructure:"secure"`
|
||||
BucketName string `mapstructure:"bucket_name"`
|
||||
}
|
||||
|
||||
type OpenCVConfig struct {
|
||||
Threshold float32 `mapstructure:"threshold"`
|
||||
}
|
||||
|
||||
type MySQLConfig struct {
|
||||
Host string `mapstructure:"host"`
|
||||
User string `mapstructure:"user"`
|
||||
Password string `mapstructure:"password"`
|
||||
DB string `mapstructure:"dbname"`
|
||||
Port int `mapstructure:"port"`
|
||||
MaxOpenConns int `mapstructure:"max_open_conns"`
|
||||
MaxIdleConns int `mapstructure:"max_idle_conns"`
|
||||
}
|
||||
|
||||
type SnowflakeConfig struct {
|
||||
StartTime string `mapstructure:"start_time"`
|
||||
MachineID int64 `mapstructure:"machine_id"`
|
||||
}
|
||||
|
||||
type GrpcConfig struct {
|
||||
Port int `mapstructure:"port"`
|
||||
MaxRecvMsgSize int `mapstructure:"max_recv_msg_size"`
|
||||
MaxSendMsgSize int `mapstructure:"max_send_msg_size"`
|
||||
}
|
||||
|
||||
type Registrar struct {
|
||||
Enabled bool `mapstructure:"enabled"`
|
||||
Address []string `mapstructure:"address"`
|
||||
}
|
||||
|
||||
type RcloneConfig struct {
|
||||
RemoteName string `mapstructure:"remote_name"`
|
||||
BucketName string `mapstructure:"bucket_name"`
|
||||
RclonePath string `mapstructure:"rclone_path"` // rclone命令所在位置,在全局环境中则填入rclone
|
||||
Expire int `mapstructure:"expire"` // 公共储存通有效时间s
|
||||
RcloneConfig string `mapstructure:"rclone_config"` // Rclone配置文件所在目录
|
||||
CustomDomains string `mapstructure:"custom_domains"` // 自定义域
|
||||
}
|
||||
|
||||
type OpenAI struct {
|
||||
BaseURL string `mapstructure:"base_url"`
|
||||
ApiKey string `mapstructure:"api_key"`
|
||||
Model string `mapstructure:"model"`
|
||||
Prompt string `mapstructure:"prompt"`
|
||||
}
|
||||
|
||||
// Init 整个服务配置文件初始化的方法
|
||||
func Init(yamlContent string) (err error) {
|
||||
// 方式1:直接指定配置文件路径(相对路径或者绝对路径)
|
||||
// 相对路径:相对执行的可执行文件的相对路径
|
||||
// viper.SetConfigFile("./conf/config.yaml")
|
||||
|
||||
viper.SetConfigType("yaml")
|
||||
err = viper.ReadConfig(strings.NewReader(yamlContent))
|
||||
if err != nil {
|
||||
// 读取配置信息失败
|
||||
fmt.Printf("viper.ReadInConfig failed, err:%v\n", err)
|
||||
return
|
||||
}
|
||||
// 如果使用的是 viper.GetXxx()方式使用配置的话,就无须下面的操作
|
||||
|
||||
// 把读取到的配置信息反序列化到 Conf 变量中
|
||||
if err := viper.Unmarshal(&Conf); err != nil {
|
||||
fmt.Printf("viper.Unmarshal failed, err:%v\n", err)
|
||||
}
|
||||
|
||||
/*viper.WatchConfig() // 配置文件监听
|
||||
viper.OnConfigChange(func(in fsnotify.Event) {
|
||||
ConfLock.Lock() // 获取锁
|
||||
defer ConfLock.Unlock() // 释放锁
|
||||
fmt.Println("配置文件修改了...")
|
||||
if err := viper.Unmarshal(&Conf); err != nil {
|
||||
fmt.Printf("viper.Unmarshal failed, err:%v\n", err)
|
||||
}
|
||||
})*/
|
||||
/*err, ip := GetNetworkCard([]string{Conf.MetaAddr})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(ip)
|
||||
Conf.IP = "10.10.1.254"*/
|
||||
return
|
||||
}
|
||||
|
||||
var ConfLock = new(sync.RWMutex) // 配置读写锁,高并发情况下保证获取的是最新的配置
|
||||
|
||||
func InitFromFile(filePath string) (err error) {
|
||||
// 方式1:直接指定配置文件路径(相对路径或者绝对路径)
|
||||
// 相对路径:相对执行的可执行文件的相对路径
|
||||
// viper.SetConfigFile("./conf/config.yaml")
|
||||
viper.SetConfigFile(filePath)
|
||||
|
||||
err = viper.ReadInConfig() // 读取配置信息
|
||||
if err != nil {
|
||||
// 读取配置信息失败
|
||||
fmt.Printf("viper.ReadInConfig failed, err:%v\n", err)
|
||||
return
|
||||
}
|
||||
// 如果使用的是 viper.GetXxx()方式使用配置的话,就无须下面的操作
|
||||
|
||||
// 把读取到的配置信息反序列化到 Conf 变量中
|
||||
if err := viper.Unmarshal(Conf); err != nil {
|
||||
fmt.Printf("viper.Unmarshal failed, err:%v\n", err)
|
||||
}
|
||||
|
||||
viper.WatchConfig() // 配置文件监听
|
||||
viper.OnConfigChange(func(in fsnotify.Event) {
|
||||
ConfLock.Lock() // 获取锁
|
||||
defer ConfLock.Unlock() // 释放锁
|
||||
fmt.Println("配置文件修改了...")
|
||||
if err := viper.Unmarshal(&Conf); err != nil {
|
||||
fmt.Printf("viper.Unmarshal failed, err:%v\n", err)
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
65
go.mod
65
go.mod
@ -3,31 +3,78 @@ module beacon
|
||||
go 1.24.4
|
||||
|
||||
require (
|
||||
github.com/fsnotify/fsnotify v1.9.0
|
||||
github.com/gin-contrib/cors v1.7.6
|
||||
github.com/gin-gonic/gin v1.10.1
|
||||
github.com/go-playground/locales v0.14.1
|
||||
github.com/go-playground/universal-translator v0.18.1
|
||||
github.com/go-playground/validator/v10 v10.26.0
|
||||
github.com/go-sql-driver/mysql v1.9.3
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/natefinch/lumberjack v2.0.0+incompatible
|
||||
github.com/openai/openai-go v1.6.0
|
||||
github.com/spf13/viper v1.20.1
|
||||
go.temporal.io/sdk v1.34.0
|
||||
google.golang.org/protobuf v1.36.5
|
||||
go.uber.org/zap v1.18.1
|
||||
google.golang.org/grpc v1.67.3
|
||||
google.golang.org/protobuf v1.36.6
|
||||
gorm.io/driver/mysql v1.6.0
|
||||
gorm.io/gorm v1.30.0
|
||||
)
|
||||
|
||||
require (
|
||||
filippo.io/edwards25519 v1.1.0 // indirect
|
||||
github.com/bytedance/sonic v1.13.3 // indirect
|
||||
github.com/bytedance/sonic/loader v0.2.4 // indirect
|
||||
github.com/cloudwego/base64x v0.1.5 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.9 // indirect
|
||||
github.com/gin-contrib/sse v1.1.0 // indirect
|
||||
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
|
||||
github.com/goccy/go-json v0.10.5 // indirect
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/golang/mock v1.6.0 // indirect
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
|
||||
github.com/leodido/go-urn v1.4.0 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/nexus-rpc/sdk-go v0.3.0 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/robfig/cron v1.2.0 // indirect
|
||||
github.com/sagikazarmark/locafero v0.7.0 // indirect
|
||||
github.com/sourcegraph/conc v0.3.0 // indirect
|
||||
github.com/spf13/afero v1.12.0 // indirect
|
||||
github.com/spf13/cast v1.7.1 // indirect
|
||||
github.com/spf13/pflag v1.0.6 // indirect
|
||||
github.com/stretchr/objx v0.5.2 // indirect
|
||||
github.com/stretchr/testify v1.10.0 // indirect
|
||||
github.com/subosito/gotenv v1.6.0 // indirect
|
||||
github.com/tidwall/gjson v1.14.4 // indirect
|
||||
github.com/tidwall/match v1.1.1 // indirect
|
||||
github.com/tidwall/pretty v1.2.1 // indirect
|
||||
github.com/tidwall/sjson v1.2.5 // indirect
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/ugorji/go/codec v1.3.0 // indirect
|
||||
go.temporal.io/api v1.46.0 // indirect
|
||||
golang.org/x/net v0.36.0 // indirect
|
||||
golang.org/x/sync v0.11.0 // indirect
|
||||
golang.org/x/sys v0.30.0 // indirect
|
||||
golang.org/x/text v0.22.0 // indirect
|
||||
golang.org/x/time v0.3.0 // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240827150818-7e3bb234dfed // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240827150818-7e3bb234dfed // indirect
|
||||
google.golang.org/grpc v1.66.0 // indirect
|
||||
go.uber.org/atomic v1.9.0 // indirect
|
||||
go.uber.org/multierr v1.9.0 // indirect
|
||||
golang.org/x/arch v0.18.0 // indirect
|
||||
golang.org/x/crypto v0.39.0 // indirect
|
||||
golang.org/x/net v0.41.0 // indirect
|
||||
golang.org/x/sync v0.15.0 // indirect
|
||||
golang.org/x/sys v0.33.0 // indirect
|
||||
golang.org/x/text v0.26.0 // indirect
|
||||
golang.org/x/time v0.8.0 // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20241209162323-e6fa225c2576 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20241223144023-3abc09e42ca8 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
160
go.sum
160
go.sum
@ -1,8 +1,20 @@
|
||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
|
||||
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
|
||||
github.com/bytedance/sonic v1.13.3 h1:MS8gmaH16Gtirygw7jV91pDCN33NyMrPbN7qiYhEsF0=
|
||||
github.com/bytedance/sonic v1.13.3/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4=
|
||||
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
|
||||
github.com/bytedance/sonic/loader v0.2.4 h1:ZWCw4stuXUsn1/+zQDqeE7JKP+QO47tz7QCNan80NzY=
|
||||
github.com/bytedance/sonic/loader v0.2.4/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4=
|
||||
github.com/cloudwego/base64x v0.1.5/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
|
||||
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
|
||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
@ -13,9 +25,35 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a h1:yDWHCSQ40h88yih2JAcL6Ls/kVkSE8GFACTGVnMPruw=
|
||||
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a/go.mod h1:7Ga40egUymuWXxAe151lTNnCv97MddSOVsjpPPkityA=
|
||||
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
|
||||
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
|
||||
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
|
||||
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
|
||||
github.com/gabriel-vasile/mimetype v1.4.9 h1:5k+WDwEsD9eTLL8Tz3L0VnmVh9QxGjRmjBvAG7U/oYY=
|
||||
github.com/gabriel-vasile/mimetype v1.4.9/go.mod h1:WnSQhFKJuBlRyLiKohA/2DtIlPFAbguNaG7QCHcyGok=
|
||||
github.com/gin-contrib/cors v1.7.6 h1:3gQ8GMzs1Ylpf70y8bMw4fVpycXIeX1ZemuSQIsnQQY=
|
||||
github.com/gin-contrib/cors v1.7.6/go.mod h1:Ulcl+xN4jel9t1Ry8vqph23a60FwH9xVLd+3ykmTjOk=
|
||||
github.com/gin-contrib/sse v1.1.0 h1:n0w2GMuUpWDVp7qSpvze6fAu9iRxJY4Hmj6AmBOU05w=
|
||||
github.com/gin-contrib/sse v1.1.0/go.mod h1:hxRZ5gVpWMT7Z0B0gSNYqqsSCNIJMjzvm6fqCz9vjwM=
|
||||
github.com/gin-gonic/gin v1.10.1 h1:T0ujvqyCSqRopADpgPgiTT63DUQVSfojyME59Ei63pQ=
|
||||
github.com/gin-gonic/gin v1.10.1/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
|
||||
github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
|
||||
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
|
||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
||||
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
||||
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
||||
github.com/go-playground/validator/v10 v10.26.0 h1:SP05Nqhjcvz81uJaRfEV0YBSSSGMc/iMaVtFbr3Sw2k=
|
||||
github.com/go-playground/validator/v10 v10.26.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo=
|
||||
github.com/go-sql-driver/mysql v1.9.3 h1:U/N249h2WzJ3Ukj8SowVFjdtZKfu9vlLZxjPXV1aweo=
|
||||
github.com/go-sql-driver/mysql v1.9.3/go.mod h1:qn46aNg1333BRMNU69Lq93t8du/dwxI64Gl8i5p1WMU=
|
||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||
github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss=
|
||||
github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
|
||||
github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=
|
||||
github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
|
||||
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
|
||||
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
@ -28,16 +66,27 @@ github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaW
|
||||
github.com/golang/protobuf v1.5.0 h1:LUVKkCeviFUMKqHa4tXIIij/lbhnMbP7Fn5wKdKkRh4=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI=
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0/go.mod h1:g5qyo/la0ALbONm6Vbp88Yd8NsDy6rZz+RcrMPxvld8=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 h1:asbCHRVmodnJTuQ3qamDwqVOIjwqUPTYmYuemVOx+Ys=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0/go.mod h1:ggCgvZ2r7uOoQjOyu2Y1NhHmEPPzzuhWgcza5M1Ji1I=
|
||||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
||||
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
|
||||
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=
|
||||
github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
|
||||
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
@ -46,9 +95,25 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
||||
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/natefinch/lumberjack v2.0.0+incompatible h1:4QJd3OLAMgj7ph+yZTuX13Ld4UpgHp07nNdFX7mqFfM=
|
||||
github.com/natefinch/lumberjack v2.0.0+incompatible/go.mod h1:Wi9p2TTF5DG5oU+6YfsmYQpsTIOm0B1VNzQg9Mw6nPk=
|
||||
github.com/nexus-rpc/sdk-go v0.3.0 h1:Y3B0kLYbMhd4C2u00kcYajvmOrfozEtTV/nHSnV57jA=
|
||||
github.com/nexus-rpc/sdk-go v0.3.0/go.mod h1:TpfkM2Cw0Rlk9drGkoiSMpFqflKTiQLWUNyKJjF8mKQ=
|
||||
github.com/openai/openai-go v1.6.0 h1:KGjDS5sDrO27vykzO50BYknuabzVxuFuwAB8DjrmexI=
|
||||
github.com/openai/openai-go v1.6.0/go.mod h1:g461MYGXEXBVdV5SaR/5tNzNbSfwTBBefwc+LlDCK0Y=
|
||||
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
|
||||
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
|
||||
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
|
||||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
@ -57,17 +122,50 @@ github.com/robfig/cron v1.2.0 h1:ZjScXvvxeQ63Dbyxy76Fj3AT3Ut0aKsyd2/tl3DTMuQ=
|
||||
github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k=
|
||||
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
|
||||
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
|
||||
github.com/sagikazarmark/locafero v0.7.0 h1:5MqpDsTGNDhY8sGp0Aowyf0qKsPrhewaLSsFaodPcyo=
|
||||
github.com/sagikazarmark/locafero v0.7.0/go.mod h1:2za3Cg5rMaTMoG/2Ulr9AwtFaIppKXTRYnozin4aB5k=
|
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
|
||||
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
|
||||
github.com/spf13/afero v1.12.0 h1:UcOPyRBYczmFn6yvphxkn9ZEOY65cpwGKb5mL36mrqs=
|
||||
github.com/spf13/afero v1.12.0/go.mod h1:ZTlWwG4/ahT8W7T0WQ5uYmjI9duaLQGy3Q2OAl4sk/4=
|
||||
github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=
|
||||
github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
|
||||
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
|
||||
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/spf13/viper v1.20.1 h1:ZMi+z/lvLyPSCoNtFCpqjy0S4kPbirhpTMwl8BkW9X4=
|
||||
github.com/spf13/viper v1.20.1/go.mod h1:P9Mdzt1zoHIG8m2eZQinpiBjo6kCmZSKBClNNqjJvu4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
|
||||
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
|
||||
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
|
||||
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM=
|
||||
github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
|
||||
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
||||
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
|
||||
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||
github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
|
||||
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
||||
github.com/ugorji/go/codec v1.3.0 h1:Qd2W2sQawAfG8XSvzwhBeoGq71zXOC/Q1E9y/wUcsUA=
|
||||
github.com/ugorji/go/codec v1.3.0/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4=
|
||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
@ -76,16 +174,27 @@ go.temporal.io/api v1.46.0/go.mod h1:iaxoP/9OXMJcQkETTECfwYq4cw/bj4nwov8b3ZLVnXM
|
||||
go.temporal.io/sdk v1.34.0 h1:VLg/h6ny7GvLFVoQPqz2NcC93V9yXboQwblkRvZ1cZE=
|
||||
go.temporal.io/sdk v1.34.0/go.mod h1:iE4U5vFrH3asOhqpBBphpj9zNtw8btp8+MSaf5A0D3w=
|
||||
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
|
||||
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/goleak v1.1.10 h1:z+mqJhf6ss6BSfSM671tgKyZBFPTTJM+HLxnhPC3wu0=
|
||||
go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A=
|
||||
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
|
||||
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
|
||||
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
|
||||
go.uber.org/zap v1.18.1 h1:CSUJ2mjFszzEWt4CdKISEuChVIXGBn3lAPwkRGyVrc4=
|
||||
go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI=
|
||||
golang.org/x/arch v0.18.0 h1:WN9poc33zL4AzGxqf8VtpKUnGvMi8O9lhNyBMF/85qc=
|
||||
golang.org/x/arch v0.18.0/go.mod h1:bdwinDaKcfZUGpH09BB7ZmOfhalA8lQdzl62l8gGWsk=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM=
|
||||
golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
|
||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
@ -99,8 +208,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
|
||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||
golang.org/x/net v0.36.0 h1:vWF2fRbw4qslQsQzgFqZff+BItCvGFQqKzKIzx1rmoA=
|
||||
golang.org/x/net v0.36.0/go.mod h1:bFmbeoIPfrw4sMHNhb4J9f6+tPziuGjq7Jk/38fxi1I=
|
||||
golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw=
|
||||
golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
@ -108,8 +217,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
|
||||
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8=
|
||||
golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
@ -119,15 +228,16 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
|
||||
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
|
||||
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
|
||||
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
|
||||
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
|
||||
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
|
||||
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
|
||||
golang.org/x/time v0.8.0 h1:9i3RxcPv3PZnitoVGMPDKZSq1xW1gK1Xy3ArNOGZfEg=
|
||||
golang.org/x/time v0.8.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||
@ -138,6 +248,8 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
|
||||
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||
golang.org/x/tools v0.33.0 h1:4qz2S3zmRxbGIhDIAgjxvFutSvH5EfnsYrRBj0UI0bc=
|
||||
golang.org/x/tools v0.33.0/go.mod h1:CIJMaWEY88juyUfo7UbgPqbC8rU2OqfAV1h2Qp0oMYI=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
@ -147,28 +259,36 @@ google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||
google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240827150818-7e3bb234dfed h1:3RgNmBoI9MZhsj3QxC+AP/qQhNwpCLOvYDYYsFrhFt0=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240827150818-7e3bb234dfed/go.mod h1:OCdP9MfskevB/rbYvHTsXTtKC+3bHWajPdoKgjcYkfo=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240827150818-7e3bb234dfed h1:J6izYgfBXAI3xTKLgxzTmUltdYaLsuBxFCgDHWJ/eXg=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240827150818-7e3bb234dfed/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20241209162323-e6fa225c2576 h1:CkkIfIt50+lT6NHAVoRYEyAvQGFM7xEwXUUywFvEb3Q=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20241209162323-e6fa225c2576/go.mod h1:1R3kvZ1dtP3+4p4d3G8uJ8rFk/fWlScl38vanWACI08=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20241223144023-3abc09e42ca8 h1:TqExAhdPaB60Ux47Cn0oLV07rGnxZzIsaRhQaqS666A=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20241223144023-3abc09e42ca8/go.mod h1:lcTa1sDdWEIHMWlITnIczmw5w60CF9ffkb8Z+DVmmjA=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
|
||||
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk=
|
||||
google.golang.org/grpc v1.66.0 h1:DibZuoBznOxbDQxRINckZcUvnCEvrW9pcWIE2yF9r1c=
|
||||
google.golang.org/grpc v1.66.0/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y=
|
||||
google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
|
||||
google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
||||
google.golang.org/grpc v1.67.3 h1:OgPcDAFKHnH8X3O4WcO4XUc8GRDeKsKReqbQtiCj7N8=
|
||||
google.golang.org/grpc v1.67.3/go.mod h1:YGaHCc6Oap+FzBJTZLBzkGSYt/cvGPFTPxkn7QfSU8s=
|
||||
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
|
||||
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gorm.io/driver/mysql v1.6.0 h1:eNbLmNTpPpTOVZi8MMxCi2aaIm0ZpInbORNXDwyLGvg=
|
||||
gorm.io/driver/mysql v1.6.0/go.mod h1:D/oCC2GWK3M/dqoLxnOlaNKmXz8WNTfcS9y5ovaSqKo=
|
||||
gorm.io/gorm v1.30.0 h1:qbT5aPv1UH8gI99OsRlvDToLxW5zR7FzS9acZDOZcgs=
|
||||
gorm.io/gorm v1.30.0/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
|
||||
|
72
main.go
Normal file
72
main.go
Normal file
@ -0,0 +1,72 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"beacon/config"
|
||||
dao "beacon/pkg/dao/mysql"
|
||||
"beacon/pkg/logger"
|
||||
"beacon/pkg/validator"
|
||||
"beacon/routers"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func Run() {
|
||||
// 从命令行获取配置
|
||||
var cfn string
|
||||
flag.StringVar(&cfn, "conf", "./config/config.yaml", "指定启动的配置文件")
|
||||
flag.Parse()
|
||||
|
||||
// 1.加载配置文件
|
||||
err := config.InitFromFile(cfn)
|
||||
if err != nil {
|
||||
panic(err) // 程序启动时加载配置文件失败直接退出
|
||||
}
|
||||
|
||||
// 2.加载日志
|
||||
err = logger.Init(config.Conf.LogConfig, config.Conf.Mode)
|
||||
if err != nil {
|
||||
panic(err) // 程序启动时初始化日志模块失败直接退出
|
||||
}
|
||||
|
||||
// 添加校验规则
|
||||
err = validator.InitTrans("zh")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// gorm
|
||||
err = dao.InitGorm(config.Conf.MySQLConfig)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
gin.SetMode(gin.DebugMode)
|
||||
|
||||
// 6.HTTP 初始化路由
|
||||
r := routers.Init()
|
||||
go func() {
|
||||
// 启动服务
|
||||
err := r.Run(fmt.Sprintf("%s:%d", config.Conf.IP, config.Conf.Port))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
zap.L().Info(fmt.Sprintf("Serving Gin on %s:%d", config.Conf.IP, config.Conf.Port))
|
||||
zap.L().Info("service start...")
|
||||
|
||||
// 接收操作系统发来的中断信号
|
||||
QuitChan := make(chan os.Signal)
|
||||
signal.Notify(QuitChan, syscall.SIGTERM, syscall.SIGINT, syscall.SIGKILL) // kill -15 CTRL+C kill -9
|
||||
<-QuitChan
|
||||
|
||||
}
|
||||
|
||||
func main() {
|
||||
Run()
|
||||
}
|
26
middleware/cors.go
Normal file
26
middleware/cors.go
Normal file
@ -0,0 +1,26 @@
|
||||
package middleware
|
||||
|
||||
import "time"
|
||||
|
||||
import (
|
||||
"github.com/gin-contrib/cors"
|
||||
)
|
||||
|
||||
var CSRFMiddleware = cors.New(cors.Config{
|
||||
//准许跨域请求网站,多个使用,分开,限制使用*
|
||||
AllowOrigins: []string{"*"},
|
||||
//准许使用的请求方式
|
||||
AllowMethods: []string{"OPTIONS", "PUT", "PATCH", "POST", "GET", "DELETE"},
|
||||
//准许使用的请求表头
|
||||
AllowHeaders: []string{"Origin", "AccessToken", "Content-Type"},
|
||||
//显示的请求表头
|
||||
ExposeHeaders: []string{"Content-Type"},
|
||||
//凭证共享,确定共享
|
||||
AllowCredentials: true,
|
||||
//容许跨域的原点网站,可以直接return true就万事大吉了
|
||||
AllowOriginFunc: func(origin string) bool {
|
||||
return true
|
||||
},
|
||||
//超时时间设定
|
||||
MaxAge: 24 * time.Hour,
|
||||
})
|
33
middleware/crawler.go
Normal file
33
middleware/crawler.go
Normal file
@ -0,0 +1,33 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// AntiCrawlingStrategy 反爬虫策略
|
||||
func AntiCrawlingStrategy() gin.HandlerFunc {
|
||||
return func(context *gin.Context) {
|
||||
UserAgent := strings.Split(context.Request.UserAgent(), "/")
|
||||
var requestClient string
|
||||
if len(UserAgent) > 0 {
|
||||
requestClient = UserAgent[0]
|
||||
}
|
||||
IllegalList := []string{"", "Apache-HttpClient", "python-requests", "PostmanRuntime", "Go-http-client"}
|
||||
for _, illegal := range IllegalList {
|
||||
if illegal == requestClient {
|
||||
zap.L().Warn("非法用户请求", zap.String("UserAgent", requestClient))
|
||||
context.JSON(http.StatusNotImplemented, gin.H{
|
||||
"code": -1,
|
||||
"msg": "系统错误,请稍后再试",
|
||||
})
|
||||
context.Abort()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
context.Next()
|
||||
}
|
||||
}
|
82
middleware/default.go
Normal file
82
middleware/default.go
Normal file
@ -0,0 +1,82 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func GinLogger(logger *zap.Logger) gin.HandlerFunc {
|
||||
return func(context *gin.Context) {
|
||||
start := time.Now()
|
||||
path := context.Request.URL.Path
|
||||
query := context.Request.URL.RawQuery
|
||||
context.Next()
|
||||
|
||||
cost := time.Since(start)
|
||||
logger.Info(path,
|
||||
zap.Int("status", context.Writer.Status()),
|
||||
zap.String("method", context.Request.Method),
|
||||
zap.String("path", path),
|
||||
zap.String("query", query),
|
||||
zap.String("ip", context.ClientIP()),
|
||||
zap.String("user-agent", context.Request.UserAgent()),
|
||||
zap.String("errors", context.Errors.ByType(gin.ErrorTypePrivate).String()),
|
||||
zap.Duration("cost", cost),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func GinRecovery(logger *zap.Logger, stack bool) gin.HandlerFunc {
|
||||
return func(context *gin.Context) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
// Check for a broken connection, as it is not really a
|
||||
// condition that warrants a panic stack trace.
|
||||
var brokenPipe bool
|
||||
if ne, ok := err.(*net.OpError); ok {
|
||||
if se, ok := ne.Err.(*os.SyscallError); ok {
|
||||
if strings.Contains(strings.ToLower(se.Error()), "broken pipe") || strings.Contains(strings.ToLower(se.Error()), "connection reset by peer") {
|
||||
brokenPipe = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
httpRequest, _ := httputil.DumpRequest(context.Request, false)
|
||||
if brokenPipe {
|
||||
logger.Error(context.Request.URL.Path,
|
||||
zap.Any("error", err),
|
||||
zap.String("request", string(httpRequest)),
|
||||
)
|
||||
// If the connection is dead, we can't write a status to it.
|
||||
context.Error(err.(error)) // nolint: err check
|
||||
context.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
if stack {
|
||||
logger.Error("[Recovery from panic]",
|
||||
zap.Any("error", err),
|
||||
zap.String("request", string(httpRequest)),
|
||||
zap.String("stack", string(debug.Stack())),
|
||||
)
|
||||
} else {
|
||||
logger.Error("[Recovery from panic]",
|
||||
zap.Any("error", err),
|
||||
zap.String("request", string(httpRequest)),
|
||||
)
|
||||
}
|
||||
|
||||
// 500
|
||||
context.AbortWithStatus(http.StatusInternalServerError)
|
||||
}
|
||||
}()
|
||||
context.Next()
|
||||
}
|
||||
}
|
71
models/composite.go
Normal file
71
models/composite.go
Normal file
@ -0,0 +1,71 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
// CompositeCase 复合案例定义
|
||||
type CompositeCase struct {
|
||||
ID uint `json:"id" gorm:"primaryKey"`
|
||||
Name string `json:"name" gorm:"not null;size:255"`
|
||||
Description string `json:"description" gorm:"type:text"`
|
||||
Status string `json:"status" gorm:"default:'active';size:50"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
|
||||
|
||||
// 关联的步骤
|
||||
Steps []CompositeCaseStep `json:"steps" gorm:"foreignKey:CompositeCaseID"`
|
||||
}
|
||||
|
||||
// CompositeCaseStep 复合案例步骤
|
||||
type CompositeCaseStep struct {
|
||||
ID uint `json:"id" gorm:"primaryKey"`
|
||||
CompositeCaseID uint `json:"composite_case_id" gorm:"not null"`
|
||||
StepOrder int `json:"step_order" gorm:"not null"`
|
||||
StepName string `json:"step_name" gorm:"not null;size:255"`
|
||||
StepDescription string `json:"step_description" gorm:"type:text"`
|
||||
StepType string `json:"step_type" gorm:"not null;size:100"`
|
||||
StepConfig string `json:"step_config" gorm:"type:json"`
|
||||
IsRequired bool `json:"is_required" gorm:"default:true"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// CreateCompositeCaseRequest 创建复合案例请求
|
||||
type CreateCompositeCaseRequest struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
Description string `json:"description"`
|
||||
Status string `json:"status"`
|
||||
Steps []CreateCompositeCaseStepRequest `json:"steps"`
|
||||
}
|
||||
|
||||
// CreateCompositeCaseStepRequest 创建复合案例步骤请求
|
||||
type CreateCompositeCaseStepRequest struct {
|
||||
StepOrder int `json:"step_order" binding:"required"`
|
||||
StepName string `json:"step_name" binding:"required"`
|
||||
StepDescription string `json:"step_description"`
|
||||
StepType string `json:"step_type" binding:"required"`
|
||||
StepConfig string `json:"step_config"`
|
||||
IsRequired bool `json:"is_required"`
|
||||
}
|
||||
|
||||
// UpdateCompositeCaseRequest 更新复合案例请求
|
||||
type UpdateCompositeCaseRequest struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Status string `json:"status"`
|
||||
Steps []UpdateCompositeCaseStepRequest `json:"steps"`
|
||||
}
|
||||
|
||||
// UpdateCompositeCaseStepRequest 更新复合案例步骤请求
|
||||
type UpdateCompositeCaseStepRequest struct {
|
||||
ID uint `json:"id"`
|
||||
StepOrder int `json:"step_order"`
|
||||
StepName string `json:"step_name"`
|
||||
StepDescription string `json:"step_description"`
|
||||
StepType string `json:"step_type"`
|
||||
StepConfig string `json:"step_config"`
|
||||
IsRequired bool `json:"is_required"`
|
||||
}
|
42
pkg/dao/mysql/default.go
Normal file
42
pkg/dao/mysql/default.go
Normal file
@ -0,0 +1,42 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"beacon/config"
|
||||
"fmt"
|
||||
_ "github.com/go-sql-driver/mysql" // 匿名导入 init()
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/logger"
|
||||
"time"
|
||||
)
|
||||
|
||||
var DB *gorm.DB
|
||||
|
||||
// InitGorm 初始化MySQL连接
|
||||
func InitGorm(cfg *config.MySQLConfig) (err error) {
|
||||
// 参考 https://github.com/go-sql-driver/mysql#dsn-data-source-name 获取详情
|
||||
dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local", cfg.User, cfg.Password, cfg.Host, cfg.Port, cfg.DB)
|
||||
DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{
|
||||
Logger: logger.Default.LogMode(logger.Info),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 额外的连接配置
|
||||
db, err := DB.DB() // database/sql.sqlxDB
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 以下配置要配合 my.conf 进行配置
|
||||
// SetMaxIdleConns 设置空闲连接池中连接的最大数量
|
||||
db.SetMaxIdleConns(cfg.MaxIdleConns)
|
||||
|
||||
// SetMaxOpenConns 设置打开数据库连接的最大数量。
|
||||
db.SetMaxOpenConns(cfg.MaxOpenConns)
|
||||
|
||||
// SetConnMaxLifetime 设置了连接可复用的最大时间。
|
||||
db.SetConnMaxLifetime(time.Hour)
|
||||
return
|
||||
}
|
67
pkg/logger/logger.go
Executable file
67
pkg/logger/logger.go
Executable file
@ -0,0 +1,67 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"beacon/config"
|
||||
"github.com/natefinch/lumberjack"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
"os"
|
||||
)
|
||||
|
||||
var Lg *zap.Logger
|
||||
|
||||
// zap日志库三要素
|
||||
// 1.encoder编码 2.输出位置 3.日志级别
|
||||
|
||||
// Init 初始化lg
|
||||
func Init(cfg *config.LogConfig, mode string) (err error) {
|
||||
writeSyncer := getLogWriter(cfg.Filename, cfg.MaxSize, cfg.MaxBackups, cfg.MaxAge)
|
||||
writeErrSyncer := getLogWriter(cfg.FilenameErr, cfg.MaxSize, cfg.MaxBackups, cfg.MaxAge)
|
||||
|
||||
encoder := getEncoder()
|
||||
var l = new(zapcore.Level)
|
||||
err = l.UnmarshalText([]byte(cfg.Level))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var core zapcore.Core
|
||||
if mode == "dev" {
|
||||
// 进入开发模式,日志输出到终端
|
||||
consoleEncoder := zapcore.NewConsoleEncoder(zap.NewDevelopmentEncoderConfig())
|
||||
core = zapcore.NewTee(
|
||||
zapcore.NewCore(encoder, writeSyncer, l),
|
||||
zapcore.NewCore(consoleEncoder, zapcore.Lock(os.Stdout), zapcore.DebugLevel),
|
||||
)
|
||||
} else {
|
||||
confCore := zapcore.NewCore(encoder, writeSyncer, l)
|
||||
errCore := zapcore.NewCore(encoder, writeErrSyncer, zapcore.ErrorLevel)
|
||||
core = zapcore.NewTee(confCore, errCore)
|
||||
}
|
||||
// 复习回顾:日志默认输出到app.log,如何将err日志单独在 app.err.log 记录一份
|
||||
|
||||
Lg = zap.New(core, zap.AddCaller()) // zap.AddCaller() 添加调用栈信息
|
||||
|
||||
zap.ReplaceGlobals(Lg) // 替换zap包全局的logger
|
||||
zap.L().Info("init logger success")
|
||||
return
|
||||
}
|
||||
|
||||
func getEncoder() zapcore.Encoder {
|
||||
encoderConfig := zap.NewProductionEncoderConfig()
|
||||
encoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
|
||||
encoderConfig.TimeKey = "time"
|
||||
encoderConfig.EncodeLevel = zapcore.CapitalLevelEncoder
|
||||
encoderConfig.EncodeDuration = zapcore.SecondsDurationEncoder
|
||||
encoderConfig.EncodeCaller = zapcore.ShortCallerEncoder
|
||||
return zapcore.NewJSONEncoder(encoderConfig)
|
||||
}
|
||||
|
||||
func getLogWriter(filename string, maxSize, maxBackup, maxAge int) zapcore.WriteSyncer {
|
||||
lumberJackLogger := &lumberjack.Logger{
|
||||
Filename: filename,
|
||||
MaxSize: maxSize,
|
||||
MaxBackups: maxBackup,
|
||||
MaxAge: maxAge,
|
||||
}
|
||||
return zapcore.AddSync(lumberJackLogger)
|
||||
}
|
66
pkg/openai/openai.go
Normal file
66
pkg/openai/openai.go
Normal file
@ -0,0 +1,66 @@
|
||||
package openai
|
||||
|
||||
import (
|
||||
"beacon/config"
|
||||
"beacon/utils"
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
|
||||
"github.com/openai/openai-go"
|
||||
"github.com/openai/openai-go/option"
|
||||
)
|
||||
|
||||
// encodeImageToBase64 是一个辅助函数,用于读取图像文件,
|
||||
// 检测其 MIME 类型,并将其编码为 Base64 数据 URI。
|
||||
func encodeImageToBase64(file *multipart.FileHeader) (string, error) {
|
||||
// 1. 读取文件字节。
|
||||
bytes := utils.FileStreamToBytes(file)
|
||||
|
||||
// 2. 检测文件的 MIME 类型。
|
||||
// 这对于构建正确的数据 URI至关重要。
|
||||
mimeType := http.DetectContentType(bytes)
|
||||
|
||||
// 3. 对文件字节进行 Base64 编码。
|
||||
encodedStr := base64.StdEncoding.EncodeToString(bytes)
|
||||
|
||||
// 4. 构建并返回完整的数据 URI 字符串。
|
||||
return fmt.Sprintf("data:%s;base64,%s", mimeType, encodedStr), nil
|
||||
}
|
||||
|
||||
func GetOllamaAICaptcha(file *multipart.FileHeader) (error, string) {
|
||||
client := openai.NewClient(
|
||||
option.WithAPIKey(config.Conf.OpenAI.ApiKey), // defaults to os.LookupEnv("OPENAI_API_KEY")
|
||||
option.WithBaseURL(config.Conf.OpenAI.BaseURL),
|
||||
)
|
||||
|
||||
base64Image, _ := encodeImageToBase64(file)
|
||||
|
||||
var message []openai.ChatCompletionContentPartUnionParam
|
||||
message = append(message,
|
||||
openai.ChatCompletionContentPartUnionParam{
|
||||
OfImageURL: &openai.ChatCompletionContentPartImageParam{
|
||||
ImageURL: openai.ChatCompletionContentPartImageImageURLParam{
|
||||
URL: base64Image,
|
||||
},
|
||||
},
|
||||
},
|
||||
openai.ChatCompletionContentPartUnionParam{
|
||||
OfText: &openai.ChatCompletionContentPartTextParam{
|
||||
Text: config.Conf.OpenAI.Prompt,
|
||||
},
|
||||
},
|
||||
)
|
||||
chatCompletion, err := client.Chat.Completions.New(context.TODO(), openai.ChatCompletionNewParams{
|
||||
Messages: []openai.ChatCompletionMessageParamUnion{
|
||||
openai.UserMessage(message),
|
||||
},
|
||||
Model: config.Conf.OpenAI.Model,
|
||||
})
|
||||
if err != nil {
|
||||
return err, ""
|
||||
}
|
||||
return nil, chatCompletion.Choices[0].Message.Content
|
||||
}
|
105
pkg/validator/validator.go
Executable file
105
pkg/validator/validator.go
Executable file
@ -0,0 +1,105 @@
|
||||
package validator
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
"github.com/go-playground/locales/en"
|
||||
"github.com/go-playground/locales/zh"
|
||||
ut "github.com/go-playground/universal-translator"
|
||||
"github.com/go-playground/validator/v10"
|
||||
enTranslations "github.com/go-playground/validator/v10/translations/en"
|
||||
zhTranslations "github.com/go-playground/validator/v10/translations/zh"
|
||||
"go.uber.org/zap"
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Trans 定义一个全局翻译器T
|
||||
var Trans ut.Translator
|
||||
|
||||
// InitTrans 初始化翻译器
|
||||
func InitTrans(locale string) (err error) {
|
||||
// 修改gin框架中的Validator引擎属性,实现自定制
|
||||
v, ok := binding.Validator.Engine().(*validator.Validate)
|
||||
if ok {
|
||||
// 注册一个获取json tag的自定义方法
|
||||
v.RegisterTagNameFunc(func(fld reflect.StructField) string {
|
||||
name := strings.SplitN(fld.Tag.Get("json"), ",", 2)[0]
|
||||
if name == "-" {
|
||||
return ""
|
||||
}
|
||||
return name
|
||||
})
|
||||
|
||||
zhT := zh.New() // 中文翻译器
|
||||
enT := en.New() // 英文翻译器
|
||||
|
||||
// 第一个参数是备用(fallback)的语言环境
|
||||
// 后面的参数是应该支持的语言环境(支持多个)
|
||||
// uni := ut.New(zhT, zhT) 也是可以的
|
||||
uni := ut.New(enT, zhT, enT)
|
||||
|
||||
// locale 通常取决于 http 请求头的 'Accept-Language'
|
||||
var ok bool
|
||||
// 也可以使用 uni.FindTranslator(...) 传入多个locale进行查找
|
||||
Trans, ok = uni.GetTranslator(locale)
|
||||
if !ok {
|
||||
return fmt.Errorf("uni.GetTranslator(%s) failed", locale)
|
||||
}
|
||||
|
||||
// 注册翻译器
|
||||
switch locale {
|
||||
case "en":
|
||||
err = enTranslations.RegisterDefaultTranslations(v, Trans)
|
||||
case "zh":
|
||||
err = zhTranslations.RegisterDefaultTranslations(v, Trans)
|
||||
default:
|
||||
err = enTranslations.RegisterDefaultTranslations(v, Trans)
|
||||
}
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func RemoveTopStruct(fields map[string]string) map[string]string {
|
||||
zap.L().Debug("RemoveTopStruct", zap.Any("fields", fields))
|
||||
message := map[string]string{}
|
||||
for field, err := range fields {
|
||||
dotIndex := strings.Index(field, ".")
|
||||
if dotIndex != -1 {
|
||||
message[field[dotIndex+1:]] = err
|
||||
} else {
|
||||
message[field] = err
|
||||
}
|
||||
}
|
||||
|
||||
if len(message) == 0 {
|
||||
message = map[string]string{"body": "请求的参数有误"}
|
||||
}
|
||||
return message
|
||||
}
|
||||
|
||||
func TranslateErr(err error) map[string]string {
|
||||
zap.L().Debug("TranslateErr", zap.Any("err", err))
|
||||
var errs validator.ValidationErrors
|
||||
if errors.As(err, &errs) {
|
||||
return RemoveTopStruct(errs.Translate(Trans))
|
||||
}
|
||||
// 处理 JSON unmarshal 错误,提取字段名
|
||||
var unmarshalErr *json.UnmarshalTypeError
|
||||
if errors.As(err, &unmarshalErr) {
|
||||
fieldName := unmarshalErr.Field
|
||||
if fieldName != "" {
|
||||
// 获取目标类型
|
||||
targetType := unmarshalErr.Type.String()
|
||||
|
||||
if strings.Contains(fieldName, ".") {
|
||||
fieldName = strings.Split(fieldName, ".")[len(strings.Split(fieldName, "."))-1]
|
||||
}
|
||||
return map[string]string{fieldName: fmt.Sprintf("类型错误,期望类型为 %s", targetType)}
|
||||
}
|
||||
}
|
||||
return map[string]string{"body": err.Error()}
|
||||
}
|
185
routers/handlers/composite.go
Normal file
185
routers/handlers/composite.go
Normal file
@ -0,0 +1,185 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"beacon/models"
|
||||
"beacon/services"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type CompositeCaseHandler struct {
|
||||
service *services.CompositeCaseService
|
||||
}
|
||||
|
||||
// CreateCompositeCase POST /api/composite-cases
|
||||
func (h *CompositeCaseHandler) CreateCompositeCase(c *gin.Context) {
|
||||
zap.L().Info("CreateCompositeCase")
|
||||
var req models.CreateCompositeCaseRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": "请求参数错误",
|
||||
"details": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
zap.L().Info("req", zap.Any("req", req))
|
||||
compositeCase, err := h.service.CreateCompositeCase(&req)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"error": "创建复合案例失败",
|
||||
"details": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
zap.L().Info("compositeCase", zap.Any("compositeCase", compositeCase))
|
||||
c.JSON(http.StatusCreated, gin.H{
|
||||
"message": "创建复合案例成功",
|
||||
"data": compositeCase,
|
||||
})
|
||||
}
|
||||
|
||||
// GetCompositeCase GET /api/composite-cases/{id}
|
||||
func (h *CompositeCaseHandler) GetCompositeCase(c *gin.Context) {
|
||||
idParam := c.Param("id")
|
||||
id, err := strconv.ParseUint(idParam, 10, 32)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": "无效的ID参数",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
compositeCase, err := h.service.GetCompositeCaseByID(uint(id))
|
||||
if err != nil {
|
||||
if err.Error() == "复合案例不存在" {
|
||||
c.JSON(http.StatusNotFound, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"error": "获取复合案例失败",
|
||||
"details": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "获取复合案例成功",
|
||||
"data": compositeCase,
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateCompositeCase PUT /api/composite-cases/{id}
|
||||
func (h *CompositeCaseHandler) UpdateCompositeCase(c *gin.Context) {
|
||||
idParam := c.Param("id")
|
||||
id, err := strconv.ParseUint(idParam, 10, 32)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": "无效的ID参数",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
var req models.UpdateCompositeCaseRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": "请求参数错误",
|
||||
"details": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
compositeCase, err := h.service.UpdateCompositeCase(uint(id), &req)
|
||||
if err != nil {
|
||||
if err.Error() == "复合案例不存在" {
|
||||
c.JSON(http.StatusNotFound, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"error": "更新复合案例失败",
|
||||
"details": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "更新复合案例成功",
|
||||
"data": compositeCase,
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteCompositeCase DELETE /api/composite-cases/{id}
|
||||
func (h *CompositeCaseHandler) DeleteCompositeCase(c *gin.Context) {
|
||||
idParam := c.Param("id")
|
||||
id, err := strconv.ParseUint(idParam, 10, 32)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": "无效的ID参数",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
err = h.service.DeleteCompositeCase(uint(id))
|
||||
if err != nil {
|
||||
if err.Error() == "复合案例不存在" {
|
||||
c.JSON(http.StatusNotFound, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"error": "删除复合案例失败",
|
||||
"details": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "删除复合案例成功",
|
||||
})
|
||||
}
|
||||
|
||||
// ListCompositeCases GET /api/composite-cases
|
||||
func (h *CompositeCaseHandler) ListCompositeCases(c *gin.Context) {
|
||||
// 获取查询参数
|
||||
pageStr := c.DefaultQuery("page", "1")
|
||||
pageSizeStr := c.DefaultQuery("page_size", "10")
|
||||
status := c.Query("status")
|
||||
|
||||
page, err := strconv.Atoi(pageStr)
|
||||
if err != nil || page < 1 {
|
||||
page = 1
|
||||
}
|
||||
|
||||
pageSize, err := strconv.Atoi(pageSizeStr)
|
||||
if err != nil || pageSize < 1 || pageSize > 100 {
|
||||
pageSize = 10
|
||||
}
|
||||
|
||||
compositeCases, total, err := h.service.ListCompositeCases(page, pageSize, status)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"error": "获取复合案例列表失败",
|
||||
"details": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "获取复合案例列表成功",
|
||||
"data": gin.H{
|
||||
"items": compositeCases,
|
||||
"total": total,
|
||||
"page": page,
|
||||
"page_size": pageSize,
|
||||
"total_pages": (total + int64(pageSize) - 1) / int64(pageSize),
|
||||
},
|
||||
})
|
||||
}
|
105
routers/router.go
Normal file
105
routers/router.go
Normal file
@ -0,0 +1,105 @@
|
||||
package routers
|
||||
|
||||
import (
|
||||
"beacon/config"
|
||||
"beacon/middleware"
|
||||
"beacon/pkg/logger"
|
||||
"beacon/routers/handlers"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func Init() *gin.Engine {
|
||||
// 基于获取引擎对象(路由对象)
|
||||
r := gin.New()
|
||||
r.Use(middleware.GinLogger(logger.Lg))
|
||||
r.Use(middleware.GinRecovery(logger.Lg, false))
|
||||
//r.Use(middleware.AntiCrawlingStrategy()) // 反爬虫策略
|
||||
r.Use(middleware.CSRFMiddleware)
|
||||
//r.Use(middleware.JwtAuthMiddleware()) // 用户认证
|
||||
|
||||
// 设置自定义 404 页面
|
||||
r.NoRoute(func(c *gin.Context) {
|
||||
// 您可以使用 HTML 模板文件
|
||||
//c.HTML(404, "404.html", gin.H{
|
||||
// "title": "Page Not Found",
|
||||
//})
|
||||
|
||||
// 或者,您可以直接返回 HTML 代码
|
||||
c.Data(404, "text/html", []byte(`<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>404 Not Found</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: sans-serif;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
.container {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
.content {
|
||||
max-width: 600px;
|
||||
padding: 30px;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 36px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 18px;
|
||||
line-height: 1.5em;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #000;
|
||||
text-decoration: none;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="content">
|
||||
<h1>404</h1>
|
||||
<h2>Page Not Found</h2>
|
||||
<p>The page you are looking for does not exist or has been moved.</p>
|
||||
<p>You can <a href="/">go back to the homepage</a> or <a href="mailto:support@example.com">contact us</a> if you need assistance.</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
`))
|
||||
})
|
||||
|
||||
// 路由分组
|
||||
v1 := r.Group(config.Conf.Version)
|
||||
SetupCompositeCaseRoutes(v1)
|
||||
return r
|
||||
}
|
||||
|
||||
func SetupCompositeCaseRoutes(group *gin.RouterGroup) {
|
||||
// 初始化服务和处理器
|
||||
var handler *handlers.CompositeCaseHandler
|
||||
|
||||
api := group.Group("/api")
|
||||
{
|
||||
// 复合案例相关路由
|
||||
api.POST("/composite-cases", handler.CreateCompositeCase)
|
||||
api.GET("/composite-cases", handler.ListCompositeCases)
|
||||
api.GET("/composite-cases/:id", handler.GetCompositeCase)
|
||||
api.PUT("/composite-cases/:id", handler.UpdateCompositeCase)
|
||||
api.DELETE("/composite-cases/:id", handler.DeleteCompositeCase)
|
||||
}
|
||||
}
|
236
services/composite.go
Normal file
236
services/composite.go
Normal file
@ -0,0 +1,236 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"beacon/models"
|
||||
"beacon/pkg/dao/mysql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"go.uber.org/zap"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type CompositeCaseService struct {
|
||||
}
|
||||
|
||||
// CreateCompositeCase 创建复合案例
|
||||
func (s *CompositeCaseService) CreateCompositeCase(req *models.CreateCompositeCaseRequest) (*models.CompositeCase, error) {
|
||||
zap.L().Info("CreateCompositeCase")
|
||||
// 开启事务
|
||||
tx := dao.DB.Begin()
|
||||
if tx.Error != nil {
|
||||
return nil, tx.Error
|
||||
}
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
// 创建复合案例
|
||||
compositeCase := &models.CompositeCase{
|
||||
Name: req.Name,
|
||||
Description: req.Description,
|
||||
Status: req.Status,
|
||||
}
|
||||
|
||||
if compositeCase.Status == "" {
|
||||
compositeCase.Status = "active"
|
||||
}
|
||||
|
||||
if err := tx.Create(compositeCase).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return nil, fmt.Errorf("创建复合案例失败: %w", err)
|
||||
}
|
||||
|
||||
// 创建步骤
|
||||
if len(req.Steps) > 0 {
|
||||
var steps []models.CompositeCaseStep
|
||||
for _, stepReq := range req.Steps {
|
||||
step := models.CompositeCaseStep{
|
||||
CompositeCaseID: compositeCase.ID,
|
||||
StepOrder: stepReq.StepOrder,
|
||||
StepName: stepReq.StepName,
|
||||
StepDescription: stepReq.StepDescription,
|
||||
StepType: stepReq.StepType,
|
||||
StepConfig: stepReq.StepConfig,
|
||||
IsRequired: stepReq.IsRequired,
|
||||
}
|
||||
steps = append(steps, step)
|
||||
}
|
||||
|
||||
if err := tx.Create(&steps).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return nil, fmt.Errorf("创建复合案例步骤失败: %w", err)
|
||||
}
|
||||
|
||||
compositeCase.Steps = steps
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
return compositeCase, nil
|
||||
}
|
||||
|
||||
// GetCompositeCaseByID 根据ID获取复合案例
|
||||
func (s *CompositeCaseService) GetCompositeCaseByID(id uint) (*models.CompositeCase, error) {
|
||||
var compositeCase models.CompositeCase
|
||||
|
||||
err := dao.DB.Preload("Steps", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Order("step_order ASC")
|
||||
}).First(&compositeCase, id).Error
|
||||
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, fmt.Errorf("复合案例不存在")
|
||||
}
|
||||
return nil, fmt.Errorf("获取复合案例失败: %w", err)
|
||||
}
|
||||
|
||||
return &compositeCase, nil
|
||||
}
|
||||
|
||||
// UpdateCompositeCase 更新复合案例
|
||||
func (s *CompositeCaseService) UpdateCompositeCase(id uint, req *models.UpdateCompositeCaseRequest) (*models.CompositeCase, error) {
|
||||
// 开启事务
|
||||
tx := dao.DB.Begin()
|
||||
if tx.Error != nil {
|
||||
return nil, tx.Error
|
||||
}
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
// 检查复合案例是否存在
|
||||
var compositeCase models.CompositeCase
|
||||
if err := tx.First(&compositeCase, id).Error; err != nil {
|
||||
tx.Rollback()
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, fmt.Errorf("复合案例不存在")
|
||||
}
|
||||
return nil, fmt.Errorf("查询复合案例失败: %w", err)
|
||||
}
|
||||
|
||||
// 更新基本信息
|
||||
updates := make(map[string]interface{})
|
||||
if req.Name != "" {
|
||||
updates["name"] = req.Name
|
||||
}
|
||||
if req.Description != "" {
|
||||
updates["description"] = req.Description
|
||||
}
|
||||
if req.Status != "" {
|
||||
updates["status"] = req.Status
|
||||
}
|
||||
|
||||
if len(updates) > 0 {
|
||||
if err := tx.Model(&compositeCase).Updates(updates).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return nil, fmt.Errorf("更新复合案例失败: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
// 更新步骤
|
||||
if req.Steps != nil {
|
||||
// 删除现有步骤
|
||||
if err := tx.Where("composite_case_id = ?", id).Delete(&models.CompositeCaseStep{}).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return nil, fmt.Errorf("删除现有步骤失败: %w", err)
|
||||
}
|
||||
|
||||
// 创建新步骤
|
||||
if len(req.Steps) > 0 {
|
||||
var steps []models.CompositeCaseStep
|
||||
for _, stepReq := range req.Steps {
|
||||
step := models.CompositeCaseStep{
|
||||
CompositeCaseID: id,
|
||||
StepOrder: stepReq.StepOrder,
|
||||
StepName: stepReq.StepName,
|
||||
StepDescription: stepReq.StepDescription,
|
||||
StepType: stepReq.StepType,
|
||||
StepConfig: stepReq.StepConfig,
|
||||
IsRequired: stepReq.IsRequired,
|
||||
}
|
||||
steps = append(steps, step)
|
||||
}
|
||||
|
||||
if err := tx.Create(&steps).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return nil, fmt.Errorf("创建新步骤失败: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
|
||||
// 重新查询并返回更新后的数据
|
||||
return s.GetCompositeCaseByID(id)
|
||||
}
|
||||
|
||||
// DeleteCompositeCase 删除复合案例
|
||||
func (s *CompositeCaseService) DeleteCompositeCase(id uint) error {
|
||||
// 开启事务
|
||||
tx := dao.DB.Begin()
|
||||
if tx.Error != nil {
|
||||
return tx.Error
|
||||
}
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
// 检查复合案例是否存在
|
||||
var compositeCase models.CompositeCase
|
||||
if err := tx.First(&compositeCase, id).Error; err != nil {
|
||||
tx.Rollback()
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return fmt.Errorf("复合案例不存在")
|
||||
}
|
||||
return fmt.Errorf("查询复合案例失败: %w", err)
|
||||
}
|
||||
|
||||
// 删除关联的步骤
|
||||
if err := tx.Where("composite_case_id = ?", id).Delete(&models.CompositeCaseStep{}).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return fmt.Errorf("删除复合案例步骤失败: %w", err)
|
||||
}
|
||||
|
||||
// 删除复合案例
|
||||
if err := tx.Delete(&compositeCase).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return fmt.Errorf("删除复合案例失败: %w", err)
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListCompositeCases 获取复合案例列表
|
||||
func (s *CompositeCaseService) ListCompositeCases(page, pageSize int, status string) ([]models.CompositeCase, int64, error) {
|
||||
var compositeCases []models.CompositeCase
|
||||
var total int64
|
||||
|
||||
query := dao.DB.Model(&models.CompositeCase{})
|
||||
|
||||
if status != "" {
|
||||
query = query.Where("status = ?", status)
|
||||
}
|
||||
|
||||
// 获取总数
|
||||
if err := query.Count(&total).Error; err != nil {
|
||||
return nil, 0, fmt.Errorf("获取复合案例总数失败: %w", err)
|
||||
}
|
||||
|
||||
// 分页查询
|
||||
offset := (page - 1) * pageSize
|
||||
err := query.Preload("Steps", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Order("step_order ASC")
|
||||
}).Offset(offset).Limit(pageSize).Order("created_at DESC").Find(&compositeCases).Error
|
||||
|
||||
if err != nil {
|
||||
return nil, 0, fmt.Errorf("获取复合案例列表失败: %w", err)
|
||||
}
|
||||
|
||||
return compositeCases, total, nil
|
||||
}
|
31
utils/file.go
Normal file
31
utils/file.go
Normal file
@ -0,0 +1,31 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go.uber.org/zap"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
)
|
||||
|
||||
func FileStreamToBytes(file *multipart.FileHeader) []byte {
|
||||
// 打开文件
|
||||
f, err := file.Open()
|
||||
if err != nil {
|
||||
zap.L().Info(fmt.Sprintf("无法打开文件: %s", err.Error()))
|
||||
return nil
|
||||
}
|
||||
defer func(file multipart.File) {
|
||||
err := file.Close()
|
||||
if err != nil {
|
||||
zap.L().Warn(fmt.Sprintf("警告文件未正常关闭:%s", err.Error()))
|
||||
}
|
||||
}(f)
|
||||
|
||||
// 读取文件的所有内容
|
||||
fileBytes, err := io.ReadAll(f)
|
||||
if err != nil {
|
||||
zap.L().Info(fmt.Sprintf("无法读取文件内容: %s", err.Error()))
|
||||
return nil
|
||||
}
|
||||
return fileBytes
|
||||
}
|
13
utils/router.go
Executable file
13
utils/router.go
Executable file
@ -0,0 +1,13 @@
|
||||
package utils
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
func RouterRegister(group *gin.RouterGroup, requestMethods []string, relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes {
|
||||
/* 路由注册:一次性给同一个视图方法绑定多种请求方式 */
|
||||
/* 可通switch来分发不同的请求 */
|
||||
var routers gin.IRoutes
|
||||
for _, requestMethod := range requestMethods {
|
||||
routers = group.Handle(requestMethod, relativePath, handlers...)
|
||||
}
|
||||
return routers
|
||||
}
|
Loading…
Reference in New Issue
Block a user