You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: consul_source.go
    path of file: ./repos/fabio/cert
    
    the code of the file until where you have to start completion: package cert

import (
	"crypto/tls"
	"crypto/x509"
	"errors"
	"fmt"
	"log"
	"net/url"
	"path"
	"reflect"
	"strings"
	"time"

	"github.com/hashicorp/consul/api"
)

// ConsulSource implements a certificate source which loads
// TLS and client authentication certificates from the consul KV store.
// The CertURL/ClientCAURL must point to the base path of the certificates.
// The TLS certificates are updated automatically when the KV store
// changes.
type ConsulSource struct {
	CertURL     string
	ClientCAURL string
	CAUpgradeCN string
}

func parseConsulURL(rawurl string) (config *api.Config, key string, err error) {
	if rawurl == "" || !strings.HasPrefix(rawurl, "http://") && !strings.
    
func (s ConsulSource) Certificates() chan []tls.Certificate {
	if s.CertURL == "" {
		return nil
	}

	config, key, err := parseConsulURL(s.CertURL)
	if err != nil {
		log.Printf("[ERROR] cert: Failed to parse consul url. %s", err)
	}

	client, err := api.NewClient(config)
	if err != nil {
		log.Printf("[ERROR] cert: Failed to create consul client. %s", err)
	}

	pemBlocksCh := make(chan map[string][]byte, 1)
	go watchKV(client, key, pemBlocksCh)

	ch := make(chan []tls.Certificate, 1)
	go func() {
		for pemBlocks := range pemBlocksCh {
			certs, err := loadCertificates(pemBlocks)
			if err != nil {
				log.Printf("[ERROR] cert: Failed to load certificates. %s", err)
				continue
			}
			ch <- certs
		}
	}()
	return ch
}