update to how configs work

This commit is contained in:
dtookey 2022-08-09 11:46:49 -04:00
parent 85587cd2eb
commit 577525ebaf

View File

@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"geniuscartel.xyz/vinegar/vinegarUtil"
"io/ioutil"
)
type (
@ -66,10 +67,12 @@ func LoadConfig(pathlike string) *VinegarServlet {
}
return servlet
}
} else {
CreateBlankConfig()
panic("Could not find config file at" + pathlike)
return nil
}
}
func (e ConfigEntry) toRoute(serv *VinegarServlet) {
constructor, err := getConstructorFunction(e.ConfigType)
@ -90,3 +93,14 @@ func getConstructorFunction(t ConfigType) (RouteConstructor, error) {
}
return nil, errors.New(fmt.Sprintf("could not determine constructor for invalid ConfigType: %s", t))
}
func GenerateBlankConfig() {
fileName := "servlet.json.template.tmpl"
conf := CreateBlankConfig()
content, err := json.Marshal(&conf)
if err != nil {
panic(err)
}
fmt.Println("Generating a blank configuration file at ")
ioutil.WriteFile(fileName, content, 0755)
}