-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove viper config manage which set all map key to lowercase
- Loading branch information
Showing
2 changed files
with
108 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
type InspServerConfig struct { | ||
DebugMode bool `yaml:"debugmode" mapstructure:"debugmode" json:"debugmode"` | ||
Port uint16 `yaml:"port" mapstructure:"port" json:"port"` | ||
EnableController bool `yaml:"enable_controller" mapstructure:"enable_controller" json:"enable_controller"` | ||
MetricsConfig MetricsConfig `yaml:"metrics" mapstructure:"metrics" json:"metrics"` | ||
EventConfig EventConfig `yaml:"event" mapstructure:"event" json:"event"` | ||
} | ||
|
||
type MetricsConfig struct { | ||
Probes []ProbeConfig `yaml:"probes" mapstructure:"probes" json:"probes"` | ||
} | ||
|
||
type EventConfig struct { | ||
EventSinks []EventSinkConfig `yaml:"sinks" mapstructure:"sinks" json:"sinks"` | ||
Probes []ProbeConfig `yaml:"probes" mapstructure:"probes" json:"probes"` | ||
} | ||
|
||
type EventSinkConfig struct { | ||
Name string `yaml:"name" mapstructure:"name" json:"name"` | ||
Args interface{} `yaml:"args" mapstructure:"args" json:"args"` | ||
} | ||
|
||
type ProbeConfig struct { | ||
Name string `yaml:"name" mapstructure:"name" json:"name"` | ||
Args map[string]interface{} `yaml:"args" mapstructure:"args" json:"args"` | ||
} | ||
|
||
func loadConfig(path string) (*InspServerConfig, error) { | ||
cfg := InspServerConfig{} | ||
data, err := os.ReadFile(path) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed read config file %s: %w", path, err) | ||
} | ||
|
||
if err = yaml.Unmarshal(data, &cfg); err != nil { | ||
return nil, fmt.Errorf("failed parse config file %s: %w", path, err) | ||
} | ||
|
||
return &cfg, nil | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters