diff options
Diffstat (limited to 'config.go')
| -rw-r--r-- | config.go | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/config.go b/config.go new file mode 100644 index 0000000..e03a196 --- /dev/null +++ b/config.go @@ -0,0 +1,129 @@ +package main + +import ( + "bytes" + "fmt" + //"os" + "io/ioutil" + //"strconv" + "github.com/BurntSushi/toml" +) + +type Config struct { + Database string //`toml:"database"` + Name string //`toml:"name"` + Street string //`toml:"street"` + Zip string //`toml:"zip"` + City string //`toml:"city"` + Country string //`toml:"country"` + Telefon string //`toml:"telefon"` + Mobile string //`toml:"mobile"` + Mail string //`toml:"mail"` + Url string //`toml:"url"` + Taxid string //`toml:"taxid"` + Bankacc string //`toml:"bankacc"` + Banklz string //`toml:"banklz"` + Bankname string //`toml:"bankname"` + Iban string //`toml:"iban"` + Bic string //`toml:"bic"` +} + +var conffile string +var config Config + +func init() { + conffile = "laboravi.config.toml" +} + +func editConf() { + for { + if _, err := toml.DecodeFile(conffile, &config); err != nil { + //fmt.Println(err) + fmt.Println("Configuration file not found") + makeNewTOML(false) + }else{ + showConfig() + if isSure("Is this Configuration Correct?") { + break + }else{ + //if isSure("Enter new Configuration?"){ + makeNewTOML(true) + //}else{ + // fmt.Println("I Really Dont think I can Help You then...!") + //} + } + } + } +} + +func initConf() { + for { + if _, err := toml.DecodeFile(conffile, &config); err != nil { + //fmt.Println(err) + fmt.Println("Configuration file not found") + makeNewTOML(false) + }else{ + fmt.Println("Configuration loaded Successfully") + break + } + } +} + +func makeNewTOML(gibts bool) { + if gibts { + fmt.Println("Editing Configuration File\nPress [Enter] to keep the Current setting") + }else{ + fmt.Println("Making new Configuration File") + + //arr := []string{"", "", ""} + //ma0 := MailAccount{"","","",0,"",""} + //mm0 := MassMail{"","","",arr,""} + //Examplenames Coming soon + n := "" + config = Config{"mytimes.db",n,n,n,n,n,n,n,n,n,n,n,n,n,n,n} + } + //fmt.Println("Whats Your Namecount\n") + database := getNewInput("DB File Path: ",config.Database) + name := getNewInput("Whats your Name?: ",config.Name) + street := getNewInput("Street: ",config.Street) + zip := getNewInput("Zip Code: ",config.Zip) + city := getNewInput("City: ",config.City) + country := getNewInput("Country: ",config.City) + telefon := getNewInput("Telefone number: ",config.Telefon) + mobile := getNewInput("Mobile number: ",config.Mobile) + mail := getNewInput("Email: ",config.Mail) + url := getNewInput("URL: ",config.Url) + taxid := getNewInput("Tax ID: ",config.Taxid) + bankname := getNewInput("Bank Name: ",config.Bankname) + bankacc := getNewInput("Bank Account: ",config.Bankacc) + banklz := getNewInput("BLZ: ",config.Banklz) + iban := getNewInput("IBAN: ",config.Iban) + bic := getNewInput("BIC: ",config.Bic) + + conf := Config{database,name,street,zip,city,country,telefon,mobile,mail,url,taxid,bankacc,banklz,bankname,iban,bic} + + buf := new(bytes.Buffer) + err = toml.NewEncoder(buf).Encode(conf) + if err != nil { + panic(err) + }else{ + //fmt.Println("Conffile:\n",buf.String()) + fmt.Println("Writing Configuration File") + err = ioutil.WriteFile(conffile, buf.Bytes(), 0644) + checkErr(err) + } + +} + +func showConfig() { + buf := new(bytes.Buffer) + err := toml.NewEncoder(buf).Encode(config) + if err != nil { + panic(err) + }else{ + fmt.Println("Configuration:\n",buf.String()) + //fmt.Println(config) + } +} + + |
