github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/tools/lxdclient/config.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 // +build go1.3 5 6 package lxdclient 7 8 import ( 9 "github.com/juju/errors" 10 ) 11 12 // Config contains the config values used for a connection to the LXD API. 13 type Config struct { 14 // Remote identifies the remote server to which the client should 15 // connect. For the default "remote" use Local. 16 Remote Remote 17 } 18 19 // WithDefaults updates a copy of the config with default values 20 // where needed. 21 func (cfg Config) WithDefaults() (Config, error) { 22 // We leave a blank namespace alone. 23 // Also, note that cfg is a value receiver, so it is an implicit copy. 24 25 var err error 26 cfg.Remote, err = cfg.Remote.WithDefaults() 27 if err != nil { 28 return cfg, errors.Trace(err) 29 } 30 return cfg, nil 31 } 32 33 // Validate checks the client's fields for invalid values. 34 func (cfg Config) Validate() error { 35 if err := cfg.Remote.Validate(); err != nil { 36 return errors.Trace(err) 37 } 38 39 return nil 40 }