refactor: 对齐后端样例工程规范
This commit is contained in:
29
backend/iot/internal/config/config.go
Normal file
29
backend/iot/internal/config/config.go
Normal file
@@ -0,0 +1,29 @@
|
||||
// Package config 沿用 sample/server 的 BSM 运行配置与地址校验。
|
||||
package config
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/conf"
|
||||
)
|
||||
|
||||
// Spec 是 IoT 进程运行配置。
|
||||
var Spec SrvConfig
|
||||
|
||||
// SrvConfig 保持与 API 进程相同的 BSM 配置结构。
|
||||
type SrvConfig struct {
|
||||
conf.Base `yaml:",inline"`
|
||||
Databases *conf.DBConf `yaml:"Databases"`
|
||||
Rpc map[string]conf.RpcConf `yaml:"Rpc"`
|
||||
Apm *conf.ApmConf `yaml:"APM"`
|
||||
}
|
||||
|
||||
// New 初始化 IoT 进程配置。
|
||||
func New(srvKey string) {
|
||||
conf.New(srvKey, &Spec)
|
||||
Spec.Port = conf.CheckPort(Spec.Port)
|
||||
Spec.BindIP = conf.CheckIP(Spec.BindIP)
|
||||
Spec.Addr = net.JoinHostPort(Spec.BindIP, Spec.Port)
|
||||
conf.NotNil(Spec.Service, Spec.Cache)
|
||||
conf.PrintInfo(Spec.Addr)
|
||||
}
|
||||
25
backend/iot/internal/impl/new.go
Normal file
25
backend/iot/internal/impl/new.go
Normal file
@@ -0,0 +1,25 @@
|
||||
// Package impl 沿用 sample/server 创建 IoT 进程所需的基础设施实例。
|
||||
package impl
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/cache/redis"
|
||||
"git.apinb.com/bsm-sdk/core/logger"
|
||||
"git.apinb.com/bsm-sdk/core/with"
|
||||
"git.apinb.com/heqiapp/platforms/backend/iot/internal/config"
|
||||
"github.com/patrickmn/go-cache"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var (
|
||||
RedisService *redis.RedisClient
|
||||
DBService *gorm.DB
|
||||
MemoryService *cache.Cache
|
||||
)
|
||||
|
||||
// NewImpl 初始化 MQTT Mock 进程共用的数据库、缓存、Redis 与日志。
|
||||
func NewImpl() {
|
||||
MemoryService = with.Memory(nil)
|
||||
RedisService = with.RedisCache(config.Spec.Cache)
|
||||
DBService = with.Databases(config.Spec.Databases, nil)
|
||||
logger.New(nil)
|
||||
}
|
||||
Reference in New Issue
Block a user