68 lines
1.7 KiB
Go
68 lines
1.7 KiB
Go
package config
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
)
|
|
|
|
// Config 配置文件结构体
|
|
type Config struct {
|
|
Fluentd FluentdConfig `json:"fluentd"`
|
|
Elasticsearch ElasticsearchConfig `json:"elasticsearch"`
|
|
}
|
|
|
|
// FluentdConfig Fluentd 配置
|
|
type FluentdConfig struct {
|
|
URL string `json:"url"`
|
|
}
|
|
|
|
// ElasticsearchConfig Elasticsearch 配置
|
|
type ElasticsearchConfig struct {
|
|
URL string `json:"url"`
|
|
Auth AuthConfig `json:"auth"`
|
|
ILM ILMConfig `json:"ilm"`
|
|
}
|
|
|
|
// AuthConfig 认证信息
|
|
type AuthConfig struct {
|
|
Username string `json:"username"`
|
|
Password string `json:"password"`
|
|
}
|
|
|
|
// ILMConfig ILM 配置
|
|
type ILMConfig struct {
|
|
DataTypes map[string]DataTypeConfig `json:"data_types"`
|
|
}
|
|
|
|
// DataTypeConfig 每种数据类型的 ILM 配置
|
|
type TimeParameters struct {
|
|
TimestampFormat string `json:"timestamp_format"`
|
|
DefaultAfter string `json:"default_after"`
|
|
DefaultBefore string `json:"default_before"`
|
|
MaxRangeDays int `json:"max_range_days"`
|
|
}
|
|
|
|
type DataTypeConfig struct {
|
|
IndexPattern string `json:"index_pattern"`
|
|
MaxRetention map[string]int `json:"max_retention"`
|
|
MinRetention int `json:"min_retention"`
|
|
Shards int `json:"shards"`
|
|
Replicas int `json:"replicas"`
|
|
NormalRollover map[string]string `json:"normal_rollover"`
|
|
NormalPhases map[string]int `json:"normal_phases"`
|
|
TimeParameters TimeParameters `json:"time_parameters"`
|
|
}
|
|
|
|
// LoadConfig 加载配置文件
|
|
func LoadConfig(path string) (*Config, error) {
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var config Config
|
|
if err := json.Unmarshal(data, &config); err != nil {
|
|
return nil, err
|
|
}
|
|
return &config, nil
|
|
}
|