deving
This commit is contained in:
@@ -4,22 +4,43 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.apinb.com/dataset/stock/internal/logic"
|
"git.apinb.com/dataset/stock/internal/logic"
|
||||||
|
"git.apinb.com/dataset/stock/internal/cron"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"git.apinb.com/bsm-sdk/core/infra"
|
||||||
|
"git.apinb.com/bsm-sdk/core/middleware"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ServiceKey = "folo"
|
ServiceKey = "stock"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
// 配置初始化
|
||||||
|
config.New(ServiceKey)
|
||||||
|
|
||||||
|
// 创建实现层
|
||||||
|
impl.NewImpl()
|
||||||
|
|
||||||
|
// starter crontab list
|
||||||
|
cron.Boot()
|
||||||
|
|
||||||
// 初始化Gin引擎
|
// 初始化Gin引擎
|
||||||
app := gin.Default()
|
app := gin.Default()
|
||||||
|
|
||||||
// use middleware
|
|
||||||
|
// 使用中间件
|
||||||
|
middleware.Mode(app)
|
||||||
|
app.Use(middleware.Cors())
|
||||||
app.Use(gin.Recovery())
|
app.Use(gin.Recovery())
|
||||||
|
|
||||||
|
// register health check
|
||||||
|
app.HEAD("/", infra.Health)
|
||||||
|
|
||||||
|
// register routers
|
||||||
|
routers.Register(ServiceKey, app)
|
||||||
|
|
||||||
// start
|
// start
|
||||||
err := app.Run(fmt.Sprintf(":%s", "15935"))
|
err := app.Run(fmt.Sprintf(":%s", config.Spec.Port))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
36
internal/config/config.go
Normal file
36
internal/config/config.go
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.apinb.com/bsm-sdk/core/conf"
|
||||||
|
"git.apinb.com/bsm-sdk/core/env"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
Spec SrvConfig
|
||||||
|
)
|
||||||
|
|
||||||
|
type SrvConfig struct {
|
||||||
|
conf.Base `yaml:",inline"`
|
||||||
|
Databases *conf.DBConf `yaml:"Databases"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(srvKey string) {
|
||||||
|
|
||||||
|
// 初始化通用配置 创建一个新的配置实例,用于服务配置
|
||||||
|
conf.New(srvKey, &Spec)
|
||||||
|
// 配置校验 服务端口如果不合规,则随机分配端口
|
||||||
|
Spec.Port = conf.CheckPort(Spec.Port)
|
||||||
|
|
||||||
|
// 初始化自定义环境变量
|
||||||
|
Spec.SecretKey = env.Runtime.JwtSecretKey
|
||||||
|
|
||||||
|
// InitRootUser 配置说明:
|
||||||
|
// 由于bool类型零值是false,如果配置文件中未设置该字段,默认值为false
|
||||||
|
// 为了保持向后兼容和默认启用初始化,我们采用以下策略:
|
||||||
|
// - 如果配置文件中显式设置为false,则禁用初始化
|
||||||
|
// - 如果配置文件中未设置或设置为true,则启用初始化
|
||||||
|
// 注意:InitRootUserData函数内部已有幂等性检查,重复执行是安全的
|
||||||
|
|
||||||
|
// 配置校验 服务名称地址及监听地址不能为空
|
||||||
|
conf.NotNil(Spec.Service, Spec.Cache)
|
||||||
|
}
|
||||||
5
internal/cron/boot.go
Normal file
5
internal/cron/boot.go
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package cron
|
||||||
|
|
||||||
|
func Boot(){
|
||||||
|
|
||||||
|
}
|
||||||
26
internal/impl/impl.go
Normal file
26
internal/impl/impl.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package impl
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.apinb.com/bsm-sdk/core/cache/redis"
|
||||||
|
"git.apinb.com/bsm-sdk/core/with"
|
||||||
|
"git.apinb.com/pro/rbac2/internal/config"
|
||||||
|
"github.com/allegro/bigcache/v3"
|
||||||
|
"git.apinb.com/bsm-sdk/core/with"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
RedisService *redis.RedisClient // Redis 客户端服务
|
||||||
|
MemoryService *bigcache.BigCache // 内存缓存服务
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewImpl 初始化各类服务实例
|
||||||
|
func NewImpl() {
|
||||||
|
// 初始化内存缓存
|
||||||
|
MemorySerice = with.Memory(nil)
|
||||||
|
// 初始化 Redis 缓存
|
||||||
|
RedisService = with.RedisCache(config.Spec.Cache)
|
||||||
|
// 初始化数据库服务
|
||||||
|
DBService = with.Databases(config.Spec.Databases, nil) // model
|
||||||
|
// 初始化日志服务
|
||||||
|
with.Logger(config.Spec.Log)
|
||||||
|
}
|
||||||
11
internal/logic/a.go
Normal file
11
internal/logic/a.go
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import tushare "github.com/ShawnRong/tushare-go"
|
||||||
|
|
||||||
|
var (
|
||||||
|
TushareClient *tushare.TuShare
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewApiClient(){
|
||||||
|
TushareClient = tushare.New("你的token")
|
||||||
|
}
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package logic
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Hook(ctx *gin.Context) {
|
|
||||||
fmt.Println("BODY:")
|
|
||||||
reqBody, _ := io.ReadAll(ctx.Request.Body)
|
|
||||||
fmt.Println(string(reqBody))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
1
internal/models/query.go
Normal file
1
internal/models/query.go
Normal file
@@ -0,0 +1 @@
|
|||||||
|
package models
|
||||||
37
internal/routers/register.go
Normal file
37
internal/routers/register.go
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
package routers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"git.apinb.com/bsm-sdk/core/middleware"
|
||||||
|
"git.apinb.com/pro/rbac2/internal/logic/application"
|
||||||
|
"git.apinb.com/pro/rbac2/internal/logic/hello"
|
||||||
|
"git.apinb.com/pro/rbac2/internal/logic/permission"
|
||||||
|
"git.apinb.com/pro/rbac2/internal/logic/pub"
|
||||||
|
"git.apinb.com/pro/rbac2/internal/logic/role"
|
||||||
|
"git.apinb.com/pro/rbac2/internal/logic/user"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 完成请求地址: ip:port/srvKey/v1/group/xxx
|
||||||
|
func Register(srvKey string, engine *gin.Engine) {
|
||||||
|
v1_key := fmt.Sprintf("/%s/%s", srvKey, "v1")
|
||||||
|
registerAnonymous(v1_key, engine)
|
||||||
|
registerRouters(v1_key, engine)
|
||||||
|
}
|
||||||
|
|
||||||
|
// registerAnonymous 不需要auth的接口
|
||||||
|
func registerAnonymous(v1_key string, engine *gin.Engine) {
|
||||||
|
// Anonymous router.
|
||||||
|
fmt.Println(v1_key)
|
||||||
|
anonymous := engine.Group(v1_key)
|
||||||
|
{
|
||||||
|
anonymous.GET("/ping", hello.Ping)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func registerRouters(v1_key string, engine *gin.Engine) {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user