package com.netwisd.base.gateway;

import cn.hutool.core.date.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.Inet4Address;

@EnableDiscoveryClient
@SpringBootApplication
public class GatewayApplication {

    public static void main(String[] args) {
        String startTime = DateUtil.now();
        Logger log = LoggerFactory.getLogger(GatewayApplication.class);
        ConfigurableApplicationContext context = SpringApplication.run(GatewayApplication.class);
        try {
            //ip
            String hostAddress = Inet4Address.getLocalHost().getHostAddress();
            //获取端口
            String prot = context.getBean(Environment.class).getProperty("server.port");
            String ip = "http://" + hostAddress + ":" + prot + "/swagger-ui.html";
            log.info(ip);
            String doc = "http://" + hostAddress + ":" + prot + "/doc.html";
            log.info(doc);
            log.info("Gateway启动了,启动开始时间:{}，启动结束时间:{}", startTime, DateUtil.now());
        } catch (Exception e) {
            log.error("启动失败:", e);
        }
    }

}
