https://github.com/danielgatis/go-discovery
A collection of service discovery implementations.
https://github.com/danielgatis/go-discovery
go golang kubernetes mdns service-discovery
Last synced: 7 months ago
JSON representation
A collection of service discovery implementations.
- Host: GitHub
- URL: https://github.com/danielgatis/go-discovery
- Owner: danielgatis
- License: mit
- Created: 2021-12-29T00:39:14.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-10-11T23:24:19.000Z (almost 2 years ago)
- Last Synced: 2025-03-19T00:07:01.754Z (7 months ago)
- Topics: go, golang, kubernetes, mdns, service-discovery
- Language: Go
- Homepage:
- Size: 114 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go - Discovery
[](https://goreportcard.com/report/github.com/danielgatis/go-discovery)
[](https://raw.githubusercontent.com/danielgatis/go-discovery/master/LICENSE)
[](https://godoc.org/github.com/danielgatis/go-discovery)A collection of service discovery implementations.
## Install
```bash
go get -u github.com/danielgatis/go-discovery
```And then import the package in your code:
```go
import "github.com/danielgatis/go-discovery"
```### Example
An example described below is one of the use cases.
```go
package mainimport (
"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](https://github.com/danielgatis)
Licensed under [MIT License](./LICENSE)
### Buy me a coffee
Liked some of my work? Buy me a coffee (or more likely a beer)