Files
EdgeNode/internal/configs/api_config.go

43 lines
784 B
Go
Raw Normal View History

2020-07-22 22:18:47 +08:00
package configs
import (
"github.com/iwind/TeaGo/Tea"
2022-03-04 12:30:06 +08:00
"gopkg.in/yaml.v3"
2022-08-04 11:34:06 +08:00
"os"
2020-07-22 22:18:47 +08:00
)
2022-03-04 12:30:06 +08:00
// APIConfig 节点API配置
2020-07-22 22:18:47 +08:00
type APIConfig struct {
RPC struct {
Endpoints []string `yaml:"endpoints"`
DisableUpdate bool `yaml:"disableUpdate"`
2020-07-22 22:18:47 +08:00
} `yaml:"rpc"`
2020-09-09 18:53:53 +08:00
NodeId string `yaml:"nodeId"`
Secret string `yaml:"secret"`
2020-07-22 22:18:47 +08:00
}
func LoadAPIConfig() (*APIConfig, error) {
2022-08-04 11:34:06 +08:00
data, err := os.ReadFile(Tea.ConfigFile("api.yaml"))
2020-07-22 22:18:47 +08:00
if err != nil {
return nil, err
}
config := &APIConfig{}
err = yaml.Unmarshal(data, config)
if err != nil {
return nil, err
}
return config, nil
}
// WriteFile 保存到文件
func (this *APIConfig) WriteFile(path string) error {
data, err := yaml.Marshal(this)
if err != nil {
return err
}
2022-08-04 11:34:06 +08:00
err = os.WriteFile(path, data, 0666)
return err
}