add listen address to the config
This commit is contained in:
parent
2ed7370c2c
commit
716fa54d56
2 changed files with 15 additions and 1 deletions
|
@ -17,6 +17,7 @@ type Config struct {
|
|||
StaticShowHTML bool // whether to show html files in the FileManager
|
||||
StaticMaxUploadMB int64 // max size in MB of files uploaded via FileManager
|
||||
AssetRoot string // root of Nirvash dist files (CSS, images)
|
||||
ListenAddress string // address the webserver listens on
|
||||
Plugins map[string]interface{}
|
||||
}
|
||||
|
||||
|
@ -66,6 +67,7 @@ func (self *Config) SetAdapter(adapter string) {
|
|||
|
||||
func (self *Config) IsNull() bool {
|
||||
// zero-values for StaticShowHTML, StaticShowHidden, and StaticMaxUploadMB are valid
|
||||
// zero-value for ListenAddress is also OK, falls back on 127.0.0.1:8080
|
||||
return self.Adapter == nil || len(self.Root) == 0 || len(self.StaticRoot) == 0 || len(self.AssetRoot) == 0
|
||||
}
|
||||
|
||||
|
@ -112,6 +114,11 @@ func (self *Config) RunWizard() {
|
|||
ensureNonEmptyOption(&inputBuf)
|
||||
self.AssetRoot = inputBuf
|
||||
|
||||
inputBuf = ""
|
||||
fmt.Printf("nirvash listen address? ")
|
||||
ensureNonEmptyOption(&inputBuf)
|
||||
self.ListenAddress = inputBuf
|
||||
|
||||
inputBuf = ""
|
||||
fmt.Printf("plugins? (not implemented yet) ")
|
||||
ensureNonEmptyOption(&inputBuf)
|
||||
|
@ -169,6 +176,7 @@ func writeConfig(cfg *Config, configFile string) error {
|
|||
f.WriteString("staticShowHidden=" + strconv.FormatBool(cfg.StaticShowHidden) + "\n")
|
||||
f.WriteString("staticMaxUploadMB=" + strconv.FormatInt(cfg.StaticMaxUploadMB, 10) + "\n")
|
||||
f.WriteString("assetRoot=" + cfg.AssetRoot + "\n")
|
||||
f.WriteString("listenAddress=" + cfg.ListenAddress + "\n")
|
||||
f.WriteString("adapter=" + cfg.Adapter.Name() + "\n")
|
||||
f.WriteString("plugins=\n")
|
||||
return nil
|
||||
|
@ -209,6 +217,8 @@ func parseConfig(configFile string) *Config {
|
|||
cfg.StaticMaxUploadMB, _ = strconv.ParseInt(v, 10, 64)
|
||||
case "assetRoot":
|
||||
cfg.AssetRoot = v
|
||||
case "listenAddress":
|
||||
cfg.ListenAddress = v
|
||||
case "plugins":
|
||||
// not implemented
|
||||
case "adapter":
|
||||
|
|
|
@ -407,5 +407,9 @@ func main() {
|
|||
http.MethodGet,
|
||||
udb,
|
||||
"/login"))
|
||||
http.ListenAndServe(":8080", rtr)
|
||||
|
||||
if cfg.ListenAddress == "" {
|
||||
cfg.ListenAddress = "127.0.0.1:8080"
|
||||
}
|
||||
http.ListenAndServe(cfg.ListenAddress, rtr)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue