初始化版本
This commit is contained in:
parent
0e8a31c511
commit
1bedc6546b
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# 默认忽略的文件
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# 基于编辑器的 HTTP 客户端请求
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
9
.idea/mircro-bundle.iml
Normal file
9
.idea/mircro-bundle.iml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="WEB_MODULE" version="4">
|
||||||
|
<component name="Go" enabled="true" />
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/mircro-bundle.iml" filepath="$PROJECT_DIR$/.idea/mircro-bundle.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,7 @@
|
|||||||
|
### protot文件编译指令
|
||||||
|
|
||||||
|
```shell
|
||||||
|
protoc --proto_path=. --proto_path=D:/go_workspace/src --go_out=./pb --govalidators_out=./pb --go-triple_out=./pb ./pb/bundle.proto
|
||||||
|
|
||||||
|
protoc --proto_path=. --go-grpc_out=./pb --proto_path=D:/go_workspace/src --go_out=./pb --govalidators_out=./pb --go-triple_out=./pb ./pb/bundle.proto
|
||||||
|
```
|
3
build/.gitignore
vendored
Normal file
3
build/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
||||||
|
!.gitkeep
|
0
build/.gitkeep
Normal file
0
build/.gitkeep
Normal file
50
cmd/app.go
Normal file
50
cmd/app.go
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"dubbo.apache.org/dubbo-go/v3/config"
|
||||||
|
_ "dubbo.apache.org/dubbo-go/v3/filter/tps/strategy"
|
||||||
|
_ "dubbo.apache.org/dubbo-go/v3/imports"
|
||||||
|
"github.com/bwmarrin/snowflake"
|
||||||
|
"go.uber.org/zap"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
bundleConfig "micro-bundle/config"
|
||||||
|
"micro-bundle/internal/controller"
|
||||||
|
_ "micro-bundle/internal/handler"
|
||||||
|
"micro-bundle/pkg/app"
|
||||||
|
"micro-bundle/pkg/tracing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewApp(Lg *zap.Logger, JaegerTracer *tracing.JaegerProvider, SfNode *snowflake.Node, BundleDB *gorm.DB) *app.App {
|
||||||
|
return &app.App{
|
||||||
|
Lg: Lg,
|
||||||
|
JaegerTracer: JaegerTracer,
|
||||||
|
SfNode: SfNode,
|
||||||
|
BundleDB: BundleDB,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var err error
|
||||||
|
bundleConfig.GetOptions()
|
||||||
|
app.ModuleClients, err = InitApp()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
//l, err := net.Listen("tcp", ":8883")
|
||||||
|
//if err != nil {
|
||||||
|
// fmt.Printf("failed to listen: %v", err)
|
||||||
|
// return
|
||||||
|
//}
|
||||||
|
|
||||||
|
//s := grpc.NewServer() // 创建gRPC服务器
|
||||||
|
//dci.RegisterDciServer(s, &controller.DciProvider{}) // 在gRPC服务端注册服务
|
||||||
|
// 启动服务
|
||||||
|
//err = s.Serve(l)
|
||||||
|
//注册服务
|
||||||
|
config.SetProviderService(&controller.BundleProvider{})
|
||||||
|
if err = config.Load(); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
select {}
|
||||||
|
}
|
19
cmd/wire.go
Normal file
19
cmd/wire.go
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// go:build wireinject
|
||||||
|
//go:build wireinject
|
||||||
|
// +build wireinject
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/google/wire"
|
||||||
|
"micro-bundle/pkg/app"
|
||||||
|
"micro-bundle/pkg/db"
|
||||||
|
"micro-bundle/pkg/logger"
|
||||||
|
"micro-bundle/pkg/snowf"
|
||||||
|
"micro-bundle/pkg/tracing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func InitApp() (*app.App, error) {
|
||||||
|
wire.Build(logger.Provider, tracing.Provider, snowf.Provider, db.Provider, NewApp)
|
||||||
|
return &app.App{}, nil
|
||||||
|
}
|
26
cmd/wire_gen.go
Normal file
26
cmd/wire_gen.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
// Code generated by Wire. DO NOT EDIT.
|
||||||
|
|
||||||
|
//go:generate go run github.com/google/wire/cmd/wire
|
||||||
|
//go:build !wireinject
|
||||||
|
// +build !wireinject
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"micro-bundle/pkg/app"
|
||||||
|
"micro-bundle/pkg/db"
|
||||||
|
"micro-bundle/pkg/logger"
|
||||||
|
"micro-bundle/pkg/snowf"
|
||||||
|
"micro-bundle/pkg/tracing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Injectors from wire.go:
|
||||||
|
|
||||||
|
func InitApp() (*app.App, error) {
|
||||||
|
zapLogger := logger.ZapInit()
|
||||||
|
jaegerProvider := tracing.NewTracing()
|
||||||
|
node := snowf.NewSf()
|
||||||
|
gormDB := db.NewBundleDB()
|
||||||
|
appApp := NewApp(zapLogger, jaegerProvider, node, gormDB)
|
||||||
|
return appApp, nil
|
||||||
|
}
|
34
conf/dev/config.yaml
Normal file
34
conf/dev/config.yaml
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
system:
|
||||||
|
mode: dev #正式 prod #测试 test #开发 dev
|
||||||
|
config_source: config
|
||||||
|
bundleDB:
|
||||||
|
host: 172.16.100.99
|
||||||
|
port: 9007
|
||||||
|
user: artuser
|
||||||
|
password: C250PflXIWv2SQm8
|
||||||
|
db_name: "fiee_bundle"
|
||||||
|
#aliYunRtc:
|
||||||
|
# appid: "aeztom27"
|
||||||
|
# app_key: "76c62466cbd77d7a3606660a15861d1e"
|
||||||
|
#redis:
|
||||||
|
# db: 1
|
||||||
|
# addr: 127.0.0.1:6379
|
||||||
|
# password: "7532T6R"
|
||||||
|
zapLog:
|
||||||
|
level: "info"
|
||||||
|
filename: "logs/bundle.log"
|
||||||
|
max_size: 5
|
||||||
|
max_age: 30
|
||||||
|
max_backups: 30
|
||||||
|
snowflake:
|
||||||
|
node_num: 4
|
||||||
|
start_time: "2023-11-27"
|
||||||
|
jaeger:
|
||||||
|
addr: "127.0.0.1:6831"
|
||||||
|
open: false
|
||||||
|
#rabbitmq:
|
||||||
|
# user: "myuser"
|
||||||
|
# password: "mypass"
|
||||||
|
# host: "localhost"
|
||||||
|
# port: 5672
|
||||||
|
# vhost: "oa"
|
68
conf/dev/dubbogo.yaml
Normal file
68
conf/dev/dubbogo.yaml
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
dubbo:
|
||||||
|
metrics:
|
||||||
|
enable: true # default is true
|
||||||
|
path: /metrics # default is /metrics
|
||||||
|
port: 9092 # default is 9090
|
||||||
|
namespace: dubboFiee # default is dubbo 作为数据上报 metrics 的前缀
|
||||||
|
registries:
|
||||||
|
demoZK:
|
||||||
|
protocol: zookeeper
|
||||||
|
timeout: 10s
|
||||||
|
address: 172.16.100.93:2181
|
||||||
|
protocols:
|
||||||
|
triple: #triple
|
||||||
|
name: tri
|
||||||
|
port: 20201
|
||||||
|
provider:
|
||||||
|
filter: tracing
|
||||||
|
services:
|
||||||
|
BundleProvider:
|
||||||
|
interface: com.fontree.microservices.fiee.bundle
|
||||||
|
retries: 0
|
||||||
|
filter: tps,tracing
|
||||||
|
tps.limiter: method-service
|
||||||
|
tps.limit.strategy: fixedWindow
|
||||||
|
tps.limit.rejected.handler: DefaultValueHandler
|
||||||
|
tps.limit.interval: 1000 # 间隔时间
|
||||||
|
tps.limit.rate: 30 # 间隔时间内次数
|
||||||
|
warmup: 100 #预热时间
|
||||||
|
logger:
|
||||||
|
zap-config:
|
||||||
|
level: info # 日志级别
|
||||||
|
development: false
|
||||||
|
disableCaller: false
|
||||||
|
disableStacktrace: false
|
||||||
|
encoding: "json"
|
||||||
|
# zap encoder 配置
|
||||||
|
encoderConfig:
|
||||||
|
messageKey: "message"
|
||||||
|
levelKey: "level"
|
||||||
|
timeKey: "time"
|
||||||
|
nameKey: "logger"
|
||||||
|
callerKey: "caller"
|
||||||
|
stacktraceKey: "stacktrace"
|
||||||
|
lineEnding: ""
|
||||||
|
levelEncoder: "capitalColor"
|
||||||
|
timeEncoder: "iso8601"
|
||||||
|
durationEncoder: "seconds"
|
||||||
|
callerEncoder: "short"
|
||||||
|
nameEncoder: ""
|
||||||
|
EncodeTime: zapcore.TimeEncoderOfLayout("2006-01-02 15:04:05.000"),
|
||||||
|
EncodeDuration: zapcore.SecondsDurationEncoder,
|
||||||
|
outputPaths:
|
||||||
|
- "stderr"
|
||||||
|
errorOutputPaths:
|
||||||
|
- "stderr"
|
||||||
|
lumberjack-config:
|
||||||
|
# 写日志的文件名称
|
||||||
|
filename: "runtime/logs/bundle.log"
|
||||||
|
# 每个日志文件长度的最大大小,单位是 MiB。默认 100MiB
|
||||||
|
maxSize: 5
|
||||||
|
# 日志保留的最大天数(只保留最近多少天的日志)
|
||||||
|
maxAge: 30
|
||||||
|
# 只保留最近多少个日志文件,用于控制程序总日志的大小
|
||||||
|
maxBackups: 30
|
||||||
|
# 是否使用本地时间,默认使用 UTC 时间
|
||||||
|
localTime: true
|
||||||
|
# 是否压缩日志文件,压缩方法 gzip
|
||||||
|
compress: false
|
31
conf/prod/config.yaml
Normal file
31
conf/prod/config.yaml
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
system:
|
||||||
|
mode: prod #正式 prod #测试 test #开发 dev
|
||||||
|
# config_source: configmap
|
||||||
|
bundleDB:
|
||||||
|
host: 172.16.100.99
|
||||||
|
port: 9007
|
||||||
|
user: artuser
|
||||||
|
password: C250PflXIWv2SQm8
|
||||||
|
db_name: "fontree_bundle"
|
||||||
|
#redis:
|
||||||
|
# db: ${oa-meeting.redis.db}
|
||||||
|
# addr: ${redis.addr}
|
||||||
|
# password: ${redis.password}
|
||||||
|
zapLog:
|
||||||
|
level: "info"
|
||||||
|
filename: "logs/bundle.log"
|
||||||
|
max_size: 5
|
||||||
|
max_age: 30
|
||||||
|
max_backups: 30
|
||||||
|
snowflake:
|
||||||
|
node_num: 4
|
||||||
|
start_time: "2023-11-27"
|
||||||
|
jaeger:
|
||||||
|
addr: "127.0.0.1:6831"
|
||||||
|
open: false
|
||||||
|
#rabbitmq:
|
||||||
|
# user: ${rabbitmq.user}
|
||||||
|
# password: ${rabbitmq.password}
|
||||||
|
# host: ${rabbitmq.host}
|
||||||
|
# port: ${rabbitmq.port}
|
||||||
|
# vhost: ${oa-meeting.rabbitmq.vhost}
|
68
conf/prod/dubbogo.yaml
Normal file
68
conf/prod/dubbogo.yaml
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
dubbo:
|
||||||
|
metrics:
|
||||||
|
enable: true # default is true
|
||||||
|
path: /metrics # default is /metrics
|
||||||
|
port: 9092 # default is 9090
|
||||||
|
namespace: dubboFiee # default is dubbo 作为数据上报 metrics 的前缀
|
||||||
|
registries:
|
||||||
|
demoZK:
|
||||||
|
protocol: zookeeper
|
||||||
|
timeout: 10s
|
||||||
|
address: zookeeper:2181
|
||||||
|
protocols:
|
||||||
|
triple: #triple
|
||||||
|
name: tri
|
||||||
|
port: 20201
|
||||||
|
provider:
|
||||||
|
filter: tracing
|
||||||
|
services:
|
||||||
|
BundleProvider:
|
||||||
|
interface: com.fontree.microservices.fiee.bundle
|
||||||
|
retries: 0
|
||||||
|
filter: tps,tracing
|
||||||
|
tps.limiter: method-service
|
||||||
|
tps.limit.strategy: fixedWindow
|
||||||
|
tps.limit.rejected.handler: DefaultValueHandler
|
||||||
|
tps.limit.interval: 1000 # 间隔时间
|
||||||
|
tps.limit.rate: 300 # 间隔时间内次数
|
||||||
|
warmup: 100 #预热时间
|
||||||
|
logger:
|
||||||
|
zap-config:
|
||||||
|
level: info # 日志级别
|
||||||
|
development: false
|
||||||
|
disableCaller: false
|
||||||
|
disableStacktrace: false
|
||||||
|
encoding: "json"
|
||||||
|
# zap encoder 配置
|
||||||
|
encoderConfig:
|
||||||
|
messageKey: "message"
|
||||||
|
levelKey: "level"
|
||||||
|
timeKey: "time"
|
||||||
|
nameKey: "logger"
|
||||||
|
callerKey: "caller"
|
||||||
|
stacktraceKey: "stacktrace"
|
||||||
|
lineEnding: ""
|
||||||
|
levelEncoder: "capitalColor"
|
||||||
|
timeEncoder: "iso8601"
|
||||||
|
durationEncoder: "seconds"
|
||||||
|
callerEncoder: "short"
|
||||||
|
nameEncoder: ""
|
||||||
|
EncodeTime: zapcore.TimeEncoderOfLayout("2006-01-02 15:04:05.000"),
|
||||||
|
EncodeDuration: zapcore.SecondsDurationEncoder,
|
||||||
|
outputPaths:
|
||||||
|
- "stderr"
|
||||||
|
errorOutputPaths:
|
||||||
|
- "stderr"
|
||||||
|
lumberjack-config:
|
||||||
|
# 写日志的文件名称
|
||||||
|
filename: "runtime/logs/bundle.log"
|
||||||
|
# 每个日志文件长度的最大大小,单位是 MiB。默认 100MiB
|
||||||
|
maxSize: 5
|
||||||
|
# 日志保留的最大天数(只保留最近多少天的日志)
|
||||||
|
maxAge: 30
|
||||||
|
# 只保留最近多少个日志文件,用于控制程序总日志的大小
|
||||||
|
maxBackups: 30
|
||||||
|
# 是否使用本地时间,默认使用 UTC 时间
|
||||||
|
localTime: true
|
||||||
|
# 是否压缩日志文件,压缩方法 gzip
|
||||||
|
compress: false
|
154
config/config.go
Normal file
154
config/config.go
Normal file
@ -0,0 +1,154 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"reflect"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"dubbo.apache.org/dubbo-go/v3/common/constant"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
|
"micro-bundle/pkg/msg"
|
||||||
|
)
|
||||||
|
|
||||||
|
var Data = new(AppConfig)
|
||||||
|
|
||||||
|
type AppConfig struct {
|
||||||
|
System struct {
|
||||||
|
Mode string
|
||||||
|
ConfigSource string `mapstructure:"config_source"`
|
||||||
|
}
|
||||||
|
BundleDB struct {
|
||||||
|
Host string
|
||||||
|
Port string
|
||||||
|
User string
|
||||||
|
Password string
|
||||||
|
DbName string `mapstructure:"db_name"`
|
||||||
|
}
|
||||||
|
Redis struct {
|
||||||
|
DB string
|
||||||
|
Addr string
|
||||||
|
Password string
|
||||||
|
}
|
||||||
|
ZapLog struct {
|
||||||
|
Level string `mapstructure:"level"`
|
||||||
|
Filename string `mapstructure:"filename"`
|
||||||
|
MaxSize string `mapstructure:"max_size"`
|
||||||
|
MaxAge string `mapstructure:"max_age"`
|
||||||
|
MaxBackups string `mapstructure:"max_backups"`
|
||||||
|
}
|
||||||
|
SnowFlake struct {
|
||||||
|
NodeNum string `mapstructure:"node_num"`
|
||||||
|
StartTime string `mapstructure:"start_time"`
|
||||||
|
}
|
||||||
|
Jaeger struct {
|
||||||
|
Addr string `mapstructure:"host"`
|
||||||
|
Open string `mapstructure:"open"`
|
||||||
|
}
|
||||||
|
RabbitMq struct {
|
||||||
|
User string `mapstructure:"user"`
|
||||||
|
Password string `mapstructure:"password"`
|
||||||
|
Host string `mapstructure:"host"`
|
||||||
|
Port string `mapstructure:"port"`
|
||||||
|
Vhost string `mapstructure:"vhost"`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetConf() (iniConf string, err error) {
|
||||||
|
if os.Getenv(msg.MODE_ENV) != "" {
|
||||||
|
if err = os.Setenv(constant.ConfigFileEnvKey, fmt.Sprintf("./conf/%s/%s", os.Getenv(msg.MODE_ENV), msg.SERVER_DUBBOGO_CONFIG)); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if os.Getenv(msg.MODE_ENV) == "" {
|
||||||
|
iniConf = fmt.Sprintf("../conf/%s", msg.SERVER_CONFIG)
|
||||||
|
} else {
|
||||||
|
iniConf = fmt.Sprintf("./conf/%s/%s", os.Getenv(msg.MODE_ENV), msg.SERVER_CONFIG)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetOptions() {
|
||||||
|
iniConf, err := GetConf()
|
||||||
|
if err != nil {
|
||||||
|
panic("GetOptions err" + err.Error())
|
||||||
|
}
|
||||||
|
if err = Viper(iniConf); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Viper(iniConf string) (err error) {
|
||||||
|
viper.SetConfigFile(iniConf)
|
||||||
|
err = viper.ReadInConfig()
|
||||||
|
if err != nil {
|
||||||
|
panic("viper.ReadInConfig failed" + err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = viper.Unmarshal(Data); err != nil {
|
||||||
|
panic("viper.Unmarshal failed" + err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 如果是configmap模式再修改
|
||||||
|
fmt.Println(Data.System)
|
||||||
|
if Data.System.ConfigSource == "configmap" {
|
||||||
|
traverseFields(reflect.ValueOf(*Data), "", Data)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func traverseFields(value reflect.Value, prefix string, configPtr interface{}) {
|
||||||
|
valueType := value.Type()
|
||||||
|
prefixEnv := "${"
|
||||||
|
suffixEnv := "}"
|
||||||
|
// 遍历结构体的字段
|
||||||
|
for i := 0; i < valueType.NumField(); i++ {
|
||||||
|
field := valueType.Field(i)
|
||||||
|
fieldValue := value.Field(i)
|
||||||
|
// 拼接字段名(带有前缀)
|
||||||
|
fieldName := prefix + field.Name
|
||||||
|
// 判断字段的类型
|
||||||
|
if fieldValue.Kind() == reflect.Struct {
|
||||||
|
// 递归遍历嵌套结构体字段
|
||||||
|
traverseFields(fieldValue, fieldName+".", configPtr)
|
||||||
|
} else {
|
||||||
|
// 获取字段的值
|
||||||
|
fieldValueStr := fmt.Sprintf("%v", fieldValue.Interface())
|
||||||
|
// 判断是不是需要通过环境变量获取
|
||||||
|
if len(fieldValueStr) > 3 && strings.HasPrefix(fieldValueStr, prefixEnv) && strings.HasSuffix(fieldValueStr, suffixEnv) {
|
||||||
|
end := len(fieldValueStr) - len(suffixEnv)
|
||||||
|
var hasDefault bool
|
||||||
|
if strings.Index(fieldValueStr, "|") > 0 {
|
||||||
|
hasDefault = true
|
||||||
|
end = strings.Index(fieldValueStr, "|")
|
||||||
|
}
|
||||||
|
envStr := fieldValueStr[len(prefixEnv):end]
|
||||||
|
getValue := os.Getenv(envStr)
|
||||||
|
if getValue == "" && hasDefault {
|
||||||
|
getValue = fieldValueStr[end+1 : len(fieldValueStr)-len(suffixEnv)]
|
||||||
|
}
|
||||||
|
setSubFieldValue(configPtr, fieldName, getValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func setSubFieldValue(configPtr interface{}, fieldPath string, newValue interface{}) {
|
||||||
|
value := reflect.ValueOf(configPtr).Elem()
|
||||||
|
fields := strings.Split(fieldPath, ".")
|
||||||
|
for _, field := range fields {
|
||||||
|
value = value.FieldByName(field)
|
||||||
|
if !value.IsValid() {
|
||||||
|
return // 字段不存在,直接返回
|
||||||
|
}
|
||||||
|
if value.Kind() == reflect.Ptr {
|
||||||
|
value = value.Elem() // 解引用指针类型的字段
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 检查字段是否可设置
|
||||||
|
if value.CanSet() {
|
||||||
|
// 根据字段类型,将新值转换为对应类型并设置字段的值
|
||||||
|
newValue := reflect.ValueOf(newValue).Convert(value.Type())
|
||||||
|
value.Set(newValue)
|
||||||
|
}
|
||||||
|
}
|
58
deploy/k8s/test/deployment-dci.yaml
Normal file
58
deploy/k8s/test/deployment-dci.yaml
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: chain-dci-server
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: chain-dci-server
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: chain-dci-server
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: chain-dci-server
|
||||||
|
image: testhub.szjixun.cn:9043/k8stest/chain-dci-server:latest
|
||||||
|
ports:
|
||||||
|
- containerPort: 20201
|
||||||
|
volumeMounts:
|
||||||
|
- name: logs
|
||||||
|
mountPath: /app/logs
|
||||||
|
- name: runtime
|
||||||
|
mountPath: /app/runtime
|
||||||
|
envFrom:
|
||||||
|
- configMapRef:
|
||||||
|
name: "erp-configmap"
|
||||||
|
- secretRef:
|
||||||
|
name: erp-secret
|
||||||
|
# nodeSelector:
|
||||||
|
# node: node1
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: docker-login-secret
|
||||||
|
volumes:
|
||||||
|
- name: logs
|
||||||
|
nfs:
|
||||||
|
server: node0
|
||||||
|
path: /mnt/storage/erp/chain-dci-server/logs
|
||||||
|
- name: runtime
|
||||||
|
nfs:
|
||||||
|
server: node0
|
||||||
|
path: /mnt/storage/erp/chain-dci-server/runtime
|
||||||
|
---
|
||||||
|
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: chain-dci-server
|
||||||
|
spec:
|
||||||
|
type: NodePort
|
||||||
|
selector:
|
||||||
|
app: chain-dci-server
|
||||||
|
ports:
|
||||||
|
- name: http
|
||||||
|
protocol: TCP
|
||||||
|
nodePort: 20201
|
||||||
|
targetPort: 20201
|
||||||
|
port: 20201
|
164
go.mod
Normal file
164
go.mod
Normal file
@ -0,0 +1,164 @@
|
|||||||
|
module micro-bundle
|
||||||
|
|
||||||
|
go 1.20
|
||||||
|
|
||||||
|
require (
|
||||||
|
dubbo.apache.org/dubbo-go/v3 v3.1.1
|
||||||
|
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1704
|
||||||
|
github.com/bwmarrin/snowflake v0.3.0
|
||||||
|
github.com/dubbogo/grpc-go v1.42.10
|
||||||
|
github.com/dubbogo/triple v1.2.2-rc3
|
||||||
|
github.com/getsentry/sentry-go v0.31.1
|
||||||
|
github.com/gin-gonic/gin v1.10.0
|
||||||
|
github.com/go-redis/redis v6.15.9+incompatible
|
||||||
|
github.com/golang/protobuf v1.5.4
|
||||||
|
github.com/google/wire v0.6.0
|
||||||
|
github.com/mwitkow/go-proto-validators v0.3.2
|
||||||
|
github.com/natefinch/lumberjack v2.0.0+incompatible
|
||||||
|
github.com/opentracing/opentracing-go v1.2.0
|
||||||
|
github.com/spf13/viper v1.19.0
|
||||||
|
github.com/streadway/amqp v1.1.0
|
||||||
|
github.com/uber/jaeger-client-go v2.30.0+incompatible
|
||||||
|
go.uber.org/zap v1.27.0
|
||||||
|
google.golang.org/protobuf v1.36.5
|
||||||
|
gorm.io/driver/mysql v1.5.7
|
||||||
|
gorm.io/gorm v1.25.12
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
cloud.google.com/go/compute v1.24.0 // indirect
|
||||||
|
cloud.google.com/go/compute/metadata v0.2.3 // indirect
|
||||||
|
github.com/RoaringBitmap/roaring v1.2.3 // indirect
|
||||||
|
github.com/Workiva/go-datastructures v1.0.52 // indirect
|
||||||
|
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5 // indirect
|
||||||
|
github.com/alibaba/sentinel-golang v1.0.4 // indirect
|
||||||
|
github.com/apache/dubbo-getty v1.4.9 // indirect
|
||||||
|
github.com/apache/dubbo-go-hessian2 v1.12.2 // indirect
|
||||||
|
github.com/beorn7/perks v1.0.1 // indirect
|
||||||
|
github.com/bits-and-blooms/bitset v1.2.0 // indirect
|
||||||
|
github.com/buger/jsonparser v1.1.1 // indirect
|
||||||
|
github.com/bytedance/sonic v1.11.6 // indirect
|
||||||
|
github.com/bytedance/sonic/loader v0.1.1 // indirect
|
||||||
|
github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect
|
||||||
|
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
||||||
|
github.com/cloudwego/base64x v0.1.4 // indirect
|
||||||
|
github.com/cloudwego/iasm v0.2.0 // indirect
|
||||||
|
github.com/cncf/udpa/go v0.0.0-20220112060539-c52dc94e7fbe // indirect
|
||||||
|
github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa // indirect
|
||||||
|
github.com/coreos/go-semver v0.3.0 // indirect
|
||||||
|
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
|
||||||
|
github.com/creasty/defaults v1.5.2 // indirect
|
||||||
|
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||||
|
github.com/dlclark/regexp2 v1.7.0 // indirect
|
||||||
|
github.com/dubbogo/go-zookeeper v1.0.4-0.20211212162352-f9d2183d89d5 // indirect
|
||||||
|
github.com/dubbogo/gost v1.14.0 // indirect
|
||||||
|
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||||
|
github.com/emicklei/go-restful/v3 v3.10.1 // indirect
|
||||||
|
github.com/envoyproxy/go-control-plane v0.12.0 // indirect
|
||||||
|
github.com/envoyproxy/protoc-gen-validate v1.0.4 // indirect
|
||||||
|
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||||
|
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||||
|
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||||
|
github.com/go-co-op/gocron v1.9.0 // indirect
|
||||||
|
github.com/go-logr/logr v1.4.1 // indirect
|
||||||
|
github.com/go-logr/stdr v1.2.2 // indirect
|
||||||
|
github.com/go-ole/go-ole v1.2.6 // 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.20.0 // indirect
|
||||||
|
github.com/go-resty/resty/v2 v2.7.0 // indirect
|
||||||
|
github.com/go-sql-driver/mysql v1.7.0 // indirect
|
||||||
|
github.com/goccy/go-json v0.10.2 // indirect
|
||||||
|
github.com/gogo/protobuf v1.3.2 // indirect
|
||||||
|
github.com/golang/mock v1.6.0 // indirect
|
||||||
|
github.com/golang/snappy v0.0.4 // indirect
|
||||||
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
|
github.com/gorilla/websocket v1.4.2 // indirect
|
||||||
|
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645 // indirect
|
||||||
|
github.com/hashicorp/errwrap v1.1.0 // indirect
|
||||||
|
github.com/hashicorp/go-multierror v1.1.1 // indirect
|
||||||
|
github.com/hashicorp/golang-lru v0.5.4 // indirect
|
||||||
|
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||||
|
github.com/hashicorp/vault/sdk v0.7.0 // indirect
|
||||||
|
github.com/influxdata/tdigest v0.0.1 // indirect
|
||||||
|
github.com/jinzhu/copier v0.3.5 // indirect
|
||||||
|
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||||
|
github.com/jinzhu/now v1.1.5 // indirect
|
||||||
|
github.com/jmespath/go-jmespath v0.4.0 // indirect
|
||||||
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
|
github.com/k0kubun/pp v3.0.1+incompatible // indirect
|
||||||
|
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
|
||||||
|
github.com/knadh/koanf v1.5.0 // indirect
|
||||||
|
github.com/leodido/go-urn v1.4.0 // indirect
|
||||||
|
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
|
||||||
|
github.com/magiconair/properties v1.8.7 // indirect
|
||||||
|
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||||
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
|
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
|
||||||
|
github.com/mitchellh/copystructure v1.2.0 // indirect
|
||||||
|
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
||||||
|
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||||
|
github.com/mitchellh/reflectwalk v1.0.2 // indirect
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
|
github.com/mschoch/smat v0.2.0 // indirect
|
||||||
|
github.com/nacos-group/nacos-sdk-go/v2 v2.2.2 // indirect
|
||||||
|
github.com/oliveagle/jsonpath v0.0.0-20180606110733-2e52cf6e6852 // indirect
|
||||||
|
github.com/openzipkin/zipkin-go v0.4.0 // indirect
|
||||||
|
github.com/pelletier/go-toml v1.9.3 // indirect
|
||||||
|
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
|
||||||
|
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
|
||||||
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
|
github.com/polarismesh/polaris-go v1.3.0 // indirect
|
||||||
|
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
|
||||||
|
github.com/prometheus/client_golang v1.13.0 // indirect
|
||||||
|
github.com/prometheus/client_model v0.5.0 // indirect
|
||||||
|
github.com/prometheus/common v0.37.0 // indirect
|
||||||
|
github.com/prometheus/procfs v0.8.0 // indirect
|
||||||
|
github.com/robfig/cron/v3 v3.0.1 // indirect
|
||||||
|
github.com/sagikazarmark/locafero v0.4.0 // indirect
|
||||||
|
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
|
||||||
|
github.com/shirou/gopsutil/v3 v3.22.2 // indirect
|
||||||
|
github.com/sourcegraph/conc v0.3.0 // indirect
|
||||||
|
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
||||||
|
github.com/spf13/afero v1.11.0 // indirect
|
||||||
|
github.com/spf13/cast v1.6.0 // indirect
|
||||||
|
github.com/spf13/pflag v1.0.5 // indirect
|
||||||
|
github.com/subosito/gotenv v1.6.0 // indirect
|
||||||
|
github.com/tklauser/go-sysconf v0.3.10 // indirect
|
||||||
|
github.com/tklauser/numcpus v0.4.0 // indirect
|
||||||
|
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||||
|
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
|
||||||
|
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||||
|
github.com/yusufpapurcu/wmi v1.2.2 // indirect
|
||||||
|
go.etcd.io/etcd/api/v3 v3.5.12 // indirect
|
||||||
|
go.etcd.io/etcd/client/pkg/v3 v3.5.12 // indirect
|
||||||
|
go.etcd.io/etcd/client/v3 v3.5.12 // indirect
|
||||||
|
go.opentelemetry.io/contrib/propagators/b3 v1.10.0 // indirect
|
||||||
|
go.opentelemetry.io/otel v1.24.0 // indirect
|
||||||
|
go.opentelemetry.io/otel/exporters/jaeger v1.10.0 // indirect
|
||||||
|
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.10.0 // indirect
|
||||||
|
go.opentelemetry.io/otel/exporters/zipkin v1.10.0 // indirect
|
||||||
|
go.opentelemetry.io/otel/metric v1.24.0 // indirect
|
||||||
|
go.opentelemetry.io/otel/sdk v1.21.0 // indirect
|
||||||
|
go.opentelemetry.io/otel/trace v1.24.0 // indirect
|
||||||
|
go.uber.org/atomic v1.10.0 // indirect
|
||||||
|
go.uber.org/multierr v1.10.0 // indirect
|
||||||
|
golang.org/x/arch v0.8.0 // indirect
|
||||||
|
golang.org/x/crypto v0.23.0 // indirect
|
||||||
|
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
|
||||||
|
golang.org/x/net v0.25.0 // indirect
|
||||||
|
golang.org/x/oauth2 v0.18.0 // indirect
|
||||||
|
golang.org/x/sync v0.6.0 // indirect
|
||||||
|
golang.org/x/sys v0.20.0 // indirect
|
||||||
|
golang.org/x/text v0.15.0 // indirect
|
||||||
|
golang.org/x/time v0.5.0 // indirect
|
||||||
|
google.golang.org/appengine v1.6.8 // indirect
|
||||||
|
google.golang.org/genproto/googleapis/api v0.0.0-20240311132316-a219d84964c2 // indirect
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c // indirect
|
||||||
|
google.golang.org/grpc v1.62.1 // indirect
|
||||||
|
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||||
|
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||||
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
|
)
|
49
internal/controller/bundle.go
Normal file
49
internal/controller/bundle.go
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"micro-bundle/internal/logic"
|
||||||
|
"micro-bundle/pb/bundle"
|
||||||
|
)
|
||||||
|
|
||||||
|
type BundleProvider struct {
|
||||||
|
bundle.UnimplementedBundleServer
|
||||||
|
}
|
||||||
|
|
||||||
|
// 套餐相关
|
||||||
|
func (b *BundleProvider) CreateBundle(_ context.Context, req *bundle.BundleProfile) (res *bundle.CommonResponse, err error) {
|
||||||
|
return logic.CreateBundle(req)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *BundleProvider) UpdateBundle(_ context.Context, req *bundle.BundleProfile) (res *bundle.CommonResponse, err error) {
|
||||||
|
return logic.UpdateBundle(req)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *BundleProvider) DeleteBundle(_ context.Context, req *bundle.DelBundleRequest) (res *bundle.CommonResponse, err error) {
|
||||||
|
return logic.DeleteBundle(req)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *BundleProvider) BundleList(_ context.Context, req *bundle.BundleListRequest) (res *bundle.BundleListResponse, err error) {
|
||||||
|
return logic.BundleList(req)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *BundleProvider) BundleDetail(_ context.Context, req *bundle.BundleDetailRequest) (res *bundle.BundleDetailResponse, err error) {
|
||||||
|
return logic.BundleDetail(req)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 订单相关
|
||||||
|
func (b *BundleProvider) CreateOrderRecord(_ context.Context, req *bundle.OrderRecord) (res *bundle.CommonResponse, err error) {
|
||||||
|
return logic.CreateOrderRecord(req)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *BundleProvider) UpdateOrderRecord(_ context.Context, req *bundle.OrderRecord) (res *bundle.CommonResponse, err error) {
|
||||||
|
return logic.UpdateOrderRecord(req)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *BundleProvider) OrderRecordsList(_ context.Context, req *bundle.OrderRecordsRequest) (res *bundle.OrderRecordsResponse, err error) {
|
||||||
|
return logic.OrderRecordsList(req)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *BundleProvider) OrderRecordsDetail(_ context.Context, req *bundle.OrderRecordsDetailRequest) (res *bundle.OrderRecordsDetailResponse, err error) {
|
||||||
|
return logic.OrderRecordsDetail(req)
|
||||||
|
}
|
87
internal/dao/bundleDao.go
Normal file
87
internal/dao/bundleDao.go
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
package dao
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jinzhu/copier"
|
||||||
|
"micro-bundle/internal/model"
|
||||||
|
"micro-bundle/pb/bundle"
|
||||||
|
"micro-bundle/pkg/app"
|
||||||
|
commonErr "micro-bundle/pkg/err"
|
||||||
|
"micro-bundle/pkg/msg"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CreateBundle(bundle *model.BundleProfile) (res *bundle.CommonResponse, err error) {
|
||||||
|
res = new(bundle.CommonResponse)
|
||||||
|
err = app.ModuleClients.BundleDB.Model(&model.BundleProfile{}).Create(&bundle).Error
|
||||||
|
if err != nil {
|
||||||
|
res.Msg = msg.ErrorCreateBundleInfo
|
||||||
|
return res, commonErr.ReturnError(err, msg.ErrorCreateBundleInfo, "创建套餐信息失败: ")
|
||||||
|
}
|
||||||
|
res.Msg = msg.SuccessCreateBundleInfo
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateBundle(bundle *model.BundleProfile) (res *bundle.CommonResponse, err error) {
|
||||||
|
res = new(bundle.CommonResponse)
|
||||||
|
err = app.ModuleClients.BundleDB.Model(&model.BundleProfile{}).Where("uuid = ?", bundle.UUID).Updates(bundle).Error
|
||||||
|
if err != nil {
|
||||||
|
res.Msg = msg.ErrorUpdateBundleInfo
|
||||||
|
return res, commonErr.ReturnError(err, msg.ErrorUpdateBundleInfo, "更新套餐信息失败: ")
|
||||||
|
}
|
||||||
|
res.Msg = msg.SuccessUpdateBundleInfo
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func DeleteBundle(uuid string) (res *bundle.CommonResponse, err error) {
|
||||||
|
res = new(bundle.CommonResponse)
|
||||||
|
err = app.ModuleClients.BundleDB.Where("uuid = ?", uuid).Delete(&model.BundleProfile{}).Error
|
||||||
|
if err != nil {
|
||||||
|
res.Msg = msg.ErrorDeleteBundleInfo
|
||||||
|
return res, commonErr.ReturnError(err, msg.ErrorDeleteBundleInfo, "删除套餐信息失败: ")
|
||||||
|
}
|
||||||
|
res.Msg = msg.SuccessDeleteBundleInfo
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func BundleList(req *bundle.BundleListRequest) (res *bundle.BundleListResponse, err error) {
|
||||||
|
res = new(bundle.BundleListResponse)
|
||||||
|
res.Bundles = make([]*bundle.BundleProfile, 0)
|
||||||
|
bundles := make([]*model.BundleProfile, 0)
|
||||||
|
|
||||||
|
query := app.ModuleClients.BundleDB.Model(&model.BundleProfile{})
|
||||||
|
|
||||||
|
if req.Name != "" {
|
||||||
|
query = query.Where("name like ?", "%"+req.Name+"%")
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.Content != "" {
|
||||||
|
query = query.Where("content like ?", "%"+req.Content+"%")
|
||||||
|
}
|
||||||
|
|
||||||
|
count := *query
|
||||||
|
|
||||||
|
if err = query.Find(&bundles).Error; err != nil {
|
||||||
|
return res, commonErr.ReturnError(err, msg.ErrorGetBundleList, "获取套餐列表失败: ")
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = copier.CopyWithOption(&res.Bundles, &bundles, copier.Option{DeepCopy: true})
|
||||||
|
|
||||||
|
var total int64
|
||||||
|
|
||||||
|
count.Count(&total)
|
||||||
|
|
||||||
|
res.Total = int32(total)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func BundleDetail(uuid string) (res *bundle.BundleProfile, err error) {
|
||||||
|
res = new(bundle.BundleProfile)
|
||||||
|
bundle := new(model.BundleProfile)
|
||||||
|
err = app.ModuleClients.BundleDB.Where("uuid = ?", uuid).First(&bundle).Error
|
||||||
|
if err != nil {
|
||||||
|
return res, commonErr.ReturnError(err, msg.ErrorGetBundleInfo, "获取套餐信息失败: ")
|
||||||
|
}
|
||||||
|
_ = copier.CopyWithOption(&res, &bundle, copier.Option{DeepCopy: true})
|
||||||
|
return
|
||||||
|
}
|
113
internal/dao/orderRecordsDao.go
Normal file
113
internal/dao/orderRecordsDao.go
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
package dao
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jinzhu/copier"
|
||||||
|
"micro-bundle/internal/model"
|
||||||
|
"micro-bundle/pb/bundle"
|
||||||
|
"micro-bundle/pkg/app"
|
||||||
|
commonErr "micro-bundle/pkg/err"
|
||||||
|
"micro-bundle/pkg/msg"
|
||||||
|
"micro-bundle/pkg/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CreateOrderRecord(orderRecord *model.BundleOrderRecords) (res *bundle.CommonResponse, err error) {
|
||||||
|
res = new(bundle.CommonResponse)
|
||||||
|
orderRecord.UUID = app.ModuleClients.SfNode.Generate().Base64()
|
||||||
|
orderRecord.OrderNo = utils.GetOrderNo()
|
||||||
|
err = app.ModuleClients.BundleDB.Model(&model.BundleProfile{}).Create(&orderRecord).Error
|
||||||
|
if err != nil {
|
||||||
|
res.Msg = msg.ErrorCreateOrderInfo
|
||||||
|
return res, commonErr.ReturnError(err, msg.ErrorCreateOrderInfo, "创建订单信息失败: ")
|
||||||
|
}
|
||||||
|
res.Uuid = orderRecord.UUID
|
||||||
|
res.Msg = msg.SuccessCreateOrderInfo
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateOrderRecord(orderRecord *model.BundleOrderRecords) (res *bundle.CommonResponse, err error) {
|
||||||
|
res = new(bundle.CommonResponse)
|
||||||
|
err = app.ModuleClients.BundleDB.Model(&model.BundleProfile{}).Where("uuid = ?", orderRecord.UUID).Updates(orderRecord).Error
|
||||||
|
if err != nil {
|
||||||
|
res.Msg = msg.ErrorUpdateOrderInfo
|
||||||
|
return res, commonErr.ReturnError(err, msg.ErrorUpdateOrderInfo, "更新订单信息失败: ")
|
||||||
|
}
|
||||||
|
res.Uuid = orderRecord.UUID
|
||||||
|
res.Msg = msg.SuccessUpdateOrderInfo
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func OrderRecordsList(req *bundle.OrderRecordsRequest) (res *bundle.OrderRecordsResponse, err error) {
|
||||||
|
res = new(bundle.OrderRecordsResponse)
|
||||||
|
res.OrderRecords = make([]*bundle.OrderRecord, 0)
|
||||||
|
records := make([]*model.BundleOrderRecords, 0)
|
||||||
|
|
||||||
|
query := app.ModuleClients.BundleDB.Model(&model.BundleOrderRecords{})
|
||||||
|
|
||||||
|
if req.CustomerNum != "" {
|
||||||
|
query = query.Where("customer_num like ?", "%"+req.CustomerNum+"%")
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.CustomerName != "" {
|
||||||
|
query = query.Where("customer_name like ?", "%"+req.CustomerName+"%")
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.BundleName != "" {
|
||||||
|
query = query.Where("bundle_name like ?", "%"+req.BundleName+"%")
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.BundleUUID != "" {
|
||||||
|
query = query.Where("bundle_uuid = ?", req.BundleUUID)
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.OrderNo != "" {
|
||||||
|
query = query.Where("order_no like ?", "%"+req.OrderNo+"%")
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.Status != 0 {
|
||||||
|
query = query.Where("status = ?", req.Status)
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.StartSignedTime != "" {
|
||||||
|
query = query.Where("signed_time >= ?", req.StartSignedTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.EndSignedTime != "" {
|
||||||
|
query = query.Where("signed_time <= ?", req.EndSignedTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.StartPayTime != "" {
|
||||||
|
query = query.Where("pay_time >= ?", req.StartPayTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.EndPayTime != "" {
|
||||||
|
query = query.Where("pay_time <= ?", req.EndPayTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
count := *query
|
||||||
|
|
||||||
|
err = query.Limit(int(req.PageSize)).Offset(int(req.Page-1) * int(req.PageSize)).Find(&records).Error
|
||||||
|
if err != nil {
|
||||||
|
return res, commonErr.ReturnError(err, msg.ErrorGetOrderList, "获取订单信息失败: ")
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = copier.CopyWithOption(&res.OrderRecords, &records, copier.Option{DeepCopy: true})
|
||||||
|
|
||||||
|
var total int64
|
||||||
|
|
||||||
|
count.Count(&total)
|
||||||
|
|
||||||
|
res.Total = int32(total)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func OrderRecordDetail(uuid string) (res *bundle.OrderRecord, err error) {
|
||||||
|
res = new(bundle.OrderRecord)
|
||||||
|
orderRecord := new(model.BundleOrderRecords)
|
||||||
|
err = app.ModuleClients.BundleDB.Where("uuid = ?", uuid).First(&orderRecord).Error
|
||||||
|
if err != nil {
|
||||||
|
return res, commonErr.ReturnError(err, msg.ErrorGetOrderInfo, "获取订单信息失败: ")
|
||||||
|
}
|
||||||
|
_ = copier.CopyWithOption(&res, &orderRecord, copier.Option{DeepCopy: true})
|
||||||
|
return
|
||||||
|
}
|
57
internal/handler/default_handler.go
Normal file
57
internal/handler/default_handler.go
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"dubbo.apache.org/dubbo-go/v3/common"
|
||||||
|
"dubbo.apache.org/dubbo-go/v3/common/extension"
|
||||||
|
"dubbo.apache.org/dubbo-go/v3/filter"
|
||||||
|
"dubbo.apache.org/dubbo-go/v3/protocol"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
extension.SetRejectedExecutionHandler("DefaultValueHandler", GetDefaultValueRejectedExecutionHandlerSingleton)
|
||||||
|
}
|
||||||
|
|
||||||
|
type DefaultValueRejectedExecutionHandler struct {
|
||||||
|
defaultResult sync.Map
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mh *DefaultValueRejectedExecutionHandler) RejectedExecution(url *common.URL, invocation protocol.Invocation) protocol.Result {
|
||||||
|
key := url.ServiceKey() + "#" + invocation.MethodName()
|
||||||
|
result, loaded := mh.defaultResult.Load(key)
|
||||||
|
if !loaded {
|
||||||
|
// we didn't configure any default value for this invocation
|
||||||
|
return &protocol.RPCResult{
|
||||||
|
Err: errors.New("请求太频繁"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result.(*protocol.RPCResult)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetCustomRejectedExecutionHandler() filter.RejectedExecutionHandler {
|
||||||
|
return &DefaultValueRejectedExecutionHandler{}
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
customHandlerOnce sync.Once
|
||||||
|
customHandlerInstance *DefaultValueRejectedExecutionHandler
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the better way is designing the RejectedExecutionHandler as singleton.
|
||||||
|
*/
|
||||||
|
func GetDefaultValueRejectedExecutionHandlerSingleton() filter.RejectedExecutionHandler {
|
||||||
|
customHandlerOnce.Do(func() {
|
||||||
|
customHandlerInstance = &DefaultValueRejectedExecutionHandler{}
|
||||||
|
})
|
||||||
|
|
||||||
|
initDefaultValue()
|
||||||
|
|
||||||
|
return customHandlerInstance
|
||||||
|
}
|
||||||
|
|
||||||
|
func initDefaultValue() {
|
||||||
|
// setting your default value
|
||||||
|
}
|
49
internal/logic/bundleLogic.go
Normal file
49
internal/logic/bundleLogic.go
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/utils"
|
||||||
|
"github.com/jinzhu/copier"
|
||||||
|
"micro-bundle/internal/dao"
|
||||||
|
|
||||||
|
"micro-bundle/internal/model"
|
||||||
|
"micro-bundle/pb/bundle"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CreateBundle(req *bundle.BundleProfile) (res *bundle.CommonResponse, err error) {
|
||||||
|
res = new(bundle.CommonResponse)
|
||||||
|
bundleProfile := new(model.BundleProfile)
|
||||||
|
_ = copier.CopyWithOption(&bundleProfile, req, copier.Option{DeepCopy: true})
|
||||||
|
bundleProfile.UUID = utils.GetUUID()
|
||||||
|
res, err = dao.CreateBundle(bundleProfile)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateBundle(req *bundle.BundleProfile) (res *bundle.CommonResponse, err error) {
|
||||||
|
res = new(bundle.CommonResponse)
|
||||||
|
bundleProfile := new(model.BundleProfile)
|
||||||
|
_ = copier.CopyWithOption(&bundleProfile, req, copier.Option{DeepCopy: true})
|
||||||
|
res, err = dao.UpdateBundle(bundleProfile)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func DeleteBundle(req *bundle.DelBundleRequest) (res *bundle.CommonResponse, err error) {
|
||||||
|
res = new(bundle.CommonResponse)
|
||||||
|
res, err = dao.DeleteBundle(req.Uuid)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func BundleList(req *bundle.BundleListRequest) (res *bundle.BundleListResponse, err error) {
|
||||||
|
res = new(bundle.BundleListResponse)
|
||||||
|
res, err = dao.BundleList(req)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func BundleDetail(req *bundle.BundleDetailRequest) (res *bundle.BundleDetailResponse, err error) {
|
||||||
|
res = new(bundle.BundleDetailResponse)
|
||||||
|
res.Bundle = new(bundle.BundleProfile)
|
||||||
|
res.Bundle, err = dao.BundleDetail(req.Uuid)
|
||||||
|
if err != nil {
|
||||||
|
res.Msg = err.Error()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
44
internal/logic/orderRecordsLogic.go
Normal file
44
internal/logic/orderRecordsLogic.go
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jinzhu/copier"
|
||||||
|
"micro-bundle/internal/dao"
|
||||||
|
"micro-bundle/internal/model"
|
||||||
|
"micro-bundle/pb/bundle"
|
||||||
|
"micro-bundle/pkg/app"
|
||||||
|
"micro-bundle/pkg/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CreateOrderRecord(req *bundle.OrderRecord) (res *bundle.CommonResponse, err error) {
|
||||||
|
res = new(bundle.CommonResponse)
|
||||||
|
orderRecord := new(model.BundleOrderRecords)
|
||||||
|
_ = copier.CopyWithOption(&orderRecord, req, copier.Option{DeepCopy: true})
|
||||||
|
orderRecord.UUID = app.ModuleClients.SfNode.Generate().Base64()
|
||||||
|
orderRecord.OrderNo = utils.GetOrderNo()
|
||||||
|
res, err = dao.CreateOrderRecord(orderRecord)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateOrderRecord(req *bundle.OrderRecord) (res *bundle.CommonResponse, err error) {
|
||||||
|
res = new(bundle.CommonResponse)
|
||||||
|
orderRecord := new(model.BundleOrderRecords)
|
||||||
|
_ = copier.CopyWithOption(&orderRecord, req, copier.Option{DeepCopy: true})
|
||||||
|
res, err = dao.UpdateOrderRecord(orderRecord)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func OrderRecordsList(req *bundle.OrderRecordsRequest) (res *bundle.OrderRecordsResponse, err error) {
|
||||||
|
res = new(bundle.OrderRecordsResponse)
|
||||||
|
res, err = dao.OrderRecordsList(req)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func OrderRecordsDetail(req *bundle.OrderRecordsDetailRequest) (res *bundle.OrderRecordsDetailResponse, err error) {
|
||||||
|
res = new(bundle.OrderRecordsDetailResponse)
|
||||||
|
res.OrderRecord = new(bundle.OrderRecord)
|
||||||
|
res.OrderRecord, err = dao.OrderRecordDetail(req.Uuid)
|
||||||
|
if err != nil {
|
||||||
|
res.Msg = err.Error()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
14
internal/model/bundle.go
Normal file
14
internal/model/bundle.go
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import "gorm.io/gorm"
|
||||||
|
|
||||||
|
type BundleProfile struct {
|
||||||
|
gorm.Model
|
||||||
|
UUID string `json:"uuid" gorm:"column:uuid;type:varchar(1024);comment:套餐UUID"`
|
||||||
|
Name string `json:"name" gorm:"column:name;type:varchar(2048);comment:套餐名称"`
|
||||||
|
Price float32 `json:"price" gorm:"column:price;type:decimal(12,2);comment:套餐价格"`
|
||||||
|
PriceType int64 `json:"priceType" gorm:"column:price_type;type:int;comment:套餐价格类型 1:人民币 2:美元"`
|
||||||
|
Contract string `json:"contract" gorm:"type:varchar(1024);comment:合同"`
|
||||||
|
Content string `json:"content" gorm:"column:content;type:text;comment:套餐内容"`
|
||||||
|
Language string `json:"language" gorm:"column:language;type:varchar(32);comment:套餐语言 zh-CN EN"`
|
||||||
|
}
|
25
internal/model/bundle_order_records.go
Normal file
25
internal/model/bundle_order_records.go
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import "gorm.io/gorm"
|
||||||
|
|
||||||
|
// BundleOrderRecords struct
|
||||||
|
type BundleOrderRecords struct {
|
||||||
|
gorm.Model
|
||||||
|
UUID string `json:"uuid" gorm:"column:uuid;type:varchar(1024);comment:UUID"`
|
||||||
|
OrderNo string `json:"orderNo" gorm:"column:order_no;type:varchar(1024);comment:交易编号"`
|
||||||
|
BundleUUID string `json:"bundleUUID" gorm:"column:bundle_uuid;type:varchar(1024);comment:套餐UUID"`
|
||||||
|
BundleName string `json:"bundleName" gorm:"column:bundle_name;type:varchar(2048);comment:套餐名"`
|
||||||
|
CustomerID string `json:"customerID" gorm:"column:customer_id;type:varchar(1024);comment:客户ID"`
|
||||||
|
CustomerNum string `json:"customerNum" gorm:"column:customer_num;type:varchar(1024);comment:客户编号"`
|
||||||
|
CustomerName string `json:"customerName" gorm:"column:customer_name;type:varchar(1024);comment:客户名"`
|
||||||
|
Amount float32 `json:"amount" gorm:"column:amount;type:decimal(12,2);comment:金额"`
|
||||||
|
AmountType int64 `json:"amountType" gorm:"column:amount_type;type:int;comment:金额类型"`
|
||||||
|
SignContract string `json:"signContract" gorm:"column:sign_contract;type:varchar(1024);comment:签约合同"`
|
||||||
|
Signature string `json:"signature" gorm:"column:signature;type:text;comment:签字"`
|
||||||
|
SignedTime string `json:"signedTime" gorm:"column:signed_time;type:varchar(1024);comment:签约时间(北京时间)"`
|
||||||
|
PayType int64 `json:"payType" gorm:"column:pay_type;type:int;comment:支付类型"`
|
||||||
|
PayTime string `json:"payTime" gorm:"column:pay_time;type:varchar(1024);comment:支付时间(北京时间)"`
|
||||||
|
CheckoutSessionId string `json:"checkoutSessionId" gorm:"column:checkout_session_id;type:varchar(1024);comment:checkoutSessionId"`
|
||||||
|
CheckoutSessionUrl string `json:"checkoutSessionUrl" gorm:"column:checkout_session_url;type:text;comment:checkoutSessionUrl"`
|
||||||
|
Status int64 `json:"status" gorm:"column:status;type:int;comment:状态 1:已签未支付 2:已签已支付"`
|
||||||
|
}
|
111
pb/bundle.proto
Normal file
111
pb/bundle.proto
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package bundle;
|
||||||
|
option go_package = "./bundle";
|
||||||
|
|
||||||
|
service Bundle {
|
||||||
|
rpc CreateBundle(BundleProfile) returns (CommonResponse) {}
|
||||||
|
rpc UpdateBundle(BundleProfile) returns (CommonResponse) {}
|
||||||
|
rpc DeleteBundle(DelBundleRequest) returns (CommonResponse) {}
|
||||||
|
|
||||||
|
rpc BundleList(BundleListRequest) returns (BundleListResponse) {}
|
||||||
|
rpc BundleDetail(BundleDetailRequest) returns (BundleDetailResponse) {}
|
||||||
|
|
||||||
|
rpc CreateOrderRecord(OrderRecord) returns (CommonResponse) {}
|
||||||
|
rpc UpdateOrderRecord(OrderRecord) returns (CommonResponse) {}
|
||||||
|
rpc OrderRecordsList(OrderRecordsRequest) returns (OrderRecordsResponse) {}
|
||||||
|
rpc OrderRecordsDetail(OrderRecordsDetailRequest) returns (OrderRecordsDetailResponse) {}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
message CommonResponse {
|
||||||
|
string msg = 1 [json_name = "msg"];
|
||||||
|
string uuid = 2 [json_name = "uuid"];
|
||||||
|
}
|
||||||
|
|
||||||
|
message BundleProfile {
|
||||||
|
string uuid = 1 [json_name = "uuid"];
|
||||||
|
string name = 2 [json_name = "name"];
|
||||||
|
int64 price = 3 [json_name = "price"];
|
||||||
|
int64 PriceType = 4 [json_name = "priceType"];
|
||||||
|
string content = 5 [json_name = "content"];
|
||||||
|
string contract = 6 [json_name = "contract"];
|
||||||
|
string language = 7 [json_name = "language"];
|
||||||
|
string createdAt = 8 [json_name = "createdAt"];
|
||||||
|
string updatedAt = 9 [json_name = "updatedAt"];
|
||||||
|
}
|
||||||
|
|
||||||
|
message DelBundleRequest {
|
||||||
|
string uuid = 1 [json_name = "uuid"];
|
||||||
|
}
|
||||||
|
|
||||||
|
message BundleListRequest {
|
||||||
|
int32 page = 1 [json_name = "page"];
|
||||||
|
int32 pageSize = 2 [json_name = "pageSize"];
|
||||||
|
string name = 3 [json_name = "name"];
|
||||||
|
string content = 4 [json_name = "content"];
|
||||||
|
}
|
||||||
|
|
||||||
|
message BundleListResponse {
|
||||||
|
repeated BundleProfile bundles = 1 [json_name = "bundles"];
|
||||||
|
int32 total = 2 [json_name = "total"];
|
||||||
|
}
|
||||||
|
|
||||||
|
message BundleDetailRequest {
|
||||||
|
string uuid = 1 [json_name = "uuid"];
|
||||||
|
}
|
||||||
|
|
||||||
|
message BundleDetailResponse {
|
||||||
|
BundleProfile bundle = 1 [json_name = "bundle"];
|
||||||
|
string msg = 2 [json_name = "msg"];
|
||||||
|
}
|
||||||
|
|
||||||
|
message OrderRecord {
|
||||||
|
string uuid = 1 [json_name = "uuid"];
|
||||||
|
string bundleUuid = 2 [json_name = "bundleUuid"];
|
||||||
|
string customerID = 3 [json_name = "customerID"];
|
||||||
|
string customerNum = 4 [json_name = "customerNum"];
|
||||||
|
string customerName = 5 [json_name = "customerName"];
|
||||||
|
int64 amount = 6 [json_name = "amount"];
|
||||||
|
int64 amountType = 7 [json_name = "amountType"];
|
||||||
|
string signContract = 8 [json_name = "signContract"];
|
||||||
|
string signature = 9 [json_name = "signature"];
|
||||||
|
string signedTime = 10 [json_name = "signedTime"];
|
||||||
|
int64 payType = 11 [json_name = "payType"];
|
||||||
|
string payTime = 12 [json_name = "payTime"];
|
||||||
|
string checkoutSessionId = 13 [json_name = "checkoutSessionId"];
|
||||||
|
string checkoutSessionUrl = 14 [json_name = "checkoutSessionUrl"];
|
||||||
|
string status = 15 [json_name = "status"];
|
||||||
|
string orderNo = 16 [json_name = "orderNo"];
|
||||||
|
string bundleName = 17 [json_name = "bundleName"];
|
||||||
|
}
|
||||||
|
|
||||||
|
message OrderRecordsRequest {
|
||||||
|
int32 page = 1 [json_name = "page"];
|
||||||
|
int32 pageSize = 2 [json_name = "pageSize"];
|
||||||
|
string customerNum = 3 [json_name = "customerNum"];
|
||||||
|
string customerName = 4 [json_name = "customerName"];
|
||||||
|
string bundleUUID = 5 [json_name = "bundleUUID"];
|
||||||
|
string orderNo = 6 [json_name = "orderNo"];
|
||||||
|
int64 status = 7 [json_name = "status"];
|
||||||
|
string bundleName = 8 [json_name = "bundleName"];
|
||||||
|
string startSignedTime = 9 [json_name = "startSignedTime"];
|
||||||
|
string endSignedTime = 10 [json_name = "endSignedTime"];
|
||||||
|
string startPayTime = 11 [json_name = "startPayTime"];
|
||||||
|
string endPayTime = 12 [json_name = "endPayTime"];
|
||||||
|
string customerID = 13 [json_name = "customerID"];
|
||||||
|
}
|
||||||
|
|
||||||
|
message OrderRecordsResponse {
|
||||||
|
repeated OrderRecord orderRecords = 1 [json_name = "orderRecords"];
|
||||||
|
int32 total = 2 [json_name = "total"];
|
||||||
|
}
|
||||||
|
|
||||||
|
message OrderRecordsDetailRequest {
|
||||||
|
string uuid = 1 [json_name = "uuid"];
|
||||||
|
}
|
||||||
|
|
||||||
|
message OrderRecordsDetailResponse {
|
||||||
|
OrderRecord orderRecord = 1 [json_name = "orderRecord"];
|
||||||
|
string msg = 2 [json_name = "msg"];
|
||||||
|
}
|
1336
pb/bundle/bundle.pb.go
Normal file
1336
pb/bundle/bundle.pb.go
Normal file
File diff suppressed because it is too large
Load Diff
77
pb/bundle/bundle.validator.pb.go
Normal file
77
pb/bundle/bundle.validator.pb.go
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||||
|
// source: pb/bundle.proto
|
||||||
|
|
||||||
|
package bundle
|
||||||
|
|
||||||
|
import (
|
||||||
|
fmt "fmt"
|
||||||
|
math "math"
|
||||||
|
proto "github.com/golang/protobuf/proto"
|
||||||
|
github_com_mwitkow_go_proto_validators "github.com/mwitkow/go-proto-validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ = proto.Marshal
|
||||||
|
var _ = fmt.Errorf
|
||||||
|
var _ = math.Inf
|
||||||
|
|
||||||
|
func (this *CommonResponse) Validate() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (this *BundleProfile) Validate() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (this *DelBundleRequest) Validate() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (this *BundleListRequest) Validate() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (this *BundleListResponse) Validate() error {
|
||||||
|
for _, item := range this.Bundles {
|
||||||
|
if item != nil {
|
||||||
|
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
|
||||||
|
return github_com_mwitkow_go_proto_validators.FieldError("Bundles", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (this *BundleDetailRequest) Validate() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (this *BundleDetailResponse) Validate() error {
|
||||||
|
if this.Bundle != nil {
|
||||||
|
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Bundle); err != nil {
|
||||||
|
return github_com_mwitkow_go_proto_validators.FieldError("Bundle", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (this *OrderRecord) Validate() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (this *OrderRecordsRequest) Validate() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (this *OrderRecordsResponse) Validate() error {
|
||||||
|
for _, item := range this.OrderRecords {
|
||||||
|
if item != nil {
|
||||||
|
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
|
||||||
|
return github_com_mwitkow_go_proto_validators.FieldError("OrderRecords", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (this *OrderRecordsDetailRequest) Validate() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (this *OrderRecordsDetailResponse) Validate() error {
|
||||||
|
if this.OrderRecord != nil {
|
||||||
|
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.OrderRecord); err != nil {
|
||||||
|
return github_com_mwitkow_go_proto_validators.FieldError("OrderRecord", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
507
pb/bundle/bundle_triple.pb.go
Normal file
507
pb/bundle/bundle_triple.pb.go
Normal file
@ -0,0 +1,507 @@
|
|||||||
|
// Code generated by protoc-gen-go-triple. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// - protoc-gen-go-triple v1.0.5
|
||||||
|
// - protoc v5.29.0--rc3
|
||||||
|
// source: pb/bundle.proto
|
||||||
|
|
||||||
|
package bundle
|
||||||
|
|
||||||
|
import (
|
||||||
|
context "context"
|
||||||
|
protocol "dubbo.apache.org/dubbo-go/v3/protocol"
|
||||||
|
dubbo3 "dubbo.apache.org/dubbo-go/v3/protocol/dubbo3"
|
||||||
|
invocation "dubbo.apache.org/dubbo-go/v3/protocol/invocation"
|
||||||
|
grpc_go "github.com/dubbogo/grpc-go"
|
||||||
|
codes "github.com/dubbogo/grpc-go/codes"
|
||||||
|
metadata "github.com/dubbogo/grpc-go/metadata"
|
||||||
|
status "github.com/dubbogo/grpc-go/status"
|
||||||
|
common "github.com/dubbogo/triple/pkg/common"
|
||||||
|
constant "github.com/dubbogo/triple/pkg/common/constant"
|
||||||
|
triple "github.com/dubbogo/triple/pkg/triple"
|
||||||
|
)
|
||||||
|
|
||||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||||
|
// is compatible with the grpc package it is being compiled against.
|
||||||
|
const _ = grpc_go.SupportPackageIsVersion7
|
||||||
|
|
||||||
|
// BundleClient is the client API for Bundle service.
|
||||||
|
//
|
||||||
|
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||||
|
type BundleClient interface {
|
||||||
|
CreateBundle(ctx context.Context, in *BundleProfile, opts ...grpc_go.CallOption) (*CommonResponse, common.ErrorWithAttachment)
|
||||||
|
UpdateBundle(ctx context.Context, in *BundleProfile, opts ...grpc_go.CallOption) (*CommonResponse, common.ErrorWithAttachment)
|
||||||
|
DeleteBundle(ctx context.Context, in *DelBundleRequest, opts ...grpc_go.CallOption) (*CommonResponse, common.ErrorWithAttachment)
|
||||||
|
BundleList(ctx context.Context, in *BundleListRequest, opts ...grpc_go.CallOption) (*BundleListResponse, common.ErrorWithAttachment)
|
||||||
|
BundleDetail(ctx context.Context, in *BundleDetailRequest, opts ...grpc_go.CallOption) (*BundleDetailResponse, common.ErrorWithAttachment)
|
||||||
|
CreateOrderRecord(ctx context.Context, in *OrderRecord, opts ...grpc_go.CallOption) (*CommonResponse, common.ErrorWithAttachment)
|
||||||
|
UpdateOrderRecord(ctx context.Context, in *OrderRecord, opts ...grpc_go.CallOption) (*CommonResponse, common.ErrorWithAttachment)
|
||||||
|
OrderRecordsList(ctx context.Context, in *OrderRecordsRequest, opts ...grpc_go.CallOption) (*OrderRecordsResponse, common.ErrorWithAttachment)
|
||||||
|
OrderRecordsDetail(ctx context.Context, in *OrderRecordsDetailRequest, opts ...grpc_go.CallOption) (*OrderRecordsDetailResponse, common.ErrorWithAttachment)
|
||||||
|
}
|
||||||
|
|
||||||
|
type bundleClient struct {
|
||||||
|
cc *triple.TripleConn
|
||||||
|
}
|
||||||
|
|
||||||
|
type BundleClientImpl struct {
|
||||||
|
CreateBundle func(ctx context.Context, in *BundleProfile) (*CommonResponse, error)
|
||||||
|
UpdateBundle func(ctx context.Context, in *BundleProfile) (*CommonResponse, error)
|
||||||
|
DeleteBundle func(ctx context.Context, in *DelBundleRequest) (*CommonResponse, error)
|
||||||
|
BundleList func(ctx context.Context, in *BundleListRequest) (*BundleListResponse, error)
|
||||||
|
BundleDetail func(ctx context.Context, in *BundleDetailRequest) (*BundleDetailResponse, error)
|
||||||
|
CreateOrderRecord func(ctx context.Context, in *OrderRecord) (*CommonResponse, error)
|
||||||
|
UpdateOrderRecord func(ctx context.Context, in *OrderRecord) (*CommonResponse, error)
|
||||||
|
OrderRecordsList func(ctx context.Context, in *OrderRecordsRequest) (*OrderRecordsResponse, error)
|
||||||
|
OrderRecordsDetail func(ctx context.Context, in *OrderRecordsDetailRequest) (*OrderRecordsDetailResponse, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *BundleClientImpl) GetDubboStub(cc *triple.TripleConn) BundleClient {
|
||||||
|
return NewBundleClient(cc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *BundleClientImpl) XXX_InterfaceName() string {
|
||||||
|
return "bundle.Bundle"
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewBundleClient(cc *triple.TripleConn) BundleClient {
|
||||||
|
return &bundleClient{cc}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *bundleClient) CreateBundle(ctx context.Context, in *BundleProfile, opts ...grpc_go.CallOption) (*CommonResponse, common.ErrorWithAttachment) {
|
||||||
|
out := new(CommonResponse)
|
||||||
|
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
|
||||||
|
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/CreateBundle", in, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *bundleClient) UpdateBundle(ctx context.Context, in *BundleProfile, opts ...grpc_go.CallOption) (*CommonResponse, common.ErrorWithAttachment) {
|
||||||
|
out := new(CommonResponse)
|
||||||
|
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
|
||||||
|
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/UpdateBundle", in, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *bundleClient) DeleteBundle(ctx context.Context, in *DelBundleRequest, opts ...grpc_go.CallOption) (*CommonResponse, common.ErrorWithAttachment) {
|
||||||
|
out := new(CommonResponse)
|
||||||
|
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
|
||||||
|
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/DeleteBundle", in, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *bundleClient) BundleList(ctx context.Context, in *BundleListRequest, opts ...grpc_go.CallOption) (*BundleListResponse, common.ErrorWithAttachment) {
|
||||||
|
out := new(BundleListResponse)
|
||||||
|
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
|
||||||
|
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/BundleList", in, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *bundleClient) BundleDetail(ctx context.Context, in *BundleDetailRequest, opts ...grpc_go.CallOption) (*BundleDetailResponse, common.ErrorWithAttachment) {
|
||||||
|
out := new(BundleDetailResponse)
|
||||||
|
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
|
||||||
|
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/BundleDetail", in, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *bundleClient) CreateOrderRecord(ctx context.Context, in *OrderRecord, opts ...grpc_go.CallOption) (*CommonResponse, common.ErrorWithAttachment) {
|
||||||
|
out := new(CommonResponse)
|
||||||
|
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
|
||||||
|
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/CreateOrderRecord", in, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *bundleClient) UpdateOrderRecord(ctx context.Context, in *OrderRecord, opts ...grpc_go.CallOption) (*CommonResponse, common.ErrorWithAttachment) {
|
||||||
|
out := new(CommonResponse)
|
||||||
|
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
|
||||||
|
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/UpdateOrderRecord", in, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *bundleClient) OrderRecordsList(ctx context.Context, in *OrderRecordsRequest, opts ...grpc_go.CallOption) (*OrderRecordsResponse, common.ErrorWithAttachment) {
|
||||||
|
out := new(OrderRecordsResponse)
|
||||||
|
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
|
||||||
|
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/OrderRecordsList", in, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *bundleClient) OrderRecordsDetail(ctx context.Context, in *OrderRecordsDetailRequest, opts ...grpc_go.CallOption) (*OrderRecordsDetailResponse, common.ErrorWithAttachment) {
|
||||||
|
out := new(OrderRecordsDetailResponse)
|
||||||
|
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
|
||||||
|
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/OrderRecordsDetail", in, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
// BundleServer is the server API for Bundle service.
|
||||||
|
// All implementations must embed UnimplementedBundleServer
|
||||||
|
// for forward compatibility
|
||||||
|
type BundleServer interface {
|
||||||
|
CreateBundle(context.Context, *BundleProfile) (*CommonResponse, error)
|
||||||
|
UpdateBundle(context.Context, *BundleProfile) (*CommonResponse, error)
|
||||||
|
DeleteBundle(context.Context, *DelBundleRequest) (*CommonResponse, error)
|
||||||
|
BundleList(context.Context, *BundleListRequest) (*BundleListResponse, error)
|
||||||
|
BundleDetail(context.Context, *BundleDetailRequest) (*BundleDetailResponse, error)
|
||||||
|
CreateOrderRecord(context.Context, *OrderRecord) (*CommonResponse, error)
|
||||||
|
UpdateOrderRecord(context.Context, *OrderRecord) (*CommonResponse, error)
|
||||||
|
OrderRecordsList(context.Context, *OrderRecordsRequest) (*OrderRecordsResponse, error)
|
||||||
|
OrderRecordsDetail(context.Context, *OrderRecordsDetailRequest) (*OrderRecordsDetailResponse, error)
|
||||||
|
mustEmbedUnimplementedBundleServer()
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnimplementedBundleServer must be embedded to have forward compatible implementations.
|
||||||
|
type UnimplementedBundleServer struct {
|
||||||
|
proxyImpl protocol.Invoker
|
||||||
|
}
|
||||||
|
|
||||||
|
func (UnimplementedBundleServer) CreateBundle(context.Context, *BundleProfile) (*CommonResponse, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method CreateBundle not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedBundleServer) UpdateBundle(context.Context, *BundleProfile) (*CommonResponse, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method UpdateBundle not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedBundleServer) DeleteBundle(context.Context, *DelBundleRequest) (*CommonResponse, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method DeleteBundle not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedBundleServer) BundleList(context.Context, *BundleListRequest) (*BundleListResponse, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method BundleList not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedBundleServer) BundleDetail(context.Context, *BundleDetailRequest) (*BundleDetailResponse, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method BundleDetail not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedBundleServer) CreateOrderRecord(context.Context, *OrderRecord) (*CommonResponse, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method CreateOrderRecord not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedBundleServer) UpdateOrderRecord(context.Context, *OrderRecord) (*CommonResponse, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method UpdateOrderRecord not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedBundleServer) OrderRecordsList(context.Context, *OrderRecordsRequest) (*OrderRecordsResponse, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method OrderRecordsList not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedBundleServer) OrderRecordsDetail(context.Context, *OrderRecordsDetailRequest) (*OrderRecordsDetailResponse, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method OrderRecordsDetail not implemented")
|
||||||
|
}
|
||||||
|
func (s *UnimplementedBundleServer) XXX_SetProxyImpl(impl protocol.Invoker) {
|
||||||
|
s.proxyImpl = impl
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *UnimplementedBundleServer) XXX_GetProxyImpl() protocol.Invoker {
|
||||||
|
return s.proxyImpl
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *UnimplementedBundleServer) XXX_ServiceDesc() *grpc_go.ServiceDesc {
|
||||||
|
return &Bundle_ServiceDesc
|
||||||
|
}
|
||||||
|
func (s *UnimplementedBundleServer) XXX_InterfaceName() string {
|
||||||
|
return "bundle.Bundle"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (UnimplementedBundleServer) mustEmbedUnimplementedBundleServer() {}
|
||||||
|
|
||||||
|
// UnsafeBundleServer may be embedded to opt out of forward compatibility for this service.
|
||||||
|
// Use of this interface is not recommended, as added methods to BundleServer will
|
||||||
|
// result in compilation errors.
|
||||||
|
type UnsafeBundleServer interface {
|
||||||
|
mustEmbedUnimplementedBundleServer()
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterBundleServer(s grpc_go.ServiceRegistrar, srv BundleServer) {
|
||||||
|
s.RegisterService(&Bundle_ServiceDesc, srv)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _Bundle_CreateBundle_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(BundleProfile)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
base := srv.(dubbo3.Dubbo3GrpcService)
|
||||||
|
args := []interface{}{}
|
||||||
|
args = append(args, in)
|
||||||
|
md, _ := metadata.FromIncomingContext(ctx)
|
||||||
|
invAttachment := make(map[string]interface{}, len(md))
|
||||||
|
for k, v := range md {
|
||||||
|
invAttachment[k] = v
|
||||||
|
}
|
||||||
|
invo := invocation.NewRPCInvocation("CreateBundle", args, invAttachment)
|
||||||
|
if interceptor == nil {
|
||||||
|
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||||
|
return result, result.Error()
|
||||||
|
}
|
||||||
|
info := &grpc_go.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||||
|
return result, result.Error()
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _Bundle_UpdateBundle_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(BundleProfile)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
base := srv.(dubbo3.Dubbo3GrpcService)
|
||||||
|
args := []interface{}{}
|
||||||
|
args = append(args, in)
|
||||||
|
md, _ := metadata.FromIncomingContext(ctx)
|
||||||
|
invAttachment := make(map[string]interface{}, len(md))
|
||||||
|
for k, v := range md {
|
||||||
|
invAttachment[k] = v
|
||||||
|
}
|
||||||
|
invo := invocation.NewRPCInvocation("UpdateBundle", args, invAttachment)
|
||||||
|
if interceptor == nil {
|
||||||
|
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||||
|
return result, result.Error()
|
||||||
|
}
|
||||||
|
info := &grpc_go.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||||
|
return result, result.Error()
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _Bundle_DeleteBundle_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(DelBundleRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
base := srv.(dubbo3.Dubbo3GrpcService)
|
||||||
|
args := []interface{}{}
|
||||||
|
args = append(args, in)
|
||||||
|
md, _ := metadata.FromIncomingContext(ctx)
|
||||||
|
invAttachment := make(map[string]interface{}, len(md))
|
||||||
|
for k, v := range md {
|
||||||
|
invAttachment[k] = v
|
||||||
|
}
|
||||||
|
invo := invocation.NewRPCInvocation("DeleteBundle", args, invAttachment)
|
||||||
|
if interceptor == nil {
|
||||||
|
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||||
|
return result, result.Error()
|
||||||
|
}
|
||||||
|
info := &grpc_go.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||||
|
return result, result.Error()
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _Bundle_BundleList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(BundleListRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
base := srv.(dubbo3.Dubbo3GrpcService)
|
||||||
|
args := []interface{}{}
|
||||||
|
args = append(args, in)
|
||||||
|
md, _ := metadata.FromIncomingContext(ctx)
|
||||||
|
invAttachment := make(map[string]interface{}, len(md))
|
||||||
|
for k, v := range md {
|
||||||
|
invAttachment[k] = v
|
||||||
|
}
|
||||||
|
invo := invocation.NewRPCInvocation("BundleList", args, invAttachment)
|
||||||
|
if interceptor == nil {
|
||||||
|
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||||
|
return result, result.Error()
|
||||||
|
}
|
||||||
|
info := &grpc_go.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||||
|
return result, result.Error()
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _Bundle_BundleDetail_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(BundleDetailRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
base := srv.(dubbo3.Dubbo3GrpcService)
|
||||||
|
args := []interface{}{}
|
||||||
|
args = append(args, in)
|
||||||
|
md, _ := metadata.FromIncomingContext(ctx)
|
||||||
|
invAttachment := make(map[string]interface{}, len(md))
|
||||||
|
for k, v := range md {
|
||||||
|
invAttachment[k] = v
|
||||||
|
}
|
||||||
|
invo := invocation.NewRPCInvocation("BundleDetail", args, invAttachment)
|
||||||
|
if interceptor == nil {
|
||||||
|
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||||
|
return result, result.Error()
|
||||||
|
}
|
||||||
|
info := &grpc_go.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||||
|
return result, result.Error()
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _Bundle_CreateOrderRecord_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(OrderRecord)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
base := srv.(dubbo3.Dubbo3GrpcService)
|
||||||
|
args := []interface{}{}
|
||||||
|
args = append(args, in)
|
||||||
|
md, _ := metadata.FromIncomingContext(ctx)
|
||||||
|
invAttachment := make(map[string]interface{}, len(md))
|
||||||
|
for k, v := range md {
|
||||||
|
invAttachment[k] = v
|
||||||
|
}
|
||||||
|
invo := invocation.NewRPCInvocation("CreateOrderRecord", args, invAttachment)
|
||||||
|
if interceptor == nil {
|
||||||
|
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||||
|
return result, result.Error()
|
||||||
|
}
|
||||||
|
info := &grpc_go.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||||
|
return result, result.Error()
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _Bundle_UpdateOrderRecord_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(OrderRecord)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
base := srv.(dubbo3.Dubbo3GrpcService)
|
||||||
|
args := []interface{}{}
|
||||||
|
args = append(args, in)
|
||||||
|
md, _ := metadata.FromIncomingContext(ctx)
|
||||||
|
invAttachment := make(map[string]interface{}, len(md))
|
||||||
|
for k, v := range md {
|
||||||
|
invAttachment[k] = v
|
||||||
|
}
|
||||||
|
invo := invocation.NewRPCInvocation("UpdateOrderRecord", args, invAttachment)
|
||||||
|
if interceptor == nil {
|
||||||
|
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||||
|
return result, result.Error()
|
||||||
|
}
|
||||||
|
info := &grpc_go.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||||
|
return result, result.Error()
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _Bundle_OrderRecordsList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(OrderRecordsRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
base := srv.(dubbo3.Dubbo3GrpcService)
|
||||||
|
args := []interface{}{}
|
||||||
|
args = append(args, in)
|
||||||
|
md, _ := metadata.FromIncomingContext(ctx)
|
||||||
|
invAttachment := make(map[string]interface{}, len(md))
|
||||||
|
for k, v := range md {
|
||||||
|
invAttachment[k] = v
|
||||||
|
}
|
||||||
|
invo := invocation.NewRPCInvocation("OrderRecordsList", args, invAttachment)
|
||||||
|
if interceptor == nil {
|
||||||
|
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||||
|
return result, result.Error()
|
||||||
|
}
|
||||||
|
info := &grpc_go.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||||
|
return result, result.Error()
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _Bundle_OrderRecordsDetail_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(OrderRecordsDetailRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
base := srv.(dubbo3.Dubbo3GrpcService)
|
||||||
|
args := []interface{}{}
|
||||||
|
args = append(args, in)
|
||||||
|
md, _ := metadata.FromIncomingContext(ctx)
|
||||||
|
invAttachment := make(map[string]interface{}, len(md))
|
||||||
|
for k, v := range md {
|
||||||
|
invAttachment[k] = v
|
||||||
|
}
|
||||||
|
invo := invocation.NewRPCInvocation("OrderRecordsDetail", args, invAttachment)
|
||||||
|
if interceptor == nil {
|
||||||
|
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||||
|
return result, result.Error()
|
||||||
|
}
|
||||||
|
info := &grpc_go.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||||
|
return result, result.Error()
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bundle_ServiceDesc is the grpc_go.ServiceDesc for Bundle service.
|
||||||
|
// It's only intended for direct use with grpc_go.RegisterService,
|
||||||
|
// and not to be introspected or modified (even as a copy)
|
||||||
|
var Bundle_ServiceDesc = grpc_go.ServiceDesc{
|
||||||
|
ServiceName: "bundle.Bundle",
|
||||||
|
HandlerType: (*BundleServer)(nil),
|
||||||
|
Methods: []grpc_go.MethodDesc{
|
||||||
|
{
|
||||||
|
MethodName: "CreateBundle",
|
||||||
|
Handler: _Bundle_CreateBundle_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "UpdateBundle",
|
||||||
|
Handler: _Bundle_UpdateBundle_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "DeleteBundle",
|
||||||
|
Handler: _Bundle_DeleteBundle_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "BundleList",
|
||||||
|
Handler: _Bundle_BundleList_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "BundleDetail",
|
||||||
|
Handler: _Bundle_BundleDetail_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "CreateOrderRecord",
|
||||||
|
Handler: _Bundle_CreateOrderRecord_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "UpdateOrderRecord",
|
||||||
|
Handler: _Bundle_UpdateOrderRecord_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "OrderRecordsList",
|
||||||
|
Handler: _Bundle_OrderRecordsList_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "OrderRecordsDetail",
|
||||||
|
Handler: _Bundle_OrderRecordsDetail_Handler,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Streams: []grpc_go.StreamDesc{},
|
||||||
|
Metadata: "pb/bundle.proto",
|
||||||
|
}
|
20
pkg/amqp/rabbitmq.go
Normal file
20
pkg/amqp/rabbitmq.go
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package amqp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/google/wire"
|
||||||
|
"github.com/streadway/amqp"
|
||||||
|
)
|
||||||
|
|
||||||
|
var RabbitMqConn *amqp.Connection
|
||||||
|
|
||||||
|
var Provider = wire.NewSet(NewRabbitMq)
|
||||||
|
|
||||||
|
func NewRabbitMq() *amqp.Connection {
|
||||||
|
//var err error
|
||||||
|
// 创建连接
|
||||||
|
/*RabbitMqConn, err = amqp.Dial(fmt.Sprintf("amqp://%s:%s@%s:%d/%s", appConfig.Data.RabbitMq.User, appConfig.Data.RabbitMq.Password, appConfig.Data.RabbitMq.Host, appConfig.Data.RabbitMq.Port, appConfig.Data.RabbitMq.Vhost))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("failed to connect RabbitMQ: %v", err)
|
||||||
|
}*/
|
||||||
|
return RabbitMqConn
|
||||||
|
}
|
18
pkg/app/app.go
Normal file
18
pkg/app/app.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/bwmarrin/snowflake"
|
||||||
|
"go.uber.org/zap"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"micro-bundle/pkg/tracing"
|
||||||
|
)
|
||||||
|
|
||||||
|
var ModuleClients *App
|
||||||
|
|
||||||
|
type App struct {
|
||||||
|
Lg *zap.Logger
|
||||||
|
//RedisClient *redis.Client
|
||||||
|
JaegerTracer *tracing.JaegerProvider
|
||||||
|
BundleDB *gorm.DB
|
||||||
|
SfNode *snowflake.Node
|
||||||
|
}
|
24
pkg/cache/redis.go
vendored
Normal file
24
pkg/cache/redis.go
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package cache
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/go-redis/redis"
|
||||||
|
"github.com/google/wire"
|
||||||
|
)
|
||||||
|
|
||||||
|
var RedisProvider = wire.NewSet(NewRedis)
|
||||||
|
|
||||||
|
// TODO 添加连接池
|
||||||
|
func NewRedis() *redis.Client {
|
||||||
|
//redisDb, _ := strconv.Atoi(dciConfig.Data.Redis.DB)
|
||||||
|
//RedisClient := redis.NewClient(&redis.Options{
|
||||||
|
// Addr: dciConfig.Data.Redis.Addr,
|
||||||
|
// Password: dciConfig.Data.Redis.Password,
|
||||||
|
// DB: redisDb,
|
||||||
|
//})
|
||||||
|
//_, err := RedisClient.Ping().Result()
|
||||||
|
//if err != nil {
|
||||||
|
// logger.Errorf("connRedis err", err)
|
||||||
|
// panic(err)
|
||||||
|
//}
|
||||||
|
return nil
|
||||||
|
}
|
18
pkg/db/bundleDB.go
Normal file
18
pkg/db/bundleDB.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package db
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/google/wire"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
bundleConfig "micro-bundle/config"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var Provider = wire.NewSet(NewBundleDB)
|
||||||
|
|
||||||
|
func NewBundleDB() *gorm.DB {
|
||||||
|
connBundleDB := strings.Join([]string{bundleConfig.Data.ChainDci.User, ":", bundleConfig.Data.ChainDci.Password,
|
||||||
|
"@tcp(", bundleConfig.Data.ChainDci.Host, ":", bundleConfig.Data.ChainDci.Port, ")/",
|
||||||
|
bundleConfig.Data.ChainDci.DbName, "?charset=utf8mb4&parseTime=true"}, "")
|
||||||
|
DciDB := loadMysqlConn(connBundleDB)
|
||||||
|
return DciDB
|
||||||
|
}
|
56
pkg/db/mysql.go
Normal file
56
pkg/db/mysql.go
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
package db
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"gorm.io/driver/mysql"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"gorm.io/gorm/logger"
|
||||||
|
"gorm.io/gorm/schema"
|
||||||
|
|
||||||
|
"micro-bundle/internal/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
func loadMysqlConn(conn string) *gorm.DB {
|
||||||
|
var ormLogger logger.Interface
|
||||||
|
if gin.Mode() == "debug" {
|
||||||
|
ormLogger = logger.Default.LogMode(logger.Info)
|
||||||
|
} else {
|
||||||
|
ormLogger = logger.Default
|
||||||
|
}
|
||||||
|
db, err := gorm.Open(mysql.New(mysql.Config{
|
||||||
|
DSN: conn, // DSN data source name
|
||||||
|
DefaultStringSize: 256, // string 类型字段的默认长度
|
||||||
|
DisableDatetimePrecision: true, // 禁用 datetime 精度,MySQL 5.6 之前的数据库不支持
|
||||||
|
DontSupportRenameIndex: true, // 重命名索引时采用删除并新建的方式,MySQL 5.7 之前的数据库和 MariaDB 不支持重命名索引
|
||||||
|
DontSupportRenameColumn: true, // 用 `change` 重命名列,MySQL 8 之前的数据库和 MariaDB 不支持重命名列
|
||||||
|
SkipInitializeWithVersion: false, // 根据版本自动配置
|
||||||
|
}), &gorm.Config{
|
||||||
|
Logger: ormLogger,
|
||||||
|
NamingStrategy: schema.NamingStrategy{
|
||||||
|
SingularTable: true,
|
||||||
|
},
|
||||||
|
DisableForeignKeyConstraintWhenMigrating: true,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
sqlDB, _ := db.DB()
|
||||||
|
sqlDB.SetMaxIdleConns(20) //设置连接池,空闲
|
||||||
|
sqlDB.SetMaxOpenConns(100) //打开
|
||||||
|
sqlDB.SetConnMaxLifetime(time.Second * 30)
|
||||||
|
err = db.AutoMigrate(&model.BundleProfile{}, &model.BundleOrderRecords{})
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return db
|
||||||
|
}
|
||||||
|
|
||||||
|
func DBMigration() {
|
||||||
|
}
|
||||||
|
|
||||||
|
func addColumn(dst interface{}, column string) {
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
40
pkg/err/common.go
Normal file
40
pkg/err/common.go
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package err
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"dubbo.apache.org/dubbo-go/v3/common/logger"
|
||||||
|
"github.com/getsentry/sentry-go"
|
||||||
|
"go.uber.org/zap"
|
||||||
|
|
||||||
|
"micro-bundle/pkg/app"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ReturnError(err error, msg, print string) error {
|
||||||
|
if err != nil {
|
||||||
|
sentry.WithScope(func(scope *sentry.Scope) {
|
||||||
|
scope.SetLevel(sentry.LevelError)
|
||||||
|
sentry.CaptureMessage(fmt.Sprintf("print:%+v msg:%+v err : %+v", print, msg, err))
|
||||||
|
})
|
||||||
|
|
||||||
|
logger.Error(print, err)
|
||||||
|
fmt.Printf(print+"%+v\n", err)
|
||||||
|
return errors.New(msg)
|
||||||
|
} else {
|
||||||
|
sentry.CaptureMessage(fmt.Sprintf("print:%+v msg:%+v ", print, msg))
|
||||||
|
return errors.New(msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func RecordCommonInfo(method, point string, value any) {
|
||||||
|
sentry.WithScope(func(scope *sentry.Scope) {
|
||||||
|
scope.SetLevel(sentry.LevelInfo)
|
||||||
|
scope.SetTag("method : ", method)
|
||||||
|
if value != nil {
|
||||||
|
sentry.CaptureMessage(fmt.Sprintf("point:%+v value:%+v ", point, value))
|
||||||
|
} else {
|
||||||
|
sentry.CaptureMessage(fmt.Sprintf("point:%+v ", point))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
5
pkg/init/start.go
Normal file
5
pkg/init/start.go
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
func Init() {
|
||||||
|
//db.DBMigration()
|
||||||
|
}
|
63
pkg/logger/zap_logger.go
Normal file
63
pkg/logger/zap_logger.go
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
package logger
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/google/wire"
|
||||||
|
bundleConfig "micro-bundle/config"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/natefinch/lumberjack"
|
||||||
|
"go.uber.org/zap"
|
||||||
|
"go.uber.org/zap/zapcore"
|
||||||
|
)
|
||||||
|
|
||||||
|
var Provider = wire.NewSet(ZapInit)
|
||||||
|
|
||||||
|
// ZapInit 初始化lg
|
||||||
|
func ZapInit() *zap.Logger {
|
||||||
|
var err error
|
||||||
|
maxSize, _ := strconv.Atoi(bundleConfig.Data.ZapLog.MaxSize)
|
||||||
|
maxAge, _ := strconv.Atoi(bundleConfig.Data.ZapLog.MaxAge)
|
||||||
|
maxBackups, _ := strconv.Atoi(bundleConfig.Data.ZapLog.MaxAge)
|
||||||
|
writeSyncer := getLogWriter(bundleConfig.Data.ZapLog.Filename, maxSize, maxBackups, maxAge)
|
||||||
|
encoder := getEncoder()
|
||||||
|
var l = new(zapcore.Level)
|
||||||
|
err = l.UnmarshalText([]byte(bundleConfig.Data.ZapLog.Level))
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
var core zapcore.Core
|
||||||
|
if bundleConfig.Data.System.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 {
|
||||||
|
core = zapcore.NewCore(encoder, writeSyncer, l)
|
||||||
|
}
|
||||||
|
lg := zap.New(core, zap.AddCaller())
|
||||||
|
zap.ReplaceGlobals(lg)
|
||||||
|
return lg
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
45
pkg/msg/msg.go
Normal file
45
pkg/msg/msg.go
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
package msg
|
||||||
|
|
||||||
|
const (
|
||||||
|
SERVER_CONFIG = "config.yaml"
|
||||||
|
SERVER_DUBBOGO_CONFIG = "dubbogo.yaml"
|
||||||
|
MODE_ENV = "MODE_ENV"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
Success = "操作成功"
|
||||||
|
Failed = "操作失败"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
Http = 200
|
||||||
|
)
|
||||||
|
|
||||||
|
// 套餐信息
|
||||||
|
const (
|
||||||
|
ErrorCreateBundleInfo = "创建套餐信息失败"
|
||||||
|
SuccessCreateBundleInfo = "创建套餐信息成功"
|
||||||
|
|
||||||
|
ErrorUpdateBundleInfo = "更新套餐信息失败"
|
||||||
|
SuccessUpdateBundleInfo = "更新套餐信息成功"
|
||||||
|
|
||||||
|
ErrorDeleteBundleInfo = "删除套餐信息失败"
|
||||||
|
SuccessDeleteBundleInfo = "删除套餐信息成功"
|
||||||
|
|
||||||
|
ErrorGetBundleList = "获取套餐列表失败"
|
||||||
|
|
||||||
|
ErrorGetBundleInfo = "获取套餐信息失败"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 订单信息
|
||||||
|
const (
|
||||||
|
ErrorCreateOrderInfo = "创建订单信息失败"
|
||||||
|
SuccessCreateOrderInfo = "创建订单信息成功"
|
||||||
|
|
||||||
|
ErrorUpdateOrderInfo = "更新订单信息失败"
|
||||||
|
SuccessUpdateOrderInfo = "更新订单信息成功"
|
||||||
|
|
||||||
|
ErrorGetOrderInfo = "获取订单信息失败"
|
||||||
|
|
||||||
|
ErrorGetOrderList = "获取订单列表失败"
|
||||||
|
)
|
4
pkg/service/init.go
Normal file
4
pkg/service/init.go
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
}
|
38
pkg/snowf/snowflake.go
Normal file
38
pkg/snowf/snowflake.go
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package snowf
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/bwmarrin/snowflake"
|
||||||
|
"github.com/google/wire"
|
||||||
|
|
||||||
|
bundleConfig "micro-bundle/config"
|
||||||
|
"micro-bundle/pkg/app"
|
||||||
|
)
|
||||||
|
|
||||||
|
var Provider = wire.NewSet(NewSf)
|
||||||
|
|
||||||
|
func NewSf() *snowflake.Node {
|
||||||
|
var err error
|
||||||
|
var st time.Time
|
||||||
|
nodeNum, _ := strconv.Atoi(bundleConfig.Data.SnowFlake.NodeNum)
|
||||||
|
st, err = time.Parse("2006-01-02", bundleConfig.Data.SnowFlake.StartTime)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
snowflake.Epoch = st.UnixNano() / 1000000
|
||||||
|
node, errS := snowflake.NewNode(int64(nodeNum))
|
||||||
|
if errS != nil {
|
||||||
|
panic(errS)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
func GenIDInt64() int64 {
|
||||||
|
return app.ModuleClients.SfNode.Generate().Int64()
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetIDBase64() string {
|
||||||
|
return app.ModuleClients.SfNode.Generate().Base64()
|
||||||
|
}
|
51
pkg/tracing/jaeger.go
Normal file
51
pkg/tracing/jaeger.go
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package tracing
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
bundleConfig "micro-bundle/config"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/wire"
|
||||||
|
"github.com/opentracing/opentracing-go"
|
||||||
|
"github.com/uber/jaeger-client-go"
|
||||||
|
jaegerConfig "github.com/uber/jaeger-client-go/config"
|
||||||
|
"go.uber.org/zap"
|
||||||
|
)
|
||||||
|
|
||||||
|
var Provider = wire.NewSet(NewTracing)
|
||||||
|
|
||||||
|
type JaegerProvider struct {
|
||||||
|
Tracer opentracing.Tracer
|
||||||
|
Closer io.Closer
|
||||||
|
}
|
||||||
|
|
||||||
|
//var JaegerPoint *JaegerProvider
|
||||||
|
|
||||||
|
func NewTracing() (jaegerProvider *JaegerProvider) {
|
||||||
|
if bundleConfig.Data.Jaeger.Open != "true" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
jaegerProvider = &JaegerProvider{}
|
||||||
|
cfg := jaegerConfig.Configuration{
|
||||||
|
ServiceName: "oa-meeting",
|
||||||
|
Sampler: &jaegerConfig.SamplerConfig{
|
||||||
|
Type: jaeger.SamplerTypeRemote,
|
||||||
|
Param: 1,
|
||||||
|
},
|
||||||
|
Reporter: &jaegerConfig.ReporterConfig{
|
||||||
|
LocalAgentHostPort: bundleConfig.Data.Jaeger.Addr,
|
||||||
|
LogSpans: true,
|
||||||
|
BufferFlushInterval: 5 * time.Second,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
nativeTracerIo, closerIo, err := cfg.NewTracer(jaegerConfig.Logger(jaeger.StdLogger))
|
||||||
|
if err != nil {
|
||||||
|
zap.L().Error("nativeTracer err", zap.Error(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
opentracing.SetGlobalTracer(nativeTracerIo)
|
||||||
|
jaegerProvider.Tracer = nativeTracerIo
|
||||||
|
jaegerProvider.Closer = closerIo
|
||||||
|
//JaegerPoint = jaegerProvider
|
||||||
|
return
|
||||||
|
}
|
75
pkg/utils/http.go
Normal file
75
pkg/utils/http.go
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"go.uber.org/zap"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Post(url string, jsonStr []byte) (statusCode int, result string) {
|
||||||
|
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
client := &http.Client{}
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
statusCode = resp.StatusCode
|
||||||
|
body, _ := ioutil.ReadAll(resp.Body)
|
||||||
|
fmt.Println("post url:", url)
|
||||||
|
fmt.Println("response Headers:", resp.Header)
|
||||||
|
fmt.Println("response Body:", string(body))
|
||||||
|
result = string(body)
|
||||||
|
zap.L().Info("post", zap.Any("url", url), zap.Any("jsonStr", jsonStr), zap.Any("result", result))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func Get(url string) (statusCode int, result string) {
|
||||||
|
resp, err := http.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
statusCode = resp.StatusCode
|
||||||
|
fmt.Println("response StatusCode:", resp.StatusCode)
|
||||||
|
fmt.Println("response Status:", resp.Status)
|
||||||
|
fmt.Println("response Headers:", resp.Header)
|
||||||
|
body, _ := ioutil.ReadAll(resp.Body)
|
||||||
|
result = string(body)
|
||||||
|
fmt.Println("response Body:", string(body))
|
||||||
|
zap.L().Info("Get", zap.Any("url", url), zap.Any("result", result))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func PutFromFileUrlWithStream(url, fileName, fileUrl string) (statusCode int, result string) {
|
||||||
|
file, err := http.Get(fileUrl)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer file.Body.Close()
|
||||||
|
fileBody, _ := ioutil.ReadAll(file.Body)
|
||||||
|
|
||||||
|
req, err := http.NewRequest("PUT", url, bytes.NewBuffer(fileBody))
|
||||||
|
req.Header.Set("Content-Type", "application/octet-stream")
|
||||||
|
req.Header.Set("x-oss-meta-rawfilename", fileName)
|
||||||
|
client := &http.Client{}
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
//panic(err)
|
||||||
|
return 400, "执行文件上传失败"
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
statusCode = resp.StatusCode
|
||||||
|
body, _ := ioutil.ReadAll(resp.Body)
|
||||||
|
result = string(body)
|
||||||
|
fmt.Println("put url:", url)
|
||||||
|
fmt.Println("fileName :", fileName)
|
||||||
|
fmt.Println("response Headers:", resp.Header)
|
||||||
|
//fmt.Println("response Body:", string(body))
|
||||||
|
fmt.Println("response StatusCode:", statusCode)
|
||||||
|
//zap.L().Info("post", zap.Any("url", url), zap.Any("jsonStr", bytes.NewBuffer(fileBody).String()), zap.Any("result", result))
|
||||||
|
return
|
||||||
|
}
|
11
pkg/utils/msg.go
Normal file
11
pkg/utils/msg.go
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
import "errors"
|
||||||
|
|
||||||
|
func SubstrError(err error) (sErr error) {
|
||||||
|
start := strings.Index(err.Error(), ":")
|
||||||
|
msg := err.Error()[start+2:]
|
||||||
|
sErr = errors.New(msg)
|
||||||
|
return
|
||||||
|
}
|
23
pkg/utils/orderNo.go
Normal file
23
pkg/utils/orderNo.go
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math/rand"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const source = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
|
|
||||||
|
// 生成订单号 模版 BD20250220104501+6位随机数 避免 订单号重复
|
||||||
|
func GetOrderNo() string {
|
||||||
|
return "BD" + time.Now().Format("20060102150405") + GetRandomString(6)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成随机字符串
|
||||||
|
func GetRandomString(length int) string {
|
||||||
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
bytes := make([]byte, length)
|
||||||
|
for i := 0; i < length; i++ {
|
||||||
|
bytes[i] = source[rand.Intn(62)]
|
||||||
|
}
|
||||||
|
return string(bytes)
|
||||||
|
}
|
52
pkg/utils/time.go
Normal file
52
pkg/utils/time.go
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"go.uber.org/zap"
|
||||||
|
|
||||||
|
"micro-bundle/pkg/msg"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
DateTimeFormat = "2006-01-02 15:04:05"
|
||||||
|
DateFormat = "2006-01-02"
|
||||||
|
DateFormatYmdHisDot = "2006.01.02 15:04"
|
||||||
|
DateFormatMonth = "2006年01月02日 15:04"
|
||||||
|
)
|
||||||
|
|
||||||
|
func DatetimeToTimes(datetime string, dateFormat string) (times int32, err error) {
|
||||||
|
if datetime == "" {
|
||||||
|
times = 0
|
||||||
|
return
|
||||||
|
}
|
||||||
|
loc, _ := time.LoadLocation("Asia/Shanghai")
|
||||||
|
t, err := time.ParseInLocation(dateFormat, datetime, loc)
|
||||||
|
if err != nil {
|
||||||
|
zap.L().Error("DatetimeToTimes err:"+datetime+":", zap.Error(err))
|
||||||
|
err = errors.New(msg.ErrorDatetime)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
times = int32(t.Unix())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func TimesToDatetime(times int32, format string) string {
|
||||||
|
if times == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
t := time.Unix(int64(times), 0)
|
||||||
|
if format == "" {
|
||||||
|
format = DateTimeFormat
|
||||||
|
}
|
||||||
|
return t.Format(format)
|
||||||
|
}
|
||||||
|
|
||||||
|
func MonthInfo() (startTime int64, endTime int64) {
|
||||||
|
timeNow := time.Now()
|
||||||
|
timeToday := time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, timeNow.Location()) // 获取当天0点时间 time类型
|
||||||
|
startTime = timeToday.AddDate(0, 0, -timeToday.Day()+1).Unix() // 获取本月第一天0点 时间戳类型
|
||||||
|
endTime = timeToday.AddDate(0, 1, -timeToday.Day()+1).Unix()
|
||||||
|
return
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user