// AutoRegisterHandler handles auto register post request

AutoRegisterHandler handles auto register post request
// AutoRegisterHandler handles auto register post request
func AutoRegisterHandler(c *routing.Context) error {
	serviceDiscovery := InternalServiceDiscovery()
	var s map[string]string
	json.Unmarshal(c.Request.Body(), &s)
	if s["MatchingUri"] == "" || s["ToUri"] == "" || s["Name"] == "" || s["Port"] == "" {
		return http.Error(c, "Missing body parameters.", 400, ServiceDiscoveryServiceName())
	}
	host := c.RemoteIP().String() + ":" + s["Port"]
	serv := service.Service{
		Hosts:            []string{host},
		MatchingURI:      s["MatchingUri"],
		ToURI:            s["ToUri"],
		Name:             s["Name"],
		HealthcheckUrl:   "http://" + host + s["HealthcheckUrl"],
		APIDocumentation: "http://" + host + s["APIDocumentation"],
		IsReachable:      true,
	}
	serv.MatchingURIRegex = sdUtils.GetMatchingURIRegex(serv.MatchingURI)
	serviceFound, err := servicediscovery.ValidateServiceExists(serv)
	if err != nil {
		serviceFound, err = serviceDiscovery.CreateService(serv)
	} else {
		serviceFound.Hosts = append(serviceFound.Hosts, host)
		serviceFound, err = serviceDiscovery.UpdateService(serviceFound)
	}
	if err != nil {
		return http.Error(c, err.Error(), 400, ServiceDiscoveryServiceName())
	}
	serv, _ = serviceDiscovery.FindService(serviceFound)
	s2, _ := json.Marshal(serv)
	http.Response(c, string(s2), 201, "AUTO_REGISTER", "application/json")
	return nil
}
func AutoRegisterHandler ( c * routing . Context ) error { serviceDiscovery := InternalServiceDiscovery ( ) var s map [ string ] string json . Unmarshal ( c . Request . Body ( ) , & s ) if s [ " " ] == " " || s [ " " ] == " " || s [ " " ] == " " || s [ " " ] == " " { return http . Error ( c , " " , 400 , ServiceDiscoveryServiceName ( ) ) } host := c . RemoteIP ( ) . String ( ) + " " + s [ " " ] serv := service . Service { Hosts : [ ] string { host } , MatchingURI : s [ " " ] , ToURI : s [ " " ] , Name : s [ " " ] , HealthcheckUrl : " " + host + s [ " " ] , APIDocumentation : " " + host + s [ " " ] , IsReachable : true , } serv . MatchingURIRegex = sdUtils . GetMatchingURIRegex ( serv . MatchingURI ) serviceFound , err := servicediscovery . ValidateServiceExists ( serv ) if err != nil { serviceFound , err = serviceDiscovery . CreateService ( serv ) } else { serviceFound . Hosts = append ( serviceFound . Hosts , host ) serviceFound , err = serviceDiscovery . UpdateService ( serviceFound ) } if err != nil { return http . Error ( c , err . Error ( ) , 400 , ServiceDiscoveryServiceName ( ) ) } serv , _ = serviceDiscovery . FindService ( serviceFound ) s2 , _ := json . Marshal ( serv ) http . Response ( c , string ( s2 ) , 201 , " " , " " ) return nil }
AutoRegisterHandler handles auto register post request
AutoRegisterHandler handles auto register post request
// Create internal service discovery object with internal api user, which has access to everything
 // TODO: create service on service discovery
