feat: allow port to be set in config
This commit is contained in:
@@ -7,12 +7,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
Port int `json:"port"`
|
||||||
DatabasePath string `json:"databasePath"`
|
DatabasePath string `json:"databasePath"`
|
||||||
TemplateDirectoryPath string `json:"templateDirectoryPath"`
|
TemplateDirectoryPath string `json:"templateDirectoryPath"`
|
||||||
HostKeyDirectoryPath string `json:"hostKeyDirectoryPath"`
|
HostKeyDirectoryPath string `json:"hostKeyDirectoryPath"`
|
||||||
HostName string `json:"hostName"`
|
HostName string `json:"hostName"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const defaultPort = 8080
|
||||||
|
|
||||||
func ReadConfigFrom(reader io.Reader) (Config, error) {
|
func ReadConfigFrom(reader io.Reader) (Config, error) {
|
||||||
var config Config
|
var config Config
|
||||||
err := json.NewDecoder(reader).Decode(&config)
|
err := json.NewDecoder(reader).Decode(&config)
|
||||||
@@ -35,5 +38,9 @@ func ReadConfigFrom(reader io.Reader) (Config, error) {
|
|||||||
return Config{}, err
|
return Config{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.Port == 0 {
|
||||||
|
config.Port = defaultPort
|
||||||
|
}
|
||||||
|
|
||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user