forked from tslocum/twins
Fork 0

Compare commits


3 Commits

Author SHA1 Message Date
Trevor Slocum c026f5c7b1 Clarify IPv4 and IPv6 configuration 2023-05-06 10:49:39 -07:00
Ivan Vilata-i-Balaguer 668e099ffa Add quotes for IPv6 address configuration example
Since leaving the quotes out in the config file causes the confusing "did not
find expected key" error, so do not assume that the user is familiar enough
with YAML syntax as to identify the issue.
2023-05-04 09:23:31 +02:00
Ivan Vilata-i-Balaguer 066fe276eb Fix listening on literal IPv6 address
Those contain colons, so splitting by colons would break the address in the
middle.  Instead, use a regular expression to split host and port at the last
colon, if followed by port digits and the end of the string.

Also, document the syntax for listening on literal IPv4 and IPv6 addresses.
2023-05-03 14:22:19 +02:00
2 changed files with 14 additions and 9 deletions

View File

@ -10,14 +10,19 @@ via the `--config` argument.
Address to listen for connections on in the format of `interface:port`.
### Listen on localhost
### Listen on all interfaces
### Listen on all addresses (IPv4 and IPv6)
### Listen on a specific address (IPv4 or IPv6)
`` or `"[2001:db8::1]:1965"` (please note the quotes and brackets
for IPv6 addresses).
### Listen on localhost (IPv4 only)
## Types
Content types may be defined by file extension. When a type is not defined for

View File

@ -127,13 +127,13 @@ func readconfig(configPath string) error {
newLine = "\r\n"
split := strings.Split(config.Listen, ":")
if len(split) != 2 {
listenRe := regexp.MustCompile("(.*):([0-9]+)$")
if !listenRe.MatchString(config.Listen) {
config.hostname = config.Listen
config.Listen += ":1965"
} else {
config.hostname = split[0]
config.port, err = strconv.Atoi(split[1])
config.hostname = listenRe.ReplaceAllString(config.Listen, "$1")
config.port, err = strconv.Atoi(listenRe.ReplaceAllString(config.Listen, "$2"))
if err != nil {
log.Fatalf("invalid port specified: %s", err)