All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.giants.feign.targeter.GiantsFeignTargeter Maven / Gradle / Ivy

The newest version!
package com.giants.feign.targeter;

import feign.Feign;
import feign.Target;
import org.apache.commons.lang.StringUtils;
import org.springframework.cloud.openfeign.FeignClientFactoryBean;
import org.springframework.cloud.openfeign.FeignContext;
import org.springframework.cloud.openfeign.Targeter;

import java.util.Map;

/**
 * GiantsFeignTargeter TODO
 * date time: 2021/11/17 14:52
 * Copyright 2021 github.com/vencent-lu/giants-feign Inc. All rights reserved.
 *
 * @author vencent-lu
 * @since 1.1
 */
public class GiantsFeignTargeter implements Targeter {

    private Map clientVersionMap;

    @Override
    public  T target(FeignClientFactoryBean factory, Feign.Builder feign, FeignContext context,
                        Target.HardCodedTarget target) {
        String version = this.getClientVersion(target.name());
        if (StringUtils.isEmpty(version)) {
            return feign.target(target);
        }
        return feign.target(new GiantsTarget<>(target, version));
    }

    public static class GiantsTarget extends Target.HardCodedTarget {

        private final String version;

        public GiantsTarget(Target target, String version) {
            super(target.type(), target.name(),
                    new StringBuilder(target.url()).append('-').append(version.replace('.','-')).toString());
            this.version = version;
        }

        public String getVersion() {
            return version;
        }
    }

    public String getClientVersion(String name) {
        if (this.clientVersionMap == null) {
            return null;
        }
        return this.clientVersionMap.get(name);
    }

    public void setClientVersionMap(Map clientVersionMap) {
        this.clientVersionMap = clientVersionMap;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy