// saveConfig handles post requests to save the configuration data provided // in the system configuration form. This method will redirect if func saveConfig(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { if config.IsSet() { logAndRedirect(w, r, front, "Configuration already initialized") return } url := r.FormValue(fvHomePage) admin := r.FormValue(fvAdmin) clientID := r.FormValue(fvClientID) clientSecret := r.FormValue(fvClientSecret) path := r.FormValue(fvStorageLoc) conf, err := config.NewConfig(url, admin, clientID, clientSecret, path) if err != nil { // can't continue without proper configuration logErrorAndRedirect(w, r, startupPage, err) } if err := conf.Save(); err != nil { // can't continue without proper configuration logErrorAndRedirect(w, r, startupPage, err) } // set global configuration struct; will be accessible through config.Get() conf.SetCurrent() logAndRedirect(w, r, home, "Configuration initialized") }
func initConfig() { // load configuration data from the provided base path conf, err := config.Load(*path) if err != nil { glog.Errorln(err) // can't load config file; check if other command line arguments provided if *admin == "" || *url == "" || *clientID == "" || *clientSecret == "" { // no config provided; let user enter through startup page return } // create config based on command line arguments conf, err = config.NewConfig(*url, *admin, *clientID, *clientSecret, *path) if err != nil { // can't continue without proper configuration glog.Fatal(err) } if err := conf.Save(); err != nil { glog.Fatal(err) } } // set global configuration struct; will be accessible through config.Get() conf.SetCurrent() glog.Info("Configuration initialized") }