// AutoDeRegisterHandler handles auto deregister post request

AutoDeRegisterHandler handles auto deregister post request
// AutoDeRegisterHandler handles auto deregister post request
func AutoDeRegisterHandler(c *routing.Context) error {
	serviceDiscovery := InternalServiceDiscovery()
	var s map[string]string
	json.Unmarshal(c.Request.Body(), &s)
	if s["MatchingUri"] == "" || s["Port"] == "" {
		return http.Error(c, "Missing body parameters.", 400, ServiceDiscoveryServiceName())
	}
	host := c.RemoteIP().String() + ":" + s["Port"]
	serv := service.Service{
		MatchingURI: s["MatchingUri"],
	}
	serv.MatchingURIRegex = sdUtils.GetMatchingURIRegex(serv.MatchingURI)
	serviceFound, err := servicediscovery.ValidateServiceExists(serv)
	var status int
	if err != nil {
		return ServiceNotFound(c)
	} else {
		serviceFound.Hosts = utils.RemoveStringFromArray(serviceFound.Hosts, host)
		serviceFound, err = serviceDiscovery.UpdateService(serviceFound)
	}
	serv, _ = serviceDiscovery.FindService(serviceFound)
	s2, _ := json.Marshal(serv)
	http.Response(c, string(s2), status, "AUTO_DEREGISTER", "application/json")
	return nil
}
func AutoDeRegisterHandler ( c * routing . Context ) error { serviceDiscovery := InternalServiceDiscovery ( ) var s map [ string ] string json . Unmarshal ( c . Request . Body ( ) , & s ) if s [ " " ] == " " || s [ " " ] == " " { return http . Error ( c , " " , 400 , ServiceDiscoveryServiceName ( ) ) } host := c . RemoteIP ( ) . String ( ) + " " + s [ " " ] serv := service . Service { MatchingURI : s [ " " ] , } serv . MatchingURIRegex = sdUtils . GetMatchingURIRegex ( serv . MatchingURI ) serviceFound , err := servicediscovery . ValidateServiceExists ( serv ) var status int if err != nil { return ServiceNotFound ( c ) } else { serviceFound . Hosts = utils . RemoveStringFromArray ( serviceFound . Hosts , host ) serviceFound , err = serviceDiscovery . UpdateService ( serviceFound ) } serv , _ = serviceDiscovery . FindService ( serviceFound ) s2 , _ := json . Marshal ( serv ) http . Response ( c , string ( s2 ) , status , " " , " " ) return nil }
AutoDeRegisterHandler handles auto deregister post request
AutoDeRegisterHandler handles auto deregister post request