5732bf3384
iotlcm-bot:独立飞书应用机器人(读取 Worker 终态 Run JSON,渲染并发送全量同步结果卡片)。
- Go module:git.5iot.com/iotlcm/iotlcm-bot → git.5iot.com/iotlcm-public/iotlcm-bot
- 飞书凭据占位:appId/appSecret/chatId → ${FEISHU_APP_ID}/${FEISHU_APP_SECRET}/${FEISHU_CHAT_ID}
- 移除内部资产:CI 触发器
- Dockerfile 改用公共基础镜像(golang:1.25-alpine → scratch)
- README 重写(命令/配置/挂载契约/常见问题),去掉内部环境路径
- 补 Apache-2.0 LICENSE,LF 行尾 + .gitattributes
64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
type Config struct {
|
|
Environment string `yaml:"environment"`
|
|
ArchiveDir string `yaml:"archiveDir"`
|
|
StateDir string `yaml:"stateDir"`
|
|
PollInterval string `yaml:"pollInterval"`
|
|
Feishu FeishuConfig `yaml:"feishu"`
|
|
|
|
PollDuration time.Duration `yaml:"-"`
|
|
}
|
|
|
|
type FeishuConfig struct {
|
|
AppID string `yaml:"appId"`
|
|
AppSecret string `yaml:"appSecret"`
|
|
ChatID string `yaml:"chatId"`
|
|
}
|
|
|
|
func Load(path string) (Config, error) {
|
|
body, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return Config{}, fmt.Errorf("read config %s: %w", path, err)
|
|
}
|
|
var cfg Config
|
|
if err := yaml.Unmarshal(body, &cfg); err != nil {
|
|
return Config{}, fmt.Errorf("parse config %s: %w", path, err)
|
|
}
|
|
if cfg.Environment == "" {
|
|
cfg.Environment = "preview"
|
|
}
|
|
if cfg.ArchiveDir == "" {
|
|
cfg.ArchiveDir = "/data/full-sync"
|
|
}
|
|
if cfg.StateDir == "" {
|
|
cfg.StateDir = "/data/state"
|
|
}
|
|
if cfg.PollInterval == "" {
|
|
cfg.PollInterval = "10s"
|
|
}
|
|
cfg.PollDuration, err = time.ParseDuration(cfg.PollInterval)
|
|
if err != nil || cfg.PollDuration <= 0 {
|
|
return Config{}, fmt.Errorf("invalid pollInterval %q", cfg.PollInterval)
|
|
}
|
|
return cfg, nil
|
|
}
|
|
|
|
func (c Config) ValidateSend() error {
|
|
if c.Feishu.AppID == "" || c.Feishu.AppSecret == "" {
|
|
return fmt.Errorf("feishu.appId and feishu.appSecret are required")
|
|
}
|
|
if c.Feishu.ChatID == "" {
|
|
return fmt.Errorf("feishu.chatId is required")
|
|
}
|
|
return nil
|
|
}
|