func (sr *Resolver) Resolve(function string) ([]string, error) {
	if val, ok := sr.cache.Get(getCacheKey(function)); ok {
		sr.logger.Info("Got Address from cache", "address", fmt.Sprintf("%#v", val))
		return val.(*cacheItem).addresses, nil
	}
	sr.logger.Info("Getting Address from consul", "function", function)
	q, err := sr.getServiceQuery(function)
	if err != nil {
		return nil, err
	}
	s, _, err := q.Fetch(sr.clientSet, nil)
	if err != nil {
		return nil, err
	}
	sr.watcher.Add(q)
	cs := s.([]*dependency.CatalogService)
	addresses := sr.updateCatalog(q, cs)
	return addresses, nil
}
Resolve resolves a function name to an array of URI
package consul
import (
	"fmt"
	"time"
	"github.com/hashicorp/consul-template/dependency"
	"github.com/hashicorp/consul-template/watch"
	"github.com/hashicorp/consul/api"
	hclog "github.com/hashicorp/go-hclog"
	cache "github.com/patrickmn/go-cache"
)
type Catalog interface {
	Service(service, tag string, q *api.QueryOptions) ([]*api.CatalogService, *api.QueryMeta, error)
}
type CatalogServiceQuery interface {
	Fetch(clients *dependency.ClientSet, opts *dependency.QueryOptions) (interface{}, *dependency.ResponseMetadata, error)
	CanShare() bool
	Stop()
	String() string
	Type() dependency.Type
}
type WrappedWatcher struct {
	*watch.Watcher
}
type iterateFunc func(dep dependency.Dependency, deps []*dependency.CatalogService)
func (ww *WrappedWatcher) IterateDataCh(f iterateFunc) {
	for cs := range ww.DataCh() {
		f(
			cs.Dependency(),
			cs.Data().([]*dependency.CatalogService),
		)
	}
}
type Watcher interface {
	Add(dependency dependency.Dependency) (bool, error)
	Remove(dependency dependency.Dependency) bool
	IterateDataCh(iterateFunc)
}
type ServiceResolver interface {
	Resolve(function string) ([]string, error)
	RemoveCacheItem(service string)
}
type Resolver struct {
	clientSet       *dependency.ClientSet
	watcher         Watcher
	cache           *cache.Cache
	getServiceQuery func(service string) (CatalogServiceQuery, error)
	logger          hclog.Logger
}
type cacheItem struct {
	serviceQuery dependency.Dependency
	addresses    []string
}
func NewResolver(address, ACLToken string, logger hclog.Logger) *Resolver {
	clientSet := dependency.NewClientSet()
	clientSet.CreateConsulClient(&dependency.CreateConsulClientInput{
		Address: address,
		Token:   ACLToken,
	})
	watch, _ := watch.NewWatcher(&watch.NewWatcherInput{
		Clients:  clientSet,
		MaxStale: 10000 * time.Millisecond,
	})
	pc := cache.New(5*time.Minute, 10*time.Minute)
	cr := &Resolver{
		clientSet:       clientSet,
		watcher:         &WrappedWatcher{watch},
		cache:           pc,
		getServiceQuery: createServiceQueryImpl,
		logger:          logger,
	}
	go cr.watch()
	return cr
}
func createServiceQueryImpl(function string) (CatalogServiceQuery, error) {
	return dependency.NewCatalogServiceQuery(function)
}