ApiGatewayServiceConfig.java 1.14 KB
package com.glsx.plat.gateway.config;

import com.glsx.plat.gateway.model.GatewayService;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author huangch
 * @version V1.0
 * @Title: ApiGatewayConsumerConfig
 * @Description:
 * @Company: Didihu.com.cn
 * @Date 2023/4/6 10:36
 */
@RefreshScope
@ConfigurationProperties(prefix = "gateway")
public class ApiGatewayServiceConfig {

    private Map<String, GatewayService> services;

    public void setServices(Map<String, GatewayService> services) {
        Map<String, GatewayService> newMap = new ConcurrentHashMap<>();
        for(Map.Entry<String, GatewayService> entry : services.entrySet()){
            GatewayService gatewayService = entry.getValue();
            gatewayService.setName(entry.getKey());
            newMap.put(gatewayService.getAppKey(), gatewayService);
        }
        this.services = newMap;
    }

    public GatewayService getServiceByAppKey(String appKey){
        return this.services.get(appKey);
    }
}