This repository has been archived on 2023-05-06. You can view files and clone it, but cannot push or open issues or pull requests.
helix/internal/config/config.go

40 lines
829 B
Go

package config
import (
"encoding/json"
"fmt"
"io/ioutil"
)
type Config struct {
ProjectName string `json:"project"`
Docker DockerConfig `json:"docker"`
}
type DockerConfig struct {
Network DockerNetworkConfig `json:"network"`
}
// DockerNetworkStackArgs contains arguments for
// creating the DockerNetworkStack
type DockerNetworkConfig struct {
Name string `json:"name"`
Subnet string `json:"subnet"`
Driver string `json:"driver"`
}
func NewConfig(file string) (Config, error) {
var c Config
var err error
data, err := ioutil.ReadFile(file)
if err != nil {
return c, fmt.Errorf("unable to read data from %s...\n%v", file, err)
}
if err = json.Unmarshal(data, &c); err != nil {
return c, fmt.Errorf("unable to decode the JSON configuration from %s...\n%v", file, err)
}
return c, nil
}