Fixed some govet warnings
This commit is contained in:
parent
f1d1918b86
commit
07a94bab65
@ -35,14 +35,17 @@ import (
|
|||||||
"github.com/IanLewis/cloud-dyndns-client/pkg/sync"
|
"github.com/IanLewis/cloud-dyndns-client/pkg/sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// VERSION is the current version of the application.
|
||||||
var VERSION = "0.1.4"
|
var VERSION = "0.1.4"
|
||||||
|
|
||||||
|
// Domain is a single domain listed in the configuration file.
|
||||||
type Domain struct {
|
type Domain struct {
|
||||||
Provider string `json:"provider"`
|
Provider string `json:"provider"`
|
||||||
ProviderConfig map[string]interface{} `json:"provider_config"`
|
ProviderConfig map[string]interface{} `json:"provider_config"`
|
||||||
Backend backend.DNSBackend
|
Backend backend.DNSBackend
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Config is the configuration contained in the given configuration file.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Domains map[string]*Domain `json:"domains"`
|
Domains map[string]*Domain `json:"domains"`
|
||||||
}
|
}
|
||||||
@ -57,48 +60,48 @@ func getFileContents(pathToFile string) ([]byte, error) {
|
|||||||
|
|
||||||
contents, err := ioutil.ReadAll(f)
|
contents, err := ioutil.ReadAll(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []byte{}, fmt.Errorf("Could not read %s: %v", f, err)
|
return []byte{}, fmt.Errorf("failed to read %s: %v", f.Name(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return contents, nil
|
return contents, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getConfig(pathToJson string) (Config, error) {
|
func getConfig(pathToJSON string) (Config, error) {
|
||||||
var cfg Config
|
var cfg Config
|
||||||
|
|
||||||
jsonContents, err := getFileContents(pathToJson)
|
jsonContents, err := getFileContents(pathToJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cfg, err
|
return cfg, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(jsonContents, &cfg)
|
err = json.Unmarshal(jsonContents, &cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cfg, fmt.Errorf("Could not load %s: %v", pathToJson, err)
|
return cfg, fmt.Errorf("Could not load %s: %v", pathToJSON, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, d := range cfg.Domains {
|
for _, d := range cfg.Domains {
|
||||||
if d.Provider == "gcp" {
|
if d.Provider == "gcp" {
|
||||||
p, ok := d.ProviderConfig["project_id"]
|
p, ok := d.ProviderConfig["project_id"]
|
||||||
if !ok {
|
if !ok {
|
||||||
return cfg, fmt.Errorf("\"project_id\" is required for Cloud DNS config.")
|
return cfg, fmt.Errorf("\"project_id\" is required for Cloud DNS config")
|
||||||
}
|
}
|
||||||
project, ok := p.(string)
|
project, ok := p.(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return cfg, fmt.Errorf("\"project_id\" must be a string.")
|
return cfg, fmt.Errorf("\"project_id\" must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
z, ok := d.ProviderConfig["managed_zone"]
|
z, ok := d.ProviderConfig["managed_zone"]
|
||||||
if !ok {
|
if !ok {
|
||||||
return cfg, fmt.Errorf("\"managed_zone\" is required for Cloud DNS config.")
|
return cfg, fmt.Errorf("\"managed_zone\" is required for Cloud DNS config")
|
||||||
}
|
}
|
||||||
zone, ok := z.(string)
|
zone, ok := z.(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return cfg, fmt.Errorf("\"managed_zone\" must be a string.")
|
return cfg, fmt.Errorf("\"managed_zone\" must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
b, err := gcp.NewCloudDNSBackend(project, zone)
|
b, err := gcp.NewCloudDNSBackend(project, zone)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cfg, fmt.Errorf("Could not create Cloud DNS backend: %#v", err)
|
return cfg, fmt.Errorf("Could not create Cloud DNS backend: %v", err)
|
||||||
}
|
}
|
||||||
d.Backend = b
|
d.Backend = b
|
||||||
} else {
|
} else {
|
||||||
@ -109,6 +112,7 @@ func getConfig(pathToJson string) (Config, error) {
|
|||||||
return cfg, nil
|
return cfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Main is the main function for the cloud-dyndns-client command. It returns the OS exit code.
|
||||||
func Main() int {
|
func Main() int {
|
||||||
addr := flag.String("addr", ":8080", "Address to listen on for health checks.")
|
addr := flag.String("addr", ":8080", "Address to listen on for health checks.")
|
||||||
version := flag.Bool("version", false, "Print the version and exit.")
|
version := flag.Bool("version", false, "Print the version and exit.")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user