add listen address to the config

This commit is contained in:
Iris Lightshard 2024-10-27 13:30:20 -06:00
parent 2ed7370c2c
commit 716fa54d56
Signed by: Iris Lightshard
GPG key ID: 688407174966CAF3
2 changed files with 15 additions and 1 deletions

View file

@ -17,6 +17,7 @@ type Config struct {
StaticShowHTML bool // whether to show html files in the FileManager StaticShowHTML bool // whether to show html files in the FileManager
StaticMaxUploadMB int64 // max size in MB of files uploaded via FileManager StaticMaxUploadMB int64 // max size in MB of files uploaded via FileManager
AssetRoot string // root of Nirvash dist files (CSS, images) AssetRoot string // root of Nirvash dist files (CSS, images)
ListenAddress string // address the webserver listens on
Plugins map[string]interface{} Plugins map[string]interface{}
} }
@ -66,6 +67,7 @@ func (self *Config) SetAdapter(adapter string) {
func (self *Config) IsNull() bool { func (self *Config) IsNull() bool {
// zero-values for StaticShowHTML, StaticShowHidden, and StaticMaxUploadMB are valid // 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 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) ensureNonEmptyOption(&inputBuf)
self.AssetRoot = inputBuf self.AssetRoot = inputBuf
inputBuf = ""
fmt.Printf("nirvash listen address? ")
ensureNonEmptyOption(&inputBuf)
self.ListenAddress = inputBuf
inputBuf = "" inputBuf = ""
fmt.Printf("plugins? (not implemented yet) ") fmt.Printf("plugins? (not implemented yet) ")
ensureNonEmptyOption(&inputBuf) ensureNonEmptyOption(&inputBuf)
@ -169,6 +176,7 @@ func writeConfig(cfg *Config, configFile string) error {
f.WriteString("staticShowHidden=" + strconv.FormatBool(cfg.StaticShowHidden) + "\n") f.WriteString("staticShowHidden=" + strconv.FormatBool(cfg.StaticShowHidden) + "\n")
f.WriteString("staticMaxUploadMB=" + strconv.FormatInt(cfg.StaticMaxUploadMB, 10) + "\n") f.WriteString("staticMaxUploadMB=" + strconv.FormatInt(cfg.StaticMaxUploadMB, 10) + "\n")
f.WriteString("assetRoot=" + cfg.AssetRoot + "\n") f.WriteString("assetRoot=" + cfg.AssetRoot + "\n")
f.WriteString("listenAddress=" + cfg.ListenAddress + "\n")
f.WriteString("adapter=" + cfg.Adapter.Name() + "\n") f.WriteString("adapter=" + cfg.Adapter.Name() + "\n")
f.WriteString("plugins=\n") f.WriteString("plugins=\n")
return nil return nil
@ -209,6 +217,8 @@ func parseConfig(configFile string) *Config {
cfg.StaticMaxUploadMB, _ = strconv.ParseInt(v, 10, 64) cfg.StaticMaxUploadMB, _ = strconv.ParseInt(v, 10, 64)
case "assetRoot": case "assetRoot":
cfg.AssetRoot = v cfg.AssetRoot = v
case "listenAddress":
cfg.ListenAddress = v
case "plugins": case "plugins":
// not implemented // not implemented
case "adapter": case "adapter":

View file

@ -407,5 +407,9 @@ func main() {
http.MethodGet, http.MethodGet,
udb, udb,
"/login")) "/login"))
http.ListenAndServe(":8080", rtr)
if cfg.ListenAddress == "" {
cfg.ListenAddress = "127.0.0.1:8080"
}
http.ListenAndServe(cfg.ListenAddress, rtr)
} }