代码拉取完成,页面将自动刷新
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 := ®istry.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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。