Skip to content

Commit

Permalink
Add dns discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
pipe01 committed Feb 22, 2024
1 parent 2a25e5c commit 05fb016
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
31 changes: 31 additions & 0 deletions discovery/dns/dns.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package dns

import (
"fmt"
"net"

"github.com/MouseHatGames/mice/options"
)

type dnsDiscovery struct {
}

func Discovery() options.Option {
return func(o *options.Options) {
o.Discovery = &dnsDiscovery{}
}
}

func (d *dnsDiscovery) Find(svc string) (host string, err error) {
ips, err := net.LookupIP(svc)
if err != nil {
return "", fmt.Errorf("lookup host: %w", err)
}

if len(ips) == 1 {
return ips[0].String(), nil
}

//TODO: Use a selection algorithm
return "", fmt.Errorf("more than one ip found")
}
5 changes: 5 additions & 0 deletions discovery/dns/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/MouseHatGames/mice-plugins/discovery/dns

go 1.21.5

require github.com/MouseHatGames/mice v1.2.8
8 changes: 8 additions & 0 deletions discovery/dns/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
github.com/MouseHatGames/mice v1.2.8 h1:3Gsj8VjVuuDsLuum3oMeBjYcxbV8OhaQ6hd6aDqbJww=
github.com/MouseHatGames/mice v1.2.8/go.mod h1:Zml0bIiLnFoNEylVWSEsnpscvXmSMnR9jqr/aYh/jNw=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 comments on commit 05fb016

Please sign in to comment.