package main import ( "fmt" "regexp" "strconv" ) type MailBoxConfiguration struct { Server string Port string User string Password string SSL string InBox string } type ServiceConfiguration struct { Address string Port string } type BlogConfiguration struct { Title string ShortName string MailBox MailBoxConfiguration Service ServiceConfiguration } func (configuration *BlogConfiguration) Prompt() error { var err error configuration.Title, err = prompt("Blog Title", nil, "", configuration.Title, false) if err != nil { return err } configuration.ShortName, err = prompt("Blog Short Name (only letters and numbers, no special signes)", nil, "blog", configuration.ShortName, false) if err != nil { return err } if !regexp.MustCompile(`^[a-zA-Z0-9]+$`).MatchString(configuration.ShortName) { return fmt.Errorf("short name invalid") } /* configuration.WWWRoot, err = prompt("Web Root directory", nil, fmt.Sprintf("/var/www/html/%s", configuration.ShortName), configuration.WWWRoot, false) if err != nil { return err } */ configuration.MailBox.Server, err = prompt("IMAP Server Hostname or IP", nil, "", configuration.MailBox.Server, false) if err != nil { return err } configuration.MailBox.Port, err = prompt("IMAP Server Port", nil, "993", configuration.MailBox.Port, false) if err != nil { return err } _, err = strconv.ParseUint(configuration.MailBox.Port, 10, 16) if err != nil { return fmt.Errorf("imap server port invalid") } configuration.MailBox.User, err = prompt("IMAP User Login", nil, "", configuration.MailBox.User, false) if err != nil { return err } configuration.MailBox.Password, err = prompt("IMAP User Password", nil, "", configuration.MailBox.Password, false) if err != nil { return err } options := [...]string{"SSL/TLS", "StartTLS", "NoTLS"} configuration.MailBox.SSL, err = prompt("IMAP SSL/TLS", options[:], "SSL/TLS", configuration.MailBox.SSL, false) if err != nil { return err } configuration.MailBox.InBox, err = prompt("IMAP INBOX", nil, "INBOX", configuration.MailBox.InBox, false) if err != nil { return err } configuration.Service.Address, err = prompt("Listen address", nil, "127.0.0.1", configuration.Service.Address, false) if err != nil { return err } configuration.Service.Port, err = prompt("Listen port", nil, "8080", configuration.Service.Port, false) if err != nil { return err } return nil }