代码拉取完成,页面将自动刷新
/**
* @Author: koulei
* @Description: TODO
* @File: eureka
* @Version: 1.0.0
* @Date: 2021/7/3 18:28
*/
package discovery
import (
"errors"
"strings"
"sync"
eureka "github.com/xuanbo/eureka-client"
)
type Eureka struct {
}
var eurekaClient *eureka.Client
func CreateEureka(username, password, node, app string, port int) *Eureka {
var once sync.Once
once.Do(func() {
eurekaClient = eureka.NewClient(&eureka.Config{
DefaultZone: "http://" + username + ":" + password + "@" + node,
App: app,
Port: port,
RenewalIntervalInSecs: 15,
DurationInSecs: 30,
Metadata: map[string]interface{}{
"VERSION": "0.1.0",
"NODE_GROUP_ID": 0,
"PRODUCT_CODE": "DEFAULT",
"PRODUCT_VERSION_CODE": "DEFAULT",
"PRODUCT_ENV_CODE": "DEFAULT",
"SERVICE_VERSION_CODE": "DEFAULT",
},
})
})
go eurekaClient.Start()
return &Eureka{}
}
func (e *Eureka) GetInstance(serviceName string) (instance string, err error) {
apps := eurekaClient.Applications
for _, v := range apps.Applications {
if v.Name == strings.ToUpper(serviceName) {
for i := 0; i < len(v.Instances); i++ {
instance = v.Instances[i].HomePageURL
return instance, nil
}
break
}
}
err = errors.New(strings.ToUpper(instance + " " + "找不到该服务"))
return instance, err
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。