当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
2 Star 0 Fork 1

JUMEI_ARCH/go-plugins
暂停

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
static.go 1.83 KB
一键复制 编辑 原始数据 按行查看 历史
package static
import (
"fmt"
"os"
"github.com/micro/go-micro/cmd"
"github.com/micro/go-micro/registry"
"github.com/micro/go-micro/selector"
)
const (
ENV_STATIC_SELECTOR_DOMAIN_NAME = "STATIC_SELECTOR_DOMAIN_NAME"
ENV_STATIC_SELECTOR_PORT_NUMBER = "STATIC_SELECTOR_PORT_NUMBER"
DEFAULT_PORT_NUMBER = "8080"
)
type staticSelector struct {
addressSuffix string
envDomainName string
envPortNumber string
}
func init() {
cmd.DefaultSelectors["static"] = NewSelector
}
func (s *staticSelector) Init(opts ...selector.Option) error {
return nil
}
func (s *staticSelector) Options() selector.Options {
return selector.Options{}
}
func (s *staticSelector) Select(service string, opts ...selector.SelectOption) (selector.Next, error) {
node := &registry.Node{
Id: service,
Address: fmt.Sprintf("%v%v", service, s.addressSuffix),
}
return func() (*registry.Node, error) {
return node, nil
}, nil
}
func (s *staticSelector) Mark(service string, node *registry.Node, err error) {
return
}
func (s *staticSelector) Reset(service string) {
return
}
func (s *staticSelector) Close() error {
return nil
}
func (s *staticSelector) String() string {
return "static"
}
func NewSelector(opts ...selector.Option) selector.Selector {
// Build a new
s := &staticSelector{
addressSuffix: "",
envDomainName: os.Getenv(ENV_STATIC_SELECTOR_DOMAIN_NAME),
envPortNumber: os.Getenv(ENV_STATIC_SELECTOR_PORT_NUMBER),
}
// Add the dns domain-name (if one was specified by an env-var):
if s.envDomainName != "" {
s.addressSuffix += fmt.Sprintf(".%v", s.envDomainName)
}
// Either add the default port-number, or override with one specified by an env-var:
if s.envPortNumber == "" {
s.addressSuffix += fmt.Sprintf(":%v", DEFAULT_PORT_NUMBER)
} else {
s.addressSuffix += fmt.Sprintf(":%v", s.envPortNumber)
}
return s
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/JMArch/go-plugins.git
git@gitee.com:JMArch/go-plugins.git
JMArch
go-plugins
go-plugins
v0.9.2

搜索帮助

0d507c66 1850385 C8b1a773 1850385