-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added the ability to discover backend nodes via srv records
- Loading branch information
1 parent
eff0086
commit a1e90d3
Showing
7 changed files
with
125 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
bin/ | ||
remco |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* This file is part of remco. | ||
* © 2016 The Remco Authors | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
package srvRecord | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
"strings" | ||
) | ||
|
||
// Record is a SRV-Record string | ||
// for example _etcd-client._tcp.example.com. | ||
type Record string | ||
|
||
// GetNodesFromSRV returns the nodes stored in the record | ||
func (r Record) GetNodesFromSRV(scheme string) ([]string, error) { | ||
var nodes []string | ||
_, addrs, err := net.LookupSRV("", "", string(r)) | ||
if err != nil { | ||
return nodes, err | ||
} | ||
|
||
for _, srv := range addrs { | ||
port := fmt.Sprintf("%d", srv.Port) | ||
host := strings.TrimRight(srv.Target, ".") | ||
host = net.JoinHostPort(host, port) | ||
if scheme != "" { | ||
host = fmt.Sprintf("%s://%s", scheme, host) | ||
} | ||
|
||
nodes = append(nodes, host) | ||
} | ||
return nodes, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters