41 lines
829 B
Go
41 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
|
||
|
}
|