32 lines
648 B
Go
32 lines
648 B
Go
package config
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
)
|
|
|
|
type Config struct {
|
|
Listen string `json:"listen"`
|
|
DiscoveryPort int `json:"discovery_port"`
|
|
DiscoveryTimeoutMs int `json:"discovery_timeout_ms"`
|
|
OfflineAfterMs int `json:"offline_after_ms"`
|
|
AgentToken string `json:"agent_token"`
|
|
Concurrency int `json:"concurrency"`
|
|
}
|
|
|
|
func LoadConfig(path string) (*Config, error) {
|
|
file, err := os.Open(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer file.Close()
|
|
|
|
var cfg Config
|
|
decoder := json.NewDecoder(file)
|
|
if err := decoder.Decode(&cfg); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &cfg, nil
|
|
}
|