区分环境

This commit is contained in:
2024-10-02 11:27:51 +08:00
parent ab842d8694
commit b8d9a72dac
30 changed files with 626 additions and 181 deletions

View File

@@ -3,6 +3,7 @@ package main
import (
"flag"
"fmt"
"os"
"tianyuan-api/apps/admin/internal/config"
"tianyuan-api/apps/admin/internal/handler"
@@ -12,9 +13,23 @@ import (
"github.com/zeromicro/go-zero/rest"
)
var configFile = flag.String("f", "etc/admin-api.yaml", "the config file")
func main() {
// 读取环境变量 ENV默认为 "prod"
env := os.Getenv("ENV")
if env == "" {
env = "production"
}
// 根据 ENV 加载不同的配置文件
var defaultConfigFile string
if env == "development" {
defaultConfigFile = "etc/admin-api.dev.yaml" // 开发环境配置
} else {
defaultConfigFile = "etc/admin-api.yaml" // 生产环境配置
}
// 允许通过命令行参数覆盖配置文件路径
configFile := flag.String("f", defaultConfigFile, "the config file")
flag.Parse()
var c config.Config

View File

@@ -0,0 +1,22 @@
Name: admin-api
Host: 0.0.0.0
Port: 10002
DataSource: "tianyuanapi:g3h98u0291j@tcp(127.0.0.1:3307)/tianyuanapi?charset=utf8mb4&parseTime=True&loc=Local"
AuthJWT:
AccessSecret: "Mf5Xph3PoyKzVpRw0Zy1+X4uR/tM7JvGMEV/5p2M/tU="
AccessExpire: 86400 # JWT过期时间
CacheRedis:
- Host: "127.0.0.1:6379"
Pass: "" # Redis 密码,如果未设置则留空
Type: "node" # 单节点模式
UserRpc:
Etcd:
Hosts:
- 127.0.0.1:2379
Key: user.rpc
SentinelRpc:
Etcd:
Hosts:
- 127.0.0.1:2379
Key: sentinel.rpc

View File

@@ -1,22 +1,22 @@
Name: admin-api
Host: 0.0.0.0
Port: 10002
DataSource: "tianyuanapi:g3h98u0291j@tcp(127.0.0.1:3307)/tianyuanapi?charset=utf8mb4&parseTime=True&loc=Local"
DataSource: "tianyuanapi:g3h98u0291j@tcp(tyapi_mysql:3306)/tianyuanapi?charset=utf8mb4&parseTime=True&loc=Local"
AuthJWT:
AccessSecret: "Mf5Xph3PoyKzVpRw0Zy1+X4uR/tM7JvGMEV/5p2M/tU="
AccessExpire: 86400 # JWT过期时间
CacheRedis:
- Host: "127.0.0.1:6379"
- Host: "tyapi_redis:6379"
Pass: "" # Redis 密码,如果未设置则留空
Type: "node" # 单节点模式
UserRpc:
Etcd:
Hosts:
- 127.0.0.1:2379
- tyapi_etcd:2379
Key: user.rpc
SentinelRpc:
Etcd:
Hosts:
- 127.0.0.1:2379
- tyapi_etcd:2379
Key: sentinel.rpc

View File

@@ -97,9 +97,6 @@ service api-api {
@handler QYGL6F2D
post /QYGL6F2D (request) returns (response)
@handler QYGL51BC
post /QYGL51BC (request) returns (response)
}
@server (
@@ -145,10 +142,5 @@ service api-api {
@handler JRZQ4AA8
post /JRZQ4AA8 (request) returns (response)
@handler JRZQCEE8
post /JRZQCEE8 (request) returns (response)
@handler JRZQFEF8
post /JRZQFEF8 (request) returns (response)
}

View File

@@ -3,6 +3,7 @@ package main
import (
"flag"
"fmt"
"os"
"tianyuan-api/apps/api/internal/config"
"tianyuan-api/apps/api/internal/handler"
@@ -12,9 +13,23 @@ import (
"github.com/zeromicro/go-zero/rest"
)
var configFile = flag.String("f", "etc/api-api.yaml", "the config file")
func main() {
// 读取环境变量 ENV默认为 "prod"
env := os.Getenv("ENV")
if env == "" {
env = "production"
}
// 根据 ENV 加载不同的配置文件
var defaultConfigFile string
if env == "development" {
defaultConfigFile = "etc/api-api.dev.yaml" // 开发环境配置
} else {
defaultConfigFile = "etc/api-api.yaml" // 生产环境配置
}
// 允许通过命令行参数覆盖配置文件路径
configFile := flag.String("f", defaultConfigFile, "the config file")
flag.Parse()
var c config.Config

View File

@@ -1,51 +0,0 @@
syntax = "proto3";
package product;
option go_package = "./api";
service ProductService {
// 获取产品列表
rpc GetProducts(ProductListReq) returns (ProductListResp);
// 获取用户开通的产品列表
rpc GetUserProducts(UserProductListReq) returns (UserProductListResp);
}
// 获取产品列表的请求
message ProductListReq {}
// 获取产品列表的响应
message ProductListResp {
repeated ProductItem products = 1;
}
// 产品信息
message ProductItem {
int64 id = 1; // 产品ID
string product_name = 2; // 产品名称
string product_code = 3; // 产品编号
string product_description = 4; // 产品简介
string product_content = 5; // 产品内容
float product_price = 6; // 产品价格
string created_at = 7; // 产品创建时间
}
// 获取用户开通的产品列表的请求
message UserProductListReq {
int64 user_id = 1; // 用户ID
}
// 获取用户开通的产品列表的响应
message UserProductListResp {
repeated UserProductItem user_products = 1;
}
// 用户产品信息
message UserProductItem {
int64 id = 1; // 用户产品ID
int64 user_id = 2; // 用户ID
int64 product_id = 3; // 产品ID
string activation_date = 4; // 激活时间
string expiration_date = 5; // 到期时间
}

View File

@@ -0,0 +1,20 @@
Name: api-api
Host: 0.0.0.0
Port: 10003
DataSource: "tianyuanapi:g3h98u0291j@tcp(127.0.0.1:3307)/tianyuanapi?charset=utf8mb4&parseTime=True&loc=Local"
CacheRedis:
- Host: "127.0.0.1:6379"
Pass: "" # Redis 密码,如果未设置则留空
Type: "node" # 单节点模式
SentinelRpc:
Etcd:
Hosts:
- 127.0.0.1:2379
Key: sentinel.rpc
KqPusherConf:
Brokers:
- 127.0.0.1:9092
Topic: apirequest
WestConfig:
Key: "121a1e41fc1690dd6b90afbcacd80cf4"
SecretId: "449159"

View File

@@ -1,19 +1,19 @@
Name: api-api
Host: 0.0.0.0
Port: 10003
DataSource: "tianyuanapi:g3h98u0291j@tcp(127.0.0.1:3307)/tianyuanapi?charset=utf8mb4&parseTime=True&loc=Local"
DataSource: "tianyuanapi:g3h98u0291j@tcp(tyapi_mysql:3306)/tianyuanapi?charset=utf8mb4&parseTime=True&loc=Local"
CacheRedis:
- Host: "127.0.0.1:6379"
- Host: "tyapi_redis:6379"
Pass: "" # Redis 密码,如果未设置则留空
Type: "node" # 单节点模式
SentinelRpc:
Etcd:
Hosts:
- 127.0.0.1:2379
- tyapi_etcd:2379
Key: sentinel.rpc
KqPusherConf:
Brokers:
- 127.0.0.1:9092
- tyapi_kafka:9092
Topic: apirequest
WestConfig:
key: "121a1e41fc1690dd6b90afbcacd80cf4"

View File

@@ -2,6 +2,10 @@ package IVYZ
import (
"context"
"encoding/hex"
"errors"
"tianyuan-api/apps/api/internal/validator"
"tianyuan-api/pkg/crypto"
"tianyuan-api/apps/api/internal/svc"
"tianyuan-api/apps/api/internal/types"
@@ -24,7 +28,59 @@ func NewIVYZ5733Logic(ctx context.Context, svcCtx *svc.ServiceContext) *IVYZ5733
}
func (l *IVYZ5733Logic) IVYZ5733(req *types.Request) (resp *types.Response, err error) {
// todo: add your logic here and delete this line
//userId, ok := l.ctx.Value("userId").(int64)
//if !ok {
// return &types.Response{}, errors.New("系统错误,请联系管理员")
//}
secretKey, ok := l.ctx.Value("secretKey").(string)
if !ok {
return &types.Response{}, errors.New("系统错误,请联系管理员")
}
return
// 1、解密
key, err := hex.DecodeString(secretKey)
decryptData, err := crypto.AesDecrypt(req.Data, key)
if err != nil || len(decryptData) == 0 {
return nil, errors.New("参数解密失败")
}
// 2、校验
var data validator.IVYZ5733Request
if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil {
return nil, validatorErr
}
// 3、西部加密
westConfig := l.svcCtx.Config.WestConfig
name, err := crypto.WestDexEncrypt(data.Name, westConfig.Key)
if err != nil {
logx.Errorf("西部加密错误:%v", err)
return nil, errors.New("业务异常")
}
idCard, err := crypto.WestDexEncrypt(data.IDCard, westConfig.Key)
if err != nil {
logx.Errorf("西部加密错误:%v", err)
return nil, errors.New("业务异常")
}
// 4、发送请求到西部
westdexRequest := map[string]interface{}{
"id": idCard,
"name": name,
}
westResp, err := l.svcCtx.WestDexService.CallAPI("G09GX01", westdexRequest)
if err != nil {
return nil, err
}
// 5、响应解析
//var respData westmodel.G09GX01Response
//unmarshalErr := json.Unmarshal(westResp, &respData)
//if unmarshalErr != nil {
// return nil, unmarshalErr
//}
//crypto.AesEncrypt()
return &types.Response{
Data: string(westResp),
}, nil
}

View File

@@ -21,7 +21,7 @@ type FLXG3D56Request struct {
Name string `json:"name" validate:"required,min=1,validName"`
TimeRange string `json:"time_range" validate:"omitempty,validTimeRange"` // 非必填字段
}
type YYSYf7dbRequest struct {
MobileNo
StartDate
type IVYZ5733Request struct {
Name string `json:"name" validate:"required,min=1,validName"`
IDCard string `json:"id_card" validate:"required,validIDCard"`
}

View File

@@ -0,0 +1,38 @@
Name: gateway-api
Host: 0.0.0.0
Port: 10001
DataSource: "tianyuanapi:g3h98u0291j@tcp(127.0.0.1:3307)/tianyuanapi?charset=utf8mb4&parseTime=True&loc=Local"
AuthJWT:
AccessSecret: "Mf5Xph3PoyKzVpRw0Zy1+X4uR/tM7JvGMEV/5p2M/tU="
AccessExpire: 86400 # JWT过期时间
CacheRedis:
- Host: "127.0.0.1:6379"
Pass: "" # Redis 密码,如果未设置则留空
Type: "node" # 单节点模式
VerifyCode:
AccessKeyID: "LTAI5tHKcV1RbC8t68UfsATy"
AccessKeySecret: "wLWjMBnAlchFMa9gC8B7ZVBKaew4t5"
EndpointURL: "dysmsapi.aliyuncs.com"
SignName: "天远查"
TemplateCode: "SMS_299200388"
ValidTime: 300
Qiniu:
AccessKey: "AO6u6sDWi6L9TsPfr4awC7FYP85JTjt3bodZACCM"
SecretKey: "2fjxweGtSAEaUdVgDkWEmN7JbBxHBQDv1cLORb9_"
Bucket: "tianyuanapi"
Domain: "https://file.tianyuanapi.com"
Baidu:
ApiKey: "aMsrBNGUJxgcgqdm3SEdcumm"
SecretKey: "sWlv2h2AWA3aAt5bjXCkE6WeA5AzpAAD"
UserRpc:
Etcd:
Hosts:
- 127.0.0.1:2379
Key: user.rpc
SentinelRpc:
Etcd:
Hosts:
- 127.0.0.1:2379
Key: sentinel.rpc

View File

@@ -1,12 +1,12 @@
Name: gateway-api
Host: 0.0.0.0
Port: 10001
DataSource: "tianyuanapi:g3h98u0291j@tcp(127.0.0.1:3307)/tianyuanapi?charset=utf8mb4&parseTime=True&loc=Local"
DataSource: "tianyuanapi:g3h98u0291j@tcp(tyapi_mysql:3306)/tianyuanapi?charset=utf8mb4&parseTime=True&loc=Local"
AuthJWT:
AccessSecret: "Mf5Xph3PoyKzVpRw0Zy1+X4uR/tM7JvGMEV/5p2M/tU="
AccessExpire: 86400 # JWT过期时间
CacheRedis:
- Host: "127.0.0.1:6379"
- Host: "tyapi_redis:6379"
Pass: "" # Redis 密码,如果未设置则留空
Type: "node" # 单节点模式
VerifyCode:
@@ -29,10 +29,10 @@ Baidu:
UserRpc:
Etcd:
Hosts:
- 127.0.0.1:2379
- tyapi_etcd:2379
Key: user.rpc
SentinelRpc:
Etcd:
Hosts:
- 127.0.0.1:2379
- tyapi_etcd:2379
Key: sentinel.rpc

View File

@@ -3,6 +3,7 @@ package main
import (
"flag"
"fmt"
"os"
"tianyuan-api/apps/gateway/internal/config"
"tianyuan-api/apps/gateway/internal/handler"
@@ -12,9 +13,23 @@ import (
"github.com/zeromicro/go-zero/rest"
)
var configFile = flag.String("f", "etc/gateway-api.yaml", "the config file")
func main() {
// 读取环境变量 ENV默认为 "prod"
env := os.Getenv("ENV")
if env == "" {
env = "production"
}
// 根据 ENV 加载不同的配置文件
var defaultConfigFile string
if env == "development" {
defaultConfigFile = "etc/gateway-api.dev.yaml" // 开发环境配置
} else {
defaultConfigFile = "etc/gateway-api.yaml" // 生产环境配置
}
// 允许通过命令行参数覆盖配置文件路径
configFile := flag.String("f", defaultConfigFile, "the config file")
flag.Parse()
var c config.Config

25
apps/mqs/etc/mqs.dev.yaml Normal file
View File

@@ -0,0 +1,25 @@
Name: mq
Host: 0.0.0.0
Port: 12001
# kq 消费者组1 - 用于记录
KqConsumerLog:
Name: kqConsumerLog
Brokers:
- 127.0.0.1:9092
Group: logGroup
Topic: apirequest
Offset: first
Consumers: 2 # 为了避免资源争夺分配2个消费者
Processors: 2
# kq 消费者组2 - 用于扣款
KqConsumerCharge:
Name: kqConsumerCharge
Brokers:
- 127.0.0.1:9092
Group: chargeGroup
Topic: apirequest
Offset: first
Consumers: 2 # 同样分配2个消费者
Processors: 2

View File

@@ -6,7 +6,7 @@ Port: 12001
KqConsumerLog:
Name: kqConsumerLog
Brokers:
- 127.0.0.1:9092
- tyapi_kafka:9092
Group: logGroup
Topic: apirequest
Offset: first
@@ -17,7 +17,7 @@ KqConsumerLog:
KqConsumerCharge:
Name: kqConsumerCharge
Brokers:
- 127.0.0.1:9092
- tyapi_kafka:9092
Group: chargeGroup
Topic: apirequest
Offset: first

View File

@@ -4,6 +4,7 @@ import (
"context"
"flag"
"github.com/zeromicro/go-zero/core/service"
"os"
"tianyuan-api/apps/mqs/internal/config"
"tianyuan-api/apps/mqs/internal/mqs"
"tianyuan-api/apps/mqs/internal/svc"
@@ -12,9 +13,23 @@ import (
"github.com/zeromicro/go-zero/rest"
)
var configFile = flag.String("f", "etc/mqs.yaml", "the config file")
func main() {
// 读取环境变量 ENV默认为 "prod"
env := os.Getenv("ENV")
if env == "" {
env = "production"
}
// 根据 ENV 加载不同的配置文件
var defaultConfigFile string
if env == "development" {
defaultConfigFile = "etc/mqs.dev.yaml" // 开发环境配置
} else {
defaultConfigFile = "etc/mqs.yaml" // 生产环境配置
}
// 允许通过命令行参数覆盖配置文件路径
configFile := flag.String("f", defaultConfigFile, "the config file")
flag.Parse()
var c config.Config

View File

@@ -0,0 +1,11 @@
Name: sentinel.rpc
ListenOn: 0.0.0.0:11002
Etcd:
Hosts:
- 127.0.0.1:2379
Key: sentinel.rpc
DataSource: "tianyuanapi:g3h98u0291j@tcp(127.0.0.1:3307)/tianyuanapi?charset=utf8mb4&parseTime=True&loc=Local"
CacheRedis:
- Host: "127.0.0.1:6379"
Pass: "" # Redis 密码,如果未设置则留空
Type: "node" # 单节点模式

View File

@@ -2,10 +2,10 @@ Name: sentinel.rpc
ListenOn: 0.0.0.0:11002
Etcd:
Hosts:
- 127.0.0.1:2379
- tyapi_etcd:2379
Key: sentinel.rpc
DataSource: "tianyuanapi:g3h98u0291j@tcp(127.0.0.1:3307)/tianyuanapi?charset=utf8mb4&parseTime=True&loc=Local"
DataSource: "tianyuanapi:g3h98u0291j@tcp(tyapi_mysql:3306)/tianyuanapi?charset=utf8mb4&parseTime=True&loc=Local"
CacheRedis:
- Host: "127.0.0.1:6379"
- Host: "tyapi_redis:6379"
Pass: "" # Redis 密码,如果未设置则留空
Type: "node" # 单节点模式

View File

@@ -3,6 +3,7 @@ package main
import (
"flag"
"fmt"
"os"
"tianyuan-api/apps/sentinel/internal/config"
productServer "tianyuan-api/apps/sentinel/internal/server/product"
@@ -19,9 +20,23 @@ import (
"google.golang.org/grpc/reflection"
)
var configFile = flag.String("f", "etc/sentinel.yaml", "the config file")
func main() {
// 读取环境变量 ENV默认为 "prod"
env := os.Getenv("ENV")
if env == "" {
env = "production"
}
// 根据 ENV 加载不同的配置文件
var defaultConfigFile string
if env == "development" {
defaultConfigFile = "etc/sentinel.dev.yaml" // 开发环境配置
} else {
defaultConfigFile = "etc/sentinel.yaml" // 生产环境配置
}
// 允许通过命令行参数覆盖配置文件路径
configFile := flag.String("f", defaultConfigFile, "the config file")
flag.Parse()
var c config.Config

View File

@@ -0,0 +1,19 @@
Name: user.rpc
ListenOn: 0.0.0.0:11001
Etcd:
Hosts:
- 127.0.0.1:2379
Key: user.rpc
DataSource: "tianyuanapi:g3h98u0291j@tcp(127.0.0.1:3307)/tianyuanapi?charset=utf8mb4&parseTime=True&loc=Local"
AuthJWT:
AccessSecret: "Mf5Xph3PoyKzVpRw0Zy1+X4uR/tM7JvGMEV/5p2M/tU="
AccessExpire: 86400 # JWT过期时间
CacheRedis:
- Host: "127.0.0.1:6379"
Pass: "" # Redis 密码,如果未设置则留空
Type: "node" # 单节点模式
SentinelRpc:
Etcd:
Hosts:
- 127.0.0.1:2379
Key: sentinel.rpc

View File

@@ -2,18 +2,18 @@ Name: user.rpc
ListenOn: 0.0.0.0:11001
Etcd:
Hosts:
- 127.0.0.1:2379
- tyapi_etcd:2379
Key: user.rpc
DataSource: "tianyuanapi:g3h98u0291j@tcp(127.0.0.1:3307)/tianyuanapi?charset=utf8mb4&parseTime=True&loc=Local"
DataSource: "tianyuanapi:g3h98u0291j@tcp(tyapi_mysql:3306)/tianyuanapi?charset=utf8mb4&parseTime=True&loc=Local"
AuthJWT:
AccessSecret: "Mf5Xph3PoyKzVpRw0Zy1+X4uR/tM7JvGMEV/5p2M/tU="
AccessExpire: 86400 # JWT过期时间
CacheRedis:
- Host: "127.0.0.1:6379"
- Host: "tyapi_redis:6379"
Pass: "" # Redis 密码,如果未设置则留空
Type: "node" # 单节点模式
SentinelRpc:
Etcd:
Hosts:
- 127.0.0.1:2379
- tyapi_etcd:2379
Key: sentinel.rpc

View File

@@ -24,7 +24,7 @@ func NewGetPendingEnterpriseLogic(ctx context.Context, svcCtx *svc.ServiceContex
}
// 获取待审核企业列表
func (l *GetPendingEnterpriseLogic) GetPendingEnterprise() (*user.GetPendingEnterpriseResp, error) {
func (l *GetPendingEnterpriseLogic) GetPendingEnterprise(in *user.GetPendingEnterpriseReq) (*user.GetPendingEnterpriseResp, error) {
// 调用 Model 层获取待审核企业列表
enterprises, total, err := l.svcCtx.EnterpriseAuthModel.FindPendingList(l.ctx, in.Page, in.PageSize)
if err != nil {

View File

@@ -26,7 +26,7 @@ func NewEnterpriseServer(svcCtx *svc.ServiceContext) *EnterpriseServer {
// 获取待审核企业列表
func (s *EnterpriseServer) GetPendingEnterprise(ctx context.Context, in *user.GetPendingEnterpriseReq) (*user.GetPendingEnterpriseResp, error) {
l := enterpriselogic.NewGetPendingEnterpriseLogic(ctx, s.svcCtx)
return l.GetPendingEnterprise()
return l.GetPendingEnterprise(in)
}
// 审核企业

View File

@@ -3,6 +3,7 @@ package main
import (
"flag"
"fmt"
"os"
"tianyuan-api/apps/user/internal/config"
authServer "tianyuan-api/apps/user/internal/server/auth"
@@ -18,9 +19,23 @@ import (
"google.golang.org/grpc/reflection"
)
var configFile = flag.String("f", "etc/user.yaml", "the config file")
func main() {
// 读取环境变量 ENV默认为 "prod"
env := os.Getenv("ENV")
if env == "" {
env = "production"
}
// 根据 ENV 加载不同的配置文件
var defaultConfigFile string
if env == "development" {
defaultConfigFile = "etc/user.dev.yaml" // 开发环境配置
} else {
defaultConfigFile = "etc/user.yaml" // 生产环境配置
}
// 允许通过命令行参数覆盖配置文件路径
configFile := flag.String("f", defaultConfigFile, "the config file")
flag.Parse()
var c config.Config