Documentation ¶
Overview ¶
Example ¶
this example creates a registry service to register instance info to discovery server. when the program is about to exit,registry.Cancel should be called.
package main import ( "context" "go-common/library/naming" "go-common/library/naming/discovery" "time" ) func main() { var c = &discovery.Config{ Nodes: []string{"api.bilibili.co"}, Zone: "sh001", Env: "pre", Key: "0c4b8fe3ff35a4b6", Secret: "b370880d1aca7d3a289b9b9a7f4d6812", } var ins = &naming.Instance{ AppID: "main.arch.test2", Addrs: []string{ "grpc://127.0.0.1:8080", }, Version: "1", Metadata: map[string]string{ "weight": "128", "color": "blue", }, } d := discovery.New(c) cacenl, err := d.Register(context.TODO(), ins) if err != nil { return } defer cacenl() //start to Serve time.Sleep(time.Second * 5) }
Output:
Index ¶
- Variables
- func Build(id string) naming.Resolver
- func Builder() naming.Builder
- func Shuffle(n int, swap func(i, j int))
- type Config
- type Discovery
- func (d *Discovery) Build(appid string) naming.Resolver
- func (d *Discovery) Close() error
- func (d *Discovery) Register(c context.Context, ins *naming.Instance) (cancelFunc context.CancelFunc, err error)
- func (d *Discovery) Reload(c *Config)
- func (d *Discovery) Scheme() string
- func (d *Discovery) Set(ins *naming.Instance) error
- type Resolver
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrDuplication duplication treeid. ErrDuplication = errors.New("discovery: instance duplicate registration") )
Functions ¶
Types ¶
type Config ¶
type Config struct { Nodes []string Key string Secret string Region string Zone string Env string Host string }
Config discovery configures.
type Discovery ¶
type Discovery struct {
// contains filtered or unexported fields
}
Discovery is discovery client.
Example ¶
this example creates a discovery client to poll instances from discovery server.
package main import ( "context" "fmt" "go-common/library/naming/discovery" ) func main() { d := discovery.Build("1231234") ch := d.Watch() for { <-ch ins, ok := d.Fetch(context.TODO()) if ok { fmt.Println("new instances found:", ins) } } }
Output:
Click to show internal directories.
Click to hide internal directories.