modulepackage
0.0.0-20230228134354-e919b88b9862
Repository: https://github.com/danielgatis/go-discovery.git
Documentation: pkg.go.dev
# README
Go - Discovery
A collection of service discovery implementations.
Install
go get -u github.com/danielgatis/go-discovery
And then import the package in your code:
import "github.com/danielgatis/go-discovery"
Example
An example described below is one of the use cases.
package main
import (
"context"
"flag"
"fmt"
"time"
"github.com/danielgatis/go-ctrlc"
"github.com/danielgatis/go-discovery"
"github.com/sirupsen/logrus"
)
var (
port int
)
func init() {
flag.IntVar(&port, "port", 3001, "port number")
}
func main() {
flag.Parse()
discovery := discovery.NewMdnsDiscovery(fmt.Sprintf("test:%d", port), "_test._tcp", "local.", port, logrus.StandardLogger())
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
ctrlc.Watch(func() {
cancel()
})
go func() {
discovery.Register(ctx)
}()
for {
select {
case <-ctx.Done():
return
default:
peers, err := discovery.Lookup()
if err != nil {
logrus.Fatal(err)
}
for _, peer := range peers {
logrus.Info(peer)
}
}
}
}
❯ go run main.go -p 3001
❯ go run main.go -p 3002
License
Copyright (c) 2021-present Daniel Gatis
Licensed under MIT License
Buy me a coffee
Liked some of my work? Buy me a coffee (or more likely a beer)
# Functions
NewDummyDiscovery returns a new dummy resolver.
NewK8sDiscovery returns a new k8s resolver.
NewMdnsDiscovery returns a new mDNS resolver.
NewNullDiscovery returns a new null resolver.
# Structs
DummyDiscovery is a dummy resolver for static peers.
K8sDiscovery is a k8s resolver.
MdnsDiscovery is a mDNS resolver.
NullDiscovery is a dummy resolver for static peers.
# Interfaces
Discovery represents a base interface for all resolvers.