code: func SetupTLSConfig(tlsConfig *TLSConfig) (*tls.Config, error) {
  	tlsClientConfig := &tls.Config{
  		InsecureSkipVerify: tlsConfig.InsecureSkipVerify,
  	}
  
  	if tlsConfig.Address != "" {
  		server := tlsConfig.Address
  		hasPort := strings.LastIndex(server, ":") > strings.LastIndex(server, "]")
  		if hasPort {
  			var err error
  			server, _, err = net.SplitHostPort(server)
  			if err != nil {
  				return nil, err
  			}
  		}
  		tlsClientConfig.ServerName = server
  	}
  
  	if tlsConfig.CertFile != "" && tlsConfig.KeyFile != "" {
  		tlsCert, err := tls.LoadX509KeyPair(tlsConfig.CertFile, tlsConfig.KeyFile)
  		if err != nil {
  			return nil, err
  		}
  		tlsClientConfig.Certificates = []tls.Certificate{tlsCert}
  	}
  
  	if tlsConfig.CAFile != "" || tlsConfig.CAPath != "" {
  		rootConfig := &rootcerts.Config{
  			CAFile: tlsConfig.CAFile,
  			CAPath: tlsConfig.CAPath,
  		}
  		if err := rootcerts.ConfigureTLS(tlsClientConfig, rootConfig); err != nil {
  			return nil, err
  		}
  	}
  
  	return tlsClientConfig, nil
  }
docs: // TLSConfig is used to generate a TLSClientConfig that's useful for talking to
  // Consul using TLS.