提交 a755f601 authored 作者: mooncake9527's avatar mooncake9527

update

上级 ea1c2441
app:
name: "xpkg"
env: "dev"
version: "v0.0.1"
host: "0.0.0.0"
enableStat: false
enableMetrics: true
enableHTTPProfile: true
enableLimit: false
enableCircuitBreaker: false
enableTrace: false
tracingSamplingRate: 1.0
registryDiscoveryType: ""
cacheType: "memory"
ipRateLimiter:
enable: true
window: 1m
maxRequests: 600
sync: true
hideSensitiveFields: "smtpPassword"
idGeneration:
type: leaf # snowflake leaf
leaf:
addr: http://leaf.qitu
showLog: true
retryCount: 2
snowflake:
node: 1
http:
port: 8080
timeout: 0
logger:
level: "debug"
format: "console"
isSave: true
logFileConfig:
filename: "/tmp/xpkg.log"
maxSize: 100
maxBackups: 100000
maxAge: 360
isCompression: true
rd:
nacos:
ips: 192.168.1.140
port: 8848
namespace: 92f5f471-d181-4028-be08-a3ee89bad9ed
context:
groupName: qitu
clusterName: public
weight: 10
enable: true
healthy: true
ephemeral: true
database:
- name: "operator"
driver: "mysql"
default: true
mysql:
dsn: "root:123456@tcp(localhost:30006)/qitu_operator?parseTime=true&loc=Local&charset=utf8,utf8mb4"
enableLog: true
maxIdleConns: 10
maxOpenConns: 100
connMaxLifetime: 30
- name: "pay"
driver: "mysql"
mysql:
dsn: "root:123456@tcp(localhost:30006)/qt-pay?parseTime=true&loc=Local&charset=utf8,utf8mb4"
enableLog: true
maxIdleConns: 10
maxOpenConns: 100
connMaxLifetime: 30
- name: "athena"
driver: "mysql"
mysql:
dsn: "root:123456@tcp(localhost:30006)/qitu_athena?parseTime=true&loc=Local&charset=utf8,utf8mb4"
enableLog: true
maxIdleConns: 10
maxOpenConns: 100
connMaxLifetime: 30
redis:
dsn: "default:password123@localhost:30079/6"
dialTimeout: 10
readTimeout: 2
writeTimeout: 2
auth:
enable: true
expire: 6h
signKey: 6m2KywHIPEaWWIxffGpp8Dfl3z5SjE5WeeDStc1T64klnpoAqHrHN01vneteCAGE
cron:
enable: true
oss:
endpoint: https://oss-cn-hangzhou.aliyuncs.com
access-key-id: LTAI5tD3VA4pi1pcz48yYgXL
access-key-secret: sus17wfcbjB6J9hDeJXXFtJf9LPN0S
bucket-name: test-wz-main
base-path: fota/upgrade
region-id: oss-cn-hangzhou
bucket-url: https://test-wz-main.oss-cn-hangzhou.aliyuncs.com
extend:
third-party:
baofu:
bct-terminal-id: ""
bct-member-id: ""
bct-version: "1.0.0"
wx:
appId: ""
appSecret: ""
pay:
addr: http://pay.qitu
reconciliation:
pull: /pay/reconciliationSummary/pull
pullNotify: /pay/reconciliationSummary/pullNotify
notify: /pay/reconciliationSummary/notify
service:
operator: # 麒兔运营商服务
server-addr: "http://athena-prime.qitu"
site-list: "/internal/operation/siteList" # 运营商下站点列表
pay-notify: "/internal/notifyPay" # 支付成功通知
refund-notify: "/internal/notifyRefund" # 退款通知
login-token: "/internal/partner/getLoginToken" # 获取运营商登录token
intake-notify: "/internal/operation/create" # 进件通知
notify-pay-success: "/internal/notifyPay" # 支付成功通知
notify-refund: "/internal/notifyRefund" # 退款通知
public: # 公共服务
server-addr: "http://car-public.car-iot:18306"
validate-sms: "/sms/validate" # 验证验证码
sms-send: "/sms/fishSend" # 发送短信(批量)
qt-pay:
server-addr: "http://qt-pay.qitu"
withdraw: "/pay/acc/sub-account/withdraw"
withdraw-query: "/pay/acc/sub-account/withdraw/query"
query-balance: "/pay/acc/sub-account/balance/query"
baofu-intake:
server-addr: "https://dev-mid.hzqitu.com/baofu-entry"
sms-send: "/insrv/common/sendCode"
upload: "/insrv/common/uploadFile"
login: "/front/user/login"
intake: "/front/entry/register"
intake-query: "/front/entry/registerInfo"
intake-qr-code: "/front/entry/getAuthQrCode"
app-id: "9285809280"
app-secret: "dx2LE3dovc51ycjqiezOcd0r0c9taKTeAqCVaR4LBs4"
pay-center:
server-addr: "http://service-pay.wz-service:18306" # 支付中心
dg-pay: "/pay/dougong" # 斗拱支付
dg-refund: "/refund/dougong" # 斗拱退款
dg-refund-query: "/refund/dougong_query" # 斗拱支付退款查询
user: # 用户中心服务
server-addr: "http://user-center2.wz-service:9901"
entry-record: "/settle/getSettleListByMemberId" # 入账记录
save-share-rate: "/agent/shareGroupAddMulti" # 保存合伙人分账
order: # 订单服务
server-addr: "http://share.qitu"
profit: "/profit/getProfitCurve" # 最近两天收益
share-profit: "/profit/getShareDayProfit" # 合伙人日收益
big-data: # 数据中台
server-addr: "http://mid-bigdata.wz-service:8000"
profit-report: "/qitu/profit/report" # 收益报表
share-income: "/qitu/income/shareList" # 合伙人收益列表
......@@ -111,11 +111,14 @@ type Config struct {
Logger Logger `yaml:"logger" json:"logger"`
Redis Redis `yaml:"redis" json:"redis"`
CronJobs Cron `yaml:"cron" json:"cron"`
Leaf Leaf `yaml:"leaf" json:"leaf"`
Oss oss.AliOssConfig `yaml:"oss" json:"oss"`
Content []byte `yaml:"-" json:"-"`
}
type Snowflake struct {
Node int `yaml:"node" json:"node"`
}
// 选择哪个配置中心
type ConfCenter struct {
Local Local `yaml:"-" json:"local"`
......@@ -201,7 +204,7 @@ type ServerSecure struct {
Type string `yaml:"type" json:"type"`
}
type EmailConfig struct {
type Email struct {
SMTPServer string `yaml:"smtpServer" json:"smtpServer"`
SMTPPort int `yaml:"smtpPort" json:"smtpPort"`
SMTPUsername string `yaml:"smtpUsername" json:"smtpUsername"`
......@@ -226,11 +229,19 @@ type App struct {
Version string `yaml:"version" json:"version"`
IPRateLimiter IPRateLimiter `yaml:"ipRateLimiter" json:"ipRateLimiter"`
HideSensitiveFields string `yaml:"hideSensitiveFields" json:"hideSensitiveFields"`
ConfPath string `yaml:"-" json:"confPath"`
PodName string `yaml:"-" json:"podName"`
WebLog WebLog `yaml:"webLog" json:"webLog"`
Email EmailConfig `yaml:"email" json:"email"`
HideSensitiveFields string `yaml:"hideSensitiveFields" json:"hideSensitiveFields"`
ConfPath string `yaml:"-" json:"confPath"`
PodName string `yaml:"-" json:"podName"`
WebLog WebLog `yaml:"webLog" json:"webLog"`
Email Email `yaml:"email" json:"email"`
Snowflake Snowflake `yaml:"snowflake" json:"snowflake"`
IDGeneration IDGeneration `yaml:"idGeneration" json:"idGeneration"`
}
type IDGeneration struct {
Type string `yaml:"type" json:"type"` // snowflake or leaf
Leaf Leaf `yaml:"leaf" json:"leaf"`
Snowflake Snowflake `yaml:"snowflake" json:"snowflake"`
}
type WebLog struct {
......
......@@ -8,7 +8,6 @@ import (
"github.com/spf13/cast"
"github.com/spf13/viper"
"gitlab.wanzhuangkj.com/tush/xpkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils"
)
var (
......@@ -20,16 +19,7 @@ type IExtend interface {
Unlock()
}
func init() {
if err := parse(); err != nil {
logger.Fatal("init failed", logger.Err(err))
}
}
func parse() (err error) {
if confType, ok := os.LookupEnv("CONF_TYPE"); (ok && sliceUtils.NotContains([]string{"local", "nacos", "consul"}, confType)) || !ok {
return
}
func Parse() (err error) {
if hostname := os.Getenv("HOSTNAME"); hostname != "" {
Cfg.App.PodName = hostname
}
......
......@@ -3,6 +3,7 @@ package xpkg
import (
"context"
"fmt"
"os"
"strconv"
"github.com/jinzhu/copier"
......@@ -15,9 +16,30 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/rd/nacos"
"gitlab.wanzhuangkj.com/tush/xpkg/stat"
"gitlab.wanzhuangkj.com/tush/xpkg/tracer"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/dxsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror"
)
func init() {
if confType, ok := os.LookupEnv("CONF_TYPE"); (ok && sliceUtils.NotContains([]string{"local", "nacos", "consul"}, confType)) || !ok {
return
}
if err := config.Parse(); err != nil {
logger.Fatal(err.Error())
}
if err := xsf.Init(); err != nil {
logger.Fatal(err.Error())
}
if err := dxsf.Init(); err != nil {
logger.Fatal(err.Error())
}
if err := Init(); err != nil {
logger.Fatal(err.Error())
}
}
func Init() (err error) {
conf := config.Cfg
if err := initLogger(conf); err != nil {
......
......@@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"net/http"
"os"
"time"
"gitlab.wanzhuangkj.com/tush/xpkg/config"
......@@ -18,7 +17,7 @@ var (
XSF_TYPE = "SF"
retryCount = 3
showLog = false
xsfAddr string = "http://leaf.qitu"
addr string = "http://leaf.qitu"
api = &client{
cli: httpcli.NewClient(
&http.Client{
......@@ -35,28 +34,23 @@ type client struct {
cli *httpcli.Client
}
func init() {
if xsfType := os.Getenv("XSF_TYPE"); xsfType != "" {
XSF_TYPE = xsfType
}
if addr := os.Getenv("XSF_ADDR"); addr != "" {
xsfAddr = addr
}
if config.Cfg.Leaf.Addr != "" {
xsfAddr = config.Cfg.Leaf.Addr
func Init() error {
if config.Cfg.App.IDGeneration.Leaf.Addr != "" {
addr = config.Cfg.App.IDGeneration.Leaf.Addr
}
config.Read(func(c *config.Config) {
if c.Leaf.ShowLog {
if c.App.IDGeneration.Leaf.ShowLog {
showLog = true
}
if c.Leaf.RetryCount > 0 {
retryCount = c.Leaf.RetryCount
if c.App.IDGeneration.Leaf.RetryCount > 0 {
retryCount = c.App.IDGeneration.Leaf.RetryCount
}
})
return nil
}
func GenerateID(ctx context.Context, bizTag string) (xsf.ID, error) {
if XSF_TYPE == "SF" {
if XSF_TYPE == "snowflake" {
return GenerateSFID(ctx, bizTag)
} else {
return GenerateApiID(ctx, bizTag)
......@@ -68,7 +62,7 @@ func GenerateSFID(ctx context.Context, bizTag string) (xsf.ID, error) {
}
func GenerateApiID(ctx context.Context, bizTag string) (xsf.ID, error) {
url := fmt.Sprintf(`%s/api/leaf?biz_tag=%s`, xsfAddr, bizTag)
url := fmt.Sprintf(`%s/api/leaf?biz_tag=%s`, addr, bizTag)
var id xsf.ID
reply := &IDReply{
Data: &id,
......
......@@ -9,6 +9,7 @@ import (
"time"
"github.com/bwmarrin/snowflake"
"gitlab.wanzhuangkj.com/tush/xpkg/config"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror"
)
......@@ -80,32 +81,49 @@ func (j JSONSyntaxError) Error() string {
}
// n [1,1023]
func init() {
var (
n int64
e error
)
if podName := os.Getenv("POD_NAME"); podName != "" {
parts := strings.Split(podName, "-")
if len(parts) == 2 {
lastPart := parts[len(parts)-1]
n, _ = strconv.ParseInt(lastPart, 10, 64)
}
}
if xsfNode := os.Getenv("XSF_NODE"); xsfNode != "" {
n, _ = strconv.ParseInt(xsfNode, 10, 64)
func Init() error {
n := getConfigN()
delta := getNodeFromPodName()
if delta > 0 {
n = n + delta
}
if n <= 0 {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
n = int64(r.Intn(1023) + 1)
n = getRandomN()
}
nod, e := snowflake.NewNode(n)
config.Write(func(c *config.Config) {
c.App.IDGeneration.Snowflake.Node = n
})
nod, e := snowflake.NewNode(int64(n))
if e != nil {
panic(e)
return e
}
node = nod
return nil
}
func getConfigN() int {
n := 0
config.Read(func(c *config.Config) {
n = c.App.Snowflake.Node
})
return n
}
func getRandomN() int {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
n := int(r.Intn(1023) + 1)
return n
}
func getNodeFromPodName() int {
if podName := os.Getenv("POD_NAME"); podName != "" {
parts := strings.Split(podName, "-")
if len(parts) == 2 {
lastPart := parts[len(parts)-1]
n, _ := strconv.ParseInt(lastPart, 10, 64)
return int(n)
}
}
return 0
}
func (x ID) String() string {
return snowflake.ID(x).String()
}
......
......@@ -110,7 +110,9 @@ func (x *cronJobController) CallOnceByCode(c *gin.Context) {
response.Success(c)
}
func Init(handlers map[string]Fn) error {
func Init(schema string, handlers map[string]Fn) error {
dao.Init(schema)
ctx := context.TODO()
TaskRegisterMaps = handlers
if !config.CronOpen() {
......
......@@ -6,11 +6,9 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/consts"
"gitlab.wanzhuangkj.com/tush/xpkg/database"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon/odao"
"gitlab.wanzhuangkj.com/tush/xpkg/xcron/cache"
"gitlab.wanzhuangkj.com/tush/xpkg/xcron/enums"
"gitlab.wanzhuangkj.com/tush/xpkg/xcron/models"
"gitlab.wanzhuangkj.com/tush/xpkg/eventbus"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror"
"golang.org/x/sync/singleflight"
......@@ -31,12 +29,6 @@ var CronJobDao = &cronJobDao{
},
}
func init() {
_ = eventbus.Eb.Subscribe(eventbus.TopicCacheInitFinish, func(ctx context.Context) {
CronJobDao.ODao.Cache = cache.NewCronJobCache(database.GetCacheType())
})
}
func (x *cronJobDao) GetByJobCode(ctx context.Context, jobCode string) (*models.CronJob, error) {
if jobCode == "" {
return nil, nil
......
package dao
import (
"context"
"gitlab.wanzhuangkj.com/tush/xpkg/database"
"gitlab.wanzhuangkj.com/tush/xpkg/eventbus"
"gitlab.wanzhuangkj.com/tush/xpkg/xcron/cache"
)
var (
Schema string
)
func Init(schema string) {
Schema = schema
_ = eventbus.Eb.Subscribe(eventbus.TopicCacheInitFinish, func(ctx context.Context) {
CronJobDao.ODao.Cache = cache.NewCronJobCache(database.GetCacheType())
})
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论