Preparation for Root Path

master
kreativmonkey 7 years ago
parent 8cfebbeebf
commit 6acc5619e7

@ -13,17 +13,19 @@ func DefaultConfig() Config {
Host: "localhost", Host: "localhost",
Port: "6889", Port: "6889",
Title: "Sgot", Title: "Sgot",
RootPath: "./",
} }
} }
type Config struct { type Config struct {
DB string `env:"SHRT_DB_FILE"` RootPath string `env:"SHRTY_ROOT_PATH"`
APIkey string `env:"SHRT_API_KEY"` DB string `env:"SHRTY_DB_FILE"`
Host string `env:"SHRT_HOST"` APIkey string `env:"SHRTY_API_KEY"`
Port string `env:"SHRT_PORT"` Host string `env:"SHRTY_HOST"`
Domain string `env:"SHRT_DOMAIN"` Port string `env:"SHRTY_PORT"`
Title string `env:"SHRT_TITLE"` Domain string `env:"SHRTY_DOMAIN"`
CheckDomain bool `env:"SHRT_CHECK_DOMAIN"` Title string `env:"SHRTY_TITLE"`
CheckDomain bool `env:"SHRTY_CHECK_DOMAIN"`
} }
func (c Config) HostPort() string { func (c Config) HostPort() string {
@ -48,6 +50,7 @@ func readConfig(f *flag.FlagSet, args []string) (*Config, error){
return nil, err return nil, err
} }
f.StringVar(&config.RootPath, "root", config.RootPath, "The path to the shrty root directory.")
f.StringVar(&config.Host, "host", config.Host, "The host to listen on") f.StringVar(&config.Host, "host", config.Host, "The host to listen on")
f.StringVar(&config.Port, "port", config.Port, "The port to listen on") f.StringVar(&config.Port, "port", config.Port, "The port to listen on")
f.StringVar(&config.APIkey, "apikey", config.APIkey, "The Key to connect to the API") f.StringVar(&config.APIkey, "apikey", config.APIkey, "The Key to connect to the API")

@ -24,6 +24,7 @@ func TestConfig_ReadConfig(t *testing.T){
"--title=title", "--title=title",
"--apikey=apikey", "--apikey=apikey",
"--domain=domain", "--domain=domain",
"--root=root"
} }
expected := &Config{ expected := &Config{
@ -33,6 +34,7 @@ func TestConfig_ReadConfig(t *testing.T){
Title: "title", Title: "title",
APIkey: "apikey", APIkey: "apikey",
Domain: "domain", Domain: "domain",
RootPath: "root",
} }
cfg, err := readConfig(flag.NewFlagSet("", flag.ContinueOnError), input) cfg, err := readConfig(flag.NewFlagSet("", flag.ContinueOnError), input)
@ -41,18 +43,20 @@ func TestConfig_ReadConfig(t *testing.T){
} }
func TestConfig_ReadConfigFromEnv(t *testing.T) { func TestConfig_ReadConfigFromEnv(t *testing.T) {
assert.NoError(t, os.Setenv("SHRT_DB_FILE", "db")) assert.NoError(t, os.Setenv("SHRTY_DB_FILE", "db"))
defer os.Unsetenv("SHRT_DB_FILE") defer os.Unsetenv("SHRTY_DB_FILE")
assert.NoError(t, os.Setenv("SHRT_API_KEY", "apikey")) assert.NoError(t, os.Setenv("SHRTY_API_KEY", "apikey"))
defer os.Unsetenv("SHRT_API_KEY") defer os.Unsetenv("SHRTY_API_KEY")
assert.NoError(t, os.Setenv("SHRT_HOST", "host")) assert.NoError(t, os.Setenv("SHRTY_HOST", "host"))
defer os.Unsetenv("SHRT_HOST") defer os.Unsetenv("SHRTY_HOST")
assert.NoError(t, os.Setenv("SHRT_PORT", "port")) assert.NoError(t, os.Setenv("SHRTY_PORT", "port"))
defer os.Unsetenv("SHRT_PORT") defer os.Unsetenv("SHRTY_PORT")
assert.NoError(t, os.Setenv("SHRT_DOMAIN", "domain")) assert.NoError(t, os.Setenv("SHRTY_DOMAIN", "domain"))
defer os.Unsetenv("SHRT_DOMAIN") defer os.Unsetenv("SHRTY_DOMAIN")
assert.NoError(t, os.Setenv("SHRT_TITLE", "title")) assert.NoError(t, os.Setenv("SHRTY_TITLE", "title"))
defer os.Unsetenv("SHRT_TITLE") defer os.Unsetenv("SHRTY_TITLE")
assert.NoError(t, os.Setenv("SHRTY_ROOT_PATH", "root"))
defer os.Unsetenv("SHRTY_ROOT_PATH")
expected := &Config{ expected := &Config{
Host: "host", Host: "host",
@ -61,6 +65,7 @@ func TestConfig_ReadConfigFromEnv(t *testing.T) {
Title: "title", Title: "title",
APIkey: "apikey", APIkey: "apikey",
Domain: "domain", Domain: "domain",
RootPath: "root",
} }
cfg, err := readConfig(flag.NewFlagSet("", flag.ContinueOnError), []string{}) cfg, err := readConfig(flag.NewFlagSet("", flag.ContinueOnError), []string{})

Loading…
Cancel
Save