mirror of
https://github.com/gomods/athens
synced 2026-02-03 11:00:32 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user