44 lines
930 B
Go
44 lines
930 B
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/pelletier/go-toml/v2"
|
|
)
|
|
|
|
type StepMonitor struct {
|
|
Enabled bool `toml:"Enabled"`
|
|
BaseURL string `toml:"BaseURL"`
|
|
RootID string `toml:"RootID"`
|
|
}
|
|
|
|
type TLSConnectionMonitor struct {
|
|
Enabled bool `toml:"Enabled"`
|
|
Address string `toml:"Address"`
|
|
Verify bool `toml:"Verify"`
|
|
ExtraCAPaths []string `toml:"ExtraCAPaths"`
|
|
Duration string `toml:"Duration"`
|
|
}
|
|
|
|
type Config struct {
|
|
ListenAddr string `toml:"ListenAddr"`
|
|
StepMonitors []StepMonitor `toml:"StepMonitors"`
|
|
TLSConnectionMonitors []TLSConnectionMonitor `toml:"TLSConnectionMonitors"`
|
|
}
|
|
|
|
func FromFile(file string) (*Config, error) {
|
|
var config Config
|
|
|
|
f, err := os.Open(file)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
decoder := toml.NewDecoder(f)
|
|
|
|
if err := decoder.Decode(&config); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &config, nil
|
|
}
|