feat: replace iot adapter with mqtt command pipeline
This commit is contained in:
44
backend/iot-client/internal/config/config.go
Normal file
44
backend/iot-client/internal/config/config.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gopkg.in/yaml.v3"
|
||||
"os"
|
||||
)
|
||||
|
||||
type HTTP struct {
|
||||
Address string `yaml:"Address"`
|
||||
InternalToken string `yaml:"InternalToken"`
|
||||
}
|
||||
type Upstream struct {
|
||||
IoTServerURL string `yaml:"IoTServerURL"`
|
||||
PlatformAPIURL string `yaml:"PlatformAPIURL"`
|
||||
Token string `yaml:"Token"`
|
||||
}
|
||||
type Config struct {
|
||||
Service string `yaml:"Service"`
|
||||
HTTP HTTP `yaml:"HTTP"`
|
||||
Upstream Upstream `yaml:"Upstream"`
|
||||
}
|
||||
|
||||
func Load(path string) (Config, error) {
|
||||
var cfg Config
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
if err = yaml.Unmarshal(data, &cfg); err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
override(&cfg.HTTP.InternalToken, "HEQI_IOT_INTERNAL_TOKEN")
|
||||
override(&cfg.Upstream.Token, "HEQI_IOT_INTERNAL_TOKEN")
|
||||
if cfg.HTTP.Address == "" || cfg.HTTP.InternalToken == "" || cfg.Upstream.IoTServerURL == "" || cfg.Upstream.PlatformAPIURL == "" {
|
||||
return cfg, fmt.Errorf("HTTP 和 Upstream 配置不完整")
|
||||
}
|
||||
return cfg, nil
|
||||
}
|
||||
func override(target *string, name string) {
|
||||
if value := os.Getenv(name); value != "" {
|
||||
*target = value
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user