-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(config): Add go-sockaddr templating support to nomad consul a…
…ddress
- Loading branch information
Showing
5 changed files
with
83 additions
and
24 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
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,28 @@ | ||
package config | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/hashicorp/go-sockaddr/template" | ||
) | ||
|
||
// ParseSingleIPTemplate is used as a helper function to parse out a single IP | ||
// address from a config parameter. | ||
func ParseSingleIPTemplate(ipTmpl string) (string, error) { | ||
out, err := template.Parse(ipTmpl) | ||
if err != nil { | ||
return "", fmt.Errorf("unable to parse address template %q: %v", ipTmpl, err) | ||
} | ||
|
||
ips := strings.Split(out, " ") | ||
switch len(ips) { | ||
case 0: | ||
return "", errors.New("no addresses found, please configure one") | ||
case 1: | ||
return strings.TrimSpace(ips[0]), nil | ||
default: | ||
return "", fmt.Errorf("multiple addresses found (%q), please configure one", out) | ||
} | ||
} |
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