add support for a host in ensurePortFormat (#1342)

* add support for an host in ensurePortFormat
using a host enables the ability to bind to a specific interface

* add support for an host in ensurePortFormat
using a host enables the ability to bind to a specific interface
This commit is contained in:
jhawk28
2019-08-14 14:46:32 -04:00
committed by Marwan Sulaiman
parent 3a3d474e1b
commit ba9dc5470e
2 changed files with 9 additions and 5 deletions
+3 -5
View File
@@ -6,12 +6,13 @@ import (
"os"
"path/filepath"
"runtime"
"strconv"
"github.com/BurntSushi/toml"
"github.com/gomods/athens/pkg/download/mode"
"github.com/gomods/athens/pkg/errors"
"github.com/kelseyhightower/envconfig"
validator "gopkg.in/go-playground/validator.v9"
"gopkg.in/go-playground/validator.v9"
)
const defaultConfigFile = "athens.toml"
@@ -188,10 +189,7 @@ func envOverride(config *Config) error {
}
func ensurePortFormat(s string) string {
if len(s) == 0 {
return ""
}
if s[0] != ':' {
if _, err := strconv.Atoi(s); err == nil {
return ":" + s
}
return s
+6
View File
@@ -143,6 +143,12 @@ func TestEnsurePortFormat(t *testing.T) {
if given != expected {
t.Fatalf("expected ensurePortFormat to not add a colon when it's present but got %v", given)
}
port = "127.0.0.1:3000"
expected = "127.0.0.1:3000"
given = ensurePortFormat(port)
if given != expected {
t.Fatalf("expected ensurePortFormat to not add a colon when it's present but got %v", given)
}
}
func TestStorageEnvOverrides(t *testing.T) {