code: func (r *RegisterMonitor) register() {
  	catalog := r.Client.Catalog()
  	serviceID := r.serviceID()
  	serviceName := r.serviceName()
  
  	// Determine the current state of this service in Consul
  	var currentService *api.CatalogService
  	services, _, err := catalog.Service(
  		serviceName, "",
  		&api.QueryOptions{AllowStale: true})
  	if err == nil {
  		for _, service := range services {
  			if serviceID == service.ServiceID {
  				currentService = service
  				break
  			}
  		}
  	}
  
  	// If we have a matching service, then we verify if we need to reregister
  	// by comparing if it matches what we expect.
  	if currentService != nil &&
  		currentService.ServiceAddress == r.LocalAddress &&
  		currentService.ServicePort == r.LocalPort {
  		r.Logger.Printf("[DEBUG] proxy: service already registered, not re-registering")
  		return
  	}
  
  	// If we're here, then we're registering the service.
  	err = r.Client.Agent().ServiceRegister(&api.AgentServiceRegistration{
  		Kind:    api.ServiceKindConnectProxy,
  		ID:      serviceID,
  		Name:    serviceName,
  		Address: r.LocalAddress,
  		Port:    r.LocalPort,
  		Proxy: &api.AgentServiceConnectProxyConfig{
  			DestinationServiceName: r.Service,
  		},
  		Check: &api.AgentServiceCheck{
  			CheckID: r.checkID(),
  			Name:    "proxy heartbeat",
  			TTL:     "30s",
  			Notes:   "Built-in proxy will heartbeat this check.",
  			Status:  "passing",
  		},
  	})
  	if err != nil {
  		r.Logger.Printf("[WARN] proxy: Failed to register Consul service: %s", err)
  		return
  	}
  
  	r.Logger.Printf("[INFO] proxy: registered Consul service: %s", serviceID)
  }
docs: // register queries the Consul agent to determine if we've already registered.
  // If we haven't or the registered service differs from what we're trying to
  // register, then we attempt to register our service.