4e2cd43a55
iotlcm-onelink-mock:OneLink 挡板服务(本地测试替身)。 - Go module 迁移至 git.5iot.com/iotlcm-public/iotlcm-onelink-mock - 修复同毫秒内多次生成卡导致 ICCID/IMSI 唯一约束冲突 - 补 Apache-2.0 LICENSE,README 重写并新增 docs/deploy.md - 移除内部部署资产(CI 触发器 / 镜像推送脚本 / 指定环境部署文档) - 测试凭据改为 demo_appid / demo_password,真实手机号与内网 IP 脱敏 - 统一 LF 行尾并加 .gitattributes
46 lines
1.4 KiB
Go
46 lines
1.4 KiB
Go
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
|
|
"git.5iot.com/iotlcm-public/iotlcm-onelink-mock/internal/controller/gateway"
|
|
"git.5iot.com/iotlcm-public/iotlcm-onelink-mock/internal/service"
|
|
"github.com/gogf/gf/v2/errors/gerror"
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
"github.com/gogf/gf/v2/os/gcmd"
|
|
)
|
|
|
|
var Main = gcmd.Command{
|
|
Name: "main",
|
|
Usage: "main",
|
|
Brief: "start OneLink mock service",
|
|
Func: func(ctx context.Context, parser *gcmd.Parser) error {
|
|
var (
|
|
server = g.Server()
|
|
runtimeLogCapacity = g.Cfg().MustGet(ctx, "runtimeLog.capacity", 500).Int()
|
|
runtimeLogs = service.NewRuntimeLogStore(runtimeLogCapacity)
|
|
databaseLink = g.Cfg().MustGet(ctx, "database.default.link", "sqlite::@file(data/onelink_mock.db)").String()
|
|
)
|
|
if value := os.Getenv("BAFFLE_ADDR"); value != "" {
|
|
server.SetAddr(value)
|
|
}
|
|
if value := os.Getenv("BAFFLE_SQLITE_PATH"); value != "" {
|
|
databaseLink = value
|
|
}
|
|
g.Log().SetWriter(runtimeLogs)
|
|
g.Log().SetWriterColorEnable(false)
|
|
server.Logger().SetWriter(runtimeLogs)
|
|
server.Logger().SetWriterColorEnable(false)
|
|
|
|
mockService, err := service.NewService(databaseLink, runtimeLogs)
|
|
if err != nil {
|
|
return gerror.Wrap(err, "initialize mock service")
|
|
}
|
|
gateway.New(mockService).Register(server)
|
|
g.Log().Infof(ctx, "OneLink mock service listening on %s", server.GetListenedAddress())
|
|
server.Run()
|
|
return nil
|
|
},
|
|
}
|