code: func New(ac *Config) (*API, error) {
  
  	if ac == nil {
  		return nil, errors.New("Invalid API configuration (nil)")
  	}
  
  	key := TokenKeyType(ac.TokenKey)
  	if key == "" {
  		return nil, errors.New("API Token is required")
  	}
  
  	app := TokenAppType(ac.TokenApp)
  	if app == "" {
  		app = defaultAPIApp
  	}
  
  	acctID := TokenAccountIDType(ac.TokenAccountID)
  
  	au := string(ac.URL)
  	if au == "" {
  		au = defaultAPIURL
  	}
  	if !strings.Contains(au, "/") {
  		// if just a hostname is passed, ASSume "https" and a path prefix of "/v2"
  		au = fmt.Sprintf("https://%s/v2", ac.URL)
  	}
  	if last := len(au) - 1; last >= 0 && au[last] == '/' {
  		// strip off trailing '/'
  		au = au[:last]
  	}
  	apiURL, err := url.Parse(au)
  	if err != nil {
  		return nil, err
  	}
  
  	a := &API{
  		apiURL:    apiURL,
  		key:       key,
  		app:       app,
  		accountID: acctID,
  		caCert:    ac.CACert,
  		tlsConfig: ac.TLSConfig,
  		Debug:     ac.Debug,
  		Log:       ac.Log,
  		useExponentialBackoff: false,
  	}
  
  	a.Debug = ac.Debug
  	a.Log = ac.Log
  	if a.Debug && a.Log == nil {
  		a.Log = log.New(os.Stderr, "", log.LstdFlags)
  	}
  	if a.Log == nil {
  		a.Log = log.New(ioutil.Discard, "", log.LstdFlags)
  	}
  
  	return a, nil
  }
docs: // New returns a new Circonus API