package com.neusoft.smart.pos.ota.controller;

import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

import java.io.PrintWriter;

@RestController
public class DiscoveryClientController {
	
	@Autowired
	DiscoveryClient discoveryClient;
	
	@Autowired
	private RequestMappingHandlerMapping handlerMapping;
	
	@GetMapping("/dc")
	public String dc() {
		String services = String.join(",", discoveryClient.getServices());
		System.out.println(services);
		return services;
	}
	
	@GetMapping("/index")
	public void get(PrintWriter printWriter) {
		val map = handlerMapping.getHandlerMethods();
		map.forEach((key, value) -> printWriter.println(key.getPatternsCondition().getPatterns() + "--" + value.toString()));
	}
	
}
