32 lines
664 B
Go
32 lines
664 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
// Config application configuration
|
|
type Config struct {
|
|
Path string `json:"path"`
|
|
Account []Account `json:"account"`
|
|
}
|
|
|
|
type Account struct {
|
|
Addr string `json:"addr"`
|
|
Username string `json:"username"`
|
|
Password string `json:"password"`
|
|
}
|
|
|
|
// NewConfig - create new config instance from file path
|
|
func NewConfig(configFile string) (config *Config) {
|
|
file, err := os.ReadFile(configFile)
|
|
if err != nil {
|
|
log.Fatalf("Error loading config file %v", err)
|
|
}
|
|
if err := json.Unmarshal(file, &config); err != nil {
|
|
log.Fatalf("Error Unmarshaling json config file %v", err)
|
|
}
|
|
return config
|
|
}
|