优化API配置格式化

This commit is contained in:
GoEdgeLab
2023-08-12 18:16:17 +08:00
parent 415cf1130b
commit b41c7e2003
2 changed files with 10 additions and 3 deletions

View File

@@ -17,9 +17,9 @@ type APIConfig struct {
OldRPC struct { OldRPC struct {
Endpoints []string `yaml:"endpoints"` Endpoints []string `yaml:"endpoints"`
DisableUpdate bool `yaml:"disableUpdate"` DisableUpdate bool `yaml:"disableUpdate"`
} `yaml:"rpc"` } `yaml:"rpc,omitempty"`
RPCEndpoints []string `yaml:"rpc.endpoints" json:"rpc.endpoints"` RPCEndpoints []string `yaml:"rpc.endpoints,flow" json:"rpc.endpoints"`
RPCDisableUpdate bool `yaml:"rpc.disableUpdate" json:"rpc.disableUpdate"` RPCDisableUpdate bool `yaml:"rpc.disableUpdate" json:"rpc.disableUpdate"`
NodeId string `yaml:"nodeId"` NodeId string `yaml:"nodeId"`

View File

@@ -2,6 +2,7 @@ package configs
import ( import (
_ "github.com/iwind/TeaGo/bootstrap" _ "github.com/iwind/TeaGo/bootstrap"
"gopkg.in/yaml.v3"
"testing" "testing"
) )
@@ -11,10 +12,16 @@ func TestLoadAPIConfig(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
t.Log(config) t.Log(config)
configData, err := yaml.Marshal(config)
if err != nil {
t.Fatal(err)
}
t.Log(string(configData))
} }
func TestAPIConfig_WriteFile(t *testing.T) { func TestAPIConfig_WriteFile(t *testing.T) {
config := &APIConfig{} var config = &APIConfig{}
err := config.WriteFile("/tmp/api_config.yaml") err := config.WriteFile("/tmp/api_config.yaml")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)