func DiscoverCatalogEndpoint(serviceType string) (endpoint string, err error) {
	sysSig := make(chan os.Signal, 1)
	signal.Notify(sysSig,
		syscall.SIGHUP,
		syscall.SIGINT,
		syscall.SIGTERM,
		syscall.SIGQUIT)
	for {
		resolver, err := bonjour.NewResolver(nil)
		if err != nil {
			logger.Println("Failed to initialize DNS-SD resolver:", err.Error())
			break
		}
		results := make(chan *bonjour.ServiceEntry)
		logger.Println("Browsing...")
		err = resolver.Browse(serviceType, "", results)
		if err != nil {
			logger.Println("Unable to browse DNS-SD services: ", err)
			break
		}
		var foundService *bonjour.ServiceEntry
		select {
		case foundService = <-results:
			logger.Printf("[DiscoverCatalogEndpoint] Discovered service: %v\n", foundService.ServiceInstanceName())
		case <-time.After(time.Duration(discoveryTimeoutSec) * time.Second):
			logger.Println("[DiscoverCatalogEndpoint] Timeout looking for a service")
		case <-sysSig:
			logger.Println("[DiscoverCatalogEndpoint] System interrupt signal received. Aborting the discovery")
			return endpoint, fmt.Errorf("Aborted by system interrupt")
		}
		if foundService == nil {
			logger.Printf("[DiscoverCatalogEndpoint] Could not discover a service %v withing the timeout. Starting from scratch...", serviceType)
			resolver.Exit <- true
			continue
		}
		resolver.Exit <- true
		close(results)
		uri := ""
		for _, s := range foundService.Text {
			if strings.HasPrefix(s, "uri=") {
				tmp := strings.Split(s, "=")
				if len(tmp) == 2 {
					uri = tmp[1]
					break
				}
			}
		}
		endpoint = fmt.Sprintf("http://%s:%v%s", foundService.HostName, foundService.Port, uri)
		break
	}
	return endpoint, err
}
Discovers a catalog endpoint given the serviceType
package catalog
import (
	"fmt"
	"os"
	"os/signal"
	"strings"
	"syscall"
	"time"
	"github.com/patchwork-toolkit/patchwork/Godeps/_workspace/src/github.com/oleksandr/bonjour"
)
const (
	discoveryTimeoutSec = 30
	minKeepaliveSec     = 5
)