diff --git a/config/config.go b/config/config.go index 110de88..1dcbc91 100644 --- a/config/config.go +++ b/config/config.go @@ -6,10 +6,16 @@ import ( ) type Config struct { - FluentdURL string `json:"fluentdURL"` - ElasticsearchURL string `json:"ElasticsearchURL"` - ElasticsearchUser string `json:"ElasticsearchUser"` - ElasticsearchPassword string `json:"ElasticsearchPassword"` + Fluentd struct { + URL string `json:"url"` + } `json:"fluentd"` + Elasticsearch struct { + URL string `json:"url"` + Auth struct { + Username string `json:"username"` + Password string `json:"password"` + } `json:"auth"` + } `json:"elasticsearch"` } // LoadConfig 从指定路径加载配置文件 diff --git a/config/config.json b/config/config.json index ab5f889..c16da24 100644 --- a/config/config.json +++ b/config/config.json @@ -1,8 +1,14 @@ { - "fluentdURL": "http://fluentd.k8s.xunlang.home", - "ElasticsearchURL": "http://elastic.k8s.xunlang.home", - "ElasticsearchUser": "fluentd_user", - "ElasticsearchPassword": "fluentd_password" + "fluentd": { + "url": "http://fluentd.k8s.xunlang.home" + }, + "elasticsearch": { + "url": "http://elastic.k8s.xunlang.home", + "auth": { + "username": "fluentd_user", + "password": "fluentd_password" + } + } } diff --git a/okx/candleList.go b/okx/candleList.go index 48f9dec..30e1de4 100644 --- a/okx/candleList.go +++ b/okx/candleList.go @@ -239,7 +239,7 @@ func (cl *CandleList) ToFluentd() error { } // 构造完整URL,添加json参数 - fullURL := fmt.Sprintf("%s/%s?json", strings.TrimRight(config.FluentdURL, "/"), tag) + fullURL := fmt.Sprintf("%s/%s?json", strings.TrimRight(config.Fluentd.URL, "/"), tag) // 输出完整请求URL和请求体到日志 fmt.Printf("Sending request to URL: %s\n", fullURL) @@ -421,7 +421,7 @@ func (cl *CandleList) ToElastic() error { } // 构造完整URL - fullURL := fmt.Sprintf("%s/%s/_doc/%d", strings.TrimRight(config.ElasticsearchURL, "/"), index, ts) + fullURL := fmt.Sprintf("%s/%s/_doc/%d", strings.TrimRight(config.Elasticsearch.URL, "/"), index, ts) fmt.Println("fullURL: ", fullURL) // 创建请求 @@ -436,7 +436,7 @@ func (cl *CandleList) ToElastic() error { // 尝试从不同层级加载配置 // 设置基本认证 - req.SetBasicAuth(config.ElasticsearchUser, config.ElasticsearchPassword) + req.SetBasicAuth(config.Elasticsearch.Auth.Username, config.Elasticsearch.Auth.Password) // 发送HTTP请求 resp, err := client.Do(req)