42 lines
761 B
Go
42 lines
761 B
Go
package config
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"net"
|
||
|
|
"path/filepath"
|
||
|
|
"strconv"
|
||
|
|
)
|
||
|
|
|
||
|
|
const (
|
||
|
|
PortPrimary = 5032
|
||
|
|
PortAlternate = 5033
|
||
|
|
UpdatesSubdir = "updates"
|
||
|
|
)
|
||
|
|
|
||
|
|
// AlternateListenAddr returns the other blue-green port (5032 <-> 5033).
|
||
|
|
func AlternateListenAddr(current string) (string, error) {
|
||
|
|
host, portStr, err := net.SplitHostPort(current)
|
||
|
|
if err != nil {
|
||
|
|
return "", err
|
||
|
|
}
|
||
|
|
if host == "" {
|
||
|
|
host = "0.0.0.0"
|
||
|
|
}
|
||
|
|
port, err := strconv.Atoi(portStr)
|
||
|
|
if err != nil {
|
||
|
|
return "", err
|
||
|
|
}
|
||
|
|
next := PortAlternate
|
||
|
|
if port == PortAlternate {
|
||
|
|
next = PortPrimary
|
||
|
|
}
|
||
|
|
return net.JoinHostPort(host, strconv.Itoa(next)), nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func UpdatesDir() (string, error) {
|
||
|
|
base, err := InstallDir()
|
||
|
|
if err != nil {
|
||
|
|
return "", err
|
||
|
|
}
|
||
|
|
return filepath.Join(base, UpdatesSubdir), nil
|
||
|
|
}
|