Skip to content

Instantly share code, notes, and snippets.

@songrgg
Last active October 28, 2018 09:52
Show Gist options
  • Save songrgg/22999fb7ab76a30dcac17cb28ed412d4 to your computer and use it in GitHub Desktop.
Save songrgg/22999fb7ab76a30dcac17cb28ed412d4 to your computer and use it in GitHub Desktop.
go-micro's istio selector, for service registry.
package istio
import (
"fmt"
"strings"
"github.com/micro/go-micro/registry"
"github.com/micro/go-micro/selector"
)
const (
svcPort = 10088
)
var (
serviceHostMapping = map[string]string{
"payment": "payment.common",
}
)
type istio struct{}
func (r *istio) Init(opts ...selector.Option) error {
return nil
}
func (r *istio) Options() selector.Options {
return selector.Options{}
}
func (r *istio) Select(service string, opts ...selector.SelectOption) (selector.Next, error) {
if host, exist := serviceHostMapping[service]; exist {
node := &registry.Node{
Id: service,
Address: host,
Port: svcPort,
}
return func() (*registry.Node, error) {
return node, nil
}, nil
}
return nil, fmt.Errorf("service %s(%s) not found", service, svc)
}
func (r *istio) Mark(service string, node *registry.Node, err error) {
return
}
func (r *istio) Reset(service string) {
return
}
func (r *istio) Close() error {
return nil
}
func (r *istio) String() string {
return "istio"
}
func NewSelector(opts ...selector.Option) selector.Selector {
return &istio{}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment