ApiGatewayServiceConfig.java
1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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);
}
}