Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
smgano committed May 18, 2024
1 parent 056cca2 commit ee984f7
Show file tree
Hide file tree
Showing 66 changed files with 502 additions and 427 deletions.
Binary file removed bfg-1.14.0.jar
Binary file not shown.
45 changes: 23 additions & 22 deletions cmd/gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package main

import (
"fmt"
"gorm.io/driver/mysql"
"gorm.io/gen"
"gorm.io/gorm"
"log"
"strings"
"unicode"

"gorm.io/driver/mysql"
"gorm.io/gen"
"gorm.io/gorm"
)

// DBType database type
Expand All @@ -23,22 +24,22 @@ const (
)

const (
//defaultQueryPath 模型文件存放目录
// defaultQueryPath 模型文件存放目录
defaultQueryPath = "./dao/query"
)

const Dsn = "root:passw0rd@tcp(127.0.0.1:3306)/db_goods_center?charset=utf8mb4&parseTime=True&loc=Local"

//const Dsn = "root:abcd1234@tcp(192.168.28.75:3306)/db_token?charset=utf8mb4&parseTime=True&loc=Local"
// const Dsn = "root:abcd1234@tcp(192.168.28.75:3306)/db_token?charset=utf8mb4&parseTime=True&loc=Local"

func main() {
//mysql
// mysql
db, err := gorm.Open(mysql.Open(Dsn))

// clickhouse
//db, err := gorm.Open(clickhouse.Open(Dsn))
// db, err := gorm.Open(clickhouse.Open(Dsn))
// postgres
//db, err := gorm.Open(postgres.Open(Dsn))
// db, err := gorm.Open(postgres.Open(Dsn))

if err != nil {
log.Fatalln("connect db server fail:", err)
Expand All @@ -47,42 +48,42 @@ func main() {
g := gen.NewGenerator(gen.Config{
OutPath: defaultQueryPath,
// 默认为:gen.go
//OutFile: "genb.go",
//ModelPkgPath 生成模型的包名
// OutFile: "genb.go",
// ModelPkgPath 生成模型的包名
ModelPkgPath: "model",
//生成单元测试。
//WithUnitTest: true,
//FieldNullable 字段可为空时使用指针生成
// 生成单元测试。
// WithUnitTest: true,
// FieldNullable 字段可为空时使用指针生成
FieldNullable: true,
//字段有默认值时使用指针生成
//FieldCoverable: true,
//FieldWithIndexTag 使用GROM索引标记生成字段
// 字段有默认值时使用指针生成
// FieldCoverable: true,
// FieldWithIndexTag 使用GROM索引标记生成字段
FieldWithIndexTag: true,
//FieldWithTypeTag 使用gorm列类型标记生成字段
// FieldWithTypeTag 使用gorm列类型标记生成字段
FieldWithTypeTag: true,
//基于数据表定义的数据类型,生成对应的数据类型
// 基于数据表定义的数据类型,生成对应的数据类型
FieldSignable: true,
})

g.UseDB(db)

g.WithJSONTagNameStrategy(
ToLowerCamelCase, //表字段 json tag 驼峰, 默认是下划线分割
ToLowerCamelCase, // 表字段 json tag 驼峰, 默认是下划线分割
)
// 部分表
tables := []string{
"apple_config",
"apple_product_price",
"user_score",
//"gp_product_price",
// "gp_product_price",
}
//tables := []string{} //全部表
// tables := []string{} //全部表
models, err := genModels(g, db, tables)
if err != nil {
log.Fatalln("get tables info fail:", err)
}

//false 指生成model,不生成query文件; true 全都生成
// false 指生成model,不生成query文件; true 全都生成
onlyModel := true
if onlyModel {
g.ApplyBasic(models...)
Expand Down
25 changes: 13 additions & 12 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package config
import (
"context"
"fmt"
"os"
"path/filepath"

"github.com/fsnotify/fsnotify"
"github.com/google/uuid"
"github.com/spf13/viper"
Expand All @@ -11,8 +14,6 @@ import (
"github.com/yituoshiniao/kit/xrds"
"github.com/yituoshiniao/kit/xtask"
"github.com/yituoshiniao/kit/xtrace"
"os"
"path/filepath"
)

type LoggerConfig struct {
Expand Down Expand Up @@ -40,13 +41,13 @@ type MonitorConfig struct {
}

type XTraceConfig struct {
//#上报配置类型
// #上报配置类型
SamplerType string
//#常量配置
// #常量配置
SamplerParam float64
//#数据服务器地址
// #数据服务器地址
ReporterLocalAgentHostPort string
//服务名
// 服务名
ServerName string
}

Expand Down Expand Up @@ -86,7 +87,7 @@ type Config struct {
type Database struct {
GoodsCenter v1.Config `yaml:"goodsCenter"`
Camexam v1.Config `yaml:"camexam"`
//解决viper读取yaml配置存在下划线时无法映射 添加tag: mapstructure
// 解决viper读取yaml配置存在下划线时无法映射 添加tag: mapstructure
DbToken v1.Config `yaml:"db_token" mapstructure:"db_token"`
}

Expand All @@ -111,11 +112,11 @@ var (
func ParseConfig(envPath string) Config {
pwd, _ := os.Getwd()
dirName := filepath.Base(pwd)
//read config
// read config
viper.SetConfigFile("./env.yaml") // 指定配置文件路径
viper.SetConfigName("env") // 配置文件名称(无扩展名)

//多环境变量
// 多环境变量
if envPath != "" {
viper.SetConfigFile("./env_" + envPath + ".yaml") // 指定配置文件路径
viper.SetConfigName("env_" + envPath) // 配置文件名称(无扩展名)
Expand All @@ -127,7 +128,7 @@ func ParseConfig(envPath string) Config {
err := viper.ReadInConfig() // 读取配置数据
if err != nil {
panic(fmt.Sprintf("Fatal error config file: %s", err))
//log.Fatalf("Fatal error config file: %s", err)
// log.Fatalf("Fatal error config file: %s", err)
}

dynamicReloadConfig(context.Background()) // 动态加载配置
Expand All @@ -137,7 +138,7 @@ func ParseConfig(envPath string) Config {
if err != nil {
// 处理读取配置文件的错误
panic(fmt.Sprintf("Unmarshal error config file: %s", err))
//log.Fatal(ctx, err)
// log.Fatal(ctx, err)
}
GlobalConfig = cfg
return cfg
Expand All @@ -158,7 +159,7 @@ func dynamicReloadConfig(ctx context.Context) {
var tmpCfg Config
if err := viper.Unmarshal(&tmpCfg); err != nil {
xlog.S(ctx).Errorw("加载配置错误", "err", err, "uuid", uuid)
//panic(fmt.Errorf("配置重载失败:%s\n", err))
// panic(fmt.Errorf("配置重载失败:%s\n", err))
return
}
GlobalConfig = tmpCfg
Expand Down
4 changes: 3 additions & 1 deletion inject/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package inject

import (
"context"

"github.com/opentracing/opentracing-go"
config2 "github.com/uber/jaeger-client-go/config"
"github.com/yituoshiniao/gin-api-http/config"
"github.com/yituoshiniao/kit/xlog"
"github.com/yituoshiniao/kit/xtrace"
"go.uber.org/zap"

"github.com/yituoshiniao/gin-api-http/config"
)

// ProvideLogger Log提供者
Expand Down
3 changes: 2 additions & 1 deletion inject/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package inject

import (
"github.com/google/wire"

"github.com/yituoshiniao/gin-api-http/config"
"github.com/yituoshiniao/gin-api-http/internal/api"
"github.com/yituoshiniao/gin-api-http/internal/api/cron"
Expand All @@ -22,7 +23,7 @@ func InitApp() (healthy *app2.App, cleanup func(), err error) {
wire.Build(
config.ParseConfig,
ProvideLogger,
ProvideTracer, //保证生成的 tracer 在文件wire_gen.go中的最前面
ProvideTracer, // 保证生成的 tracer 在文件wire_gen.go中的最前面
conn.WireSet,
app2.WireSet,
router.WireSet,
Expand Down
2 changes: 2 additions & 0 deletions internal/api/cron/enter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package cron
import (
"context"
"fmt"

"github.com/pkg/errors"

"github.com/yituoshiniao/gin-api-http/internal/metrics"
)

Expand Down
1 change: 1 addition & 0 deletions internal/api/cron/test_srv.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cron

import (
"context"

"github.com/yituoshiniao/kit/xlog"
)

Expand Down
89 changes: 45 additions & 44 deletions internal/api/dto/apple_dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dto

import (
"github.com/allegro/bigcache"

"github.com/yituoshiniao/gin-api-http/internal/api/http"
)

Expand All @@ -26,7 +27,7 @@ type StatusLocalCacheTaskResponse struct {
}

type ProductTerritoryPriceRequest struct {
ProductId string `form:"productId" binding:"required"` //产品id
ProductId string `form:"productId" binding:"required"` // 产品id
Territory string `form:"territory" binding:"required,min=2,max=3"` // 国家地区编码 三位,参数最小长度2,最大长度3
Channel string `form:"channel" binding:"required"` // 渠道 如 camexam(蜜蜂试卷)
Timestamp int64 `form:"timestamp" binding:"required"` // 传递时间戳
Expand All @@ -35,87 +36,87 @@ type ProductTerritoryPriceRequest struct {
}

type ProductTerritoryPriceInternalRequest struct {
ProductId string `form:"productId" binding:"required"` //产品id
ProductId string `form:"productId" binding:"required"` // 产品id
// Territory string `form:"territory" binding:"required,min=2,max=3"` // 国家地区编码 三位,参数最小长度2,最大长度3
Channel string `form:"channel,default=cs"` // 渠道 如 camexam(蜜蜂试卷)
Vector string `form:"vector"`
}

type AppleTokenRequest struct {
ProductId string `form:"productId" binding:"required"` //产品id
ProductId string `form:"productId" binding:"required"` // 产品id
Territory string `form:"territory" binding:"required"` // 国家地区编码 三位
Channel string `form:"channel" binding:"required"` // 渠道 如 camexam(蜜蜂试卷)
Timestamp int64 `form:"timestamp"` // 传递时间戳
}

type AppleTokenResponse struct {
Params map[string]string `json:"params"` //请求参数
Token string `json:"token"` //生成token
Params map[string]string `json:"params"` // 请求参数
Token string `json:"token"` // 生成token
}

type ProductTerritoryPriceResponse struct {
Number int64 `json:"number,string"` // int64 javascript前段精度问题,转字符串返回
ProductId string `json:"productId"` //产品id
Name string `json:"name"` //产品名
CustomerPrice float64 `json:"customerPrice"` //价格
FirstPrice float64 `json:"firstPrice"` //首单优惠价格
Territory string `json:"territory"` //地区编码
Currency string `json:"currency"` //货币
ProductId string `json:"productId"` // 产品id
Name string `json:"name"` // 产品名
CustomerPrice float64 `json:"customerPrice"` // 价格
FirstPrice float64 `json:"firstPrice"` // 首单优惠价格
Territory string `json:"territory"` // 地区编码
Currency string `json:"currency"` // 货币
ManualPricesId string `json:"manualPricesId"`
SubscriptionsPricePointsId string `json:"subscriptionsPricePointsId"`
Channel string `json:"channel"` //渠道
Channel string `json:"channel"` // 渠道
Type int8 `json:"type"` // 订阅类型
SubscriptionPeriod string `json:"subscriptionPeriod"` //订阅周期
SubscriptionPeriod string `json:"subscriptionPeriod"` // 订阅周期
InAppPurchaseType string `json:"InAppPurchaseType"`
FamilySharable int8 `json:"familySharable"` //是否家庭共享
AvailableInAllTerritories int8 `json:"availableInAllTerritories"` //是否适用于所有地区
Price string `json:"price"` //原价
PriceMonthly string `json:"priceMonthly"` //原价折月价
PriceYear string `json:"priceYear"` //原价折年价
OfferPrice string `json:"offerPrice"` //优惠价
OfferPriceMonthly string `json:"offerPriceMonthly"` //优惠折月价
OfferPriceYear string `json:"offerPriceYear"` //优惠折年价
TerritoryName string `json:"territoryName"` //国家名称
FamilySharable int8 `json:"familySharable"` // 是否家庭共享
AvailableInAllTerritories int8 `json:"availableInAllTerritories"` // 是否适用于所有地区
Price string `json:"price"` // 原价
PriceMonthly string `json:"priceMonthly"` // 原价折月价
PriceYear string `json:"priceYear"` // 原价折年价
OfferPrice string `json:"offerPrice"` // 优惠价
OfferPriceMonthly string `json:"offerPriceMonthly"` // 优惠折月价
OfferPriceYear string `json:"offerPriceYear"` // 优惠折年价
TerritoryName string `json:"territoryName"` // 国家名称
PriceNumMap map[string]string `json:"priceNumMap"`
MonthPriceMap map[string]string `json:"monthPriceMap"`
YearPriceMap map[string]string `json:"yearPriceMap"`
OfferMonthPriceMap map[string]string `json:"offerMonthPriceMap"`
OfferYearPriceMap map[string]string `json:"offerYearPriceMap"`
}
type ExtendSubscriptionRenewalDateRequest struct {
ExtendByDays string `form:"extendByDays" binding:"required,min=1,max=90"` //延长订阅续天数 最大90天
//ExtendReasonCode延迟原因;
//0、未申报;没有提供信息。
//1、延长续订日期是为了让客户满意。
//2、续订日期延期是出于其他原因。
//3、续订日期延期是由于服务问题或中断。
ExtendReasonCode string `form:"extendReasonCode" binding:"required"` //延迟原因
OriginalTransactionId string `form:"originalTransactionId" binding:"required"` //订单id
Channel string `form:"channel" binding:"required"` //渠道 cs || 蜜蜂等
Sign string `form:"sign" binding:"required"` //签名
ExtendByDays string `form:"extendByDays" binding:"required,min=1,max=90"` // 延长订阅续天数 最大90天
// ExtendReasonCode延迟原因;
// 0、未申报;没有提供信息。
// 1、延长续订日期是为了让客户满意。
// 2、续订日期延期是出于其他原因。
// 3、续订日期延期是由于服务问题或中断。
ExtendReasonCode string `form:"extendReasonCode" binding:"required"` // 延迟原因
OriginalTransactionId string `form:"originalTransactionId" binding:"required"` // 订单id
Channel string `form:"channel" binding:"required"` // 渠道 cs || 蜜蜂等
Sign string `form:"sign" binding:"required"` // 签名
}

type OfferSignRequest struct {
// 购买项id example:com.premiums.oneyear.autorenewable.free.limited2
ProductID string `form:"productId" binding:"required"` //产品id
//offerID example:firstyear178
ProductID string `form:"productId" binding:"required"` // 产品id
// offerID example:firstyear178
OfferID string `form:"offerId" binding:"required"`
//Channel 渠道 example: cs
// Channel 渠道 example: cs
Channel string `form:"channel" binding:"required"`
//ApplicationUsername
// ApplicationUsername
ApplicationUsername string `form:"applicationUsername" binding:"required"`
}

type OfferSignResponse struct {
http.ResponseData
}
type ProductTerritoryPriceInternalResponse struct {
ProductId string `json:"productId"` //产品id
Price string `json:"price"` //原价
PriceMonthly string `json:"priceMonthly"` //原价折月价
OfferPrice string `json:"offerPrice"` //优惠价
OfferPriceMonthly string `json:"offerPriceMonthly"` //优惠折月价
TerritoryName string `json:"territoryName"` //国家名称
PriceYear string `json:"priceYear"` //原价折年价
OfferPriceYear string `json:"offerPriceYear"` //优惠折年价
ProductId string `json:"productId"` // 产品id
Price string `json:"price"` // 原价
PriceMonthly string `json:"priceMonthly"` // 原价折月价
OfferPrice string `json:"offerPrice"` // 优惠价
OfferPriceMonthly string `json:"offerPriceMonthly"` // 优惠折月价
TerritoryName string `json:"territoryName"` // 国家名称
PriceYear string `json:"priceYear"` // 原价折年价
OfferPriceYear string `json:"offerPriceYear"` // 优惠折年价
}
Loading

0 comments on commit ee984f7

Please sign in to comment.