petit ménage
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type MailBoxConfiguration struct {
|
||||
Server string
|
||||
Port string
|
||||
@@ -14,3 +20,56 @@ type BlogConfiguration struct {
|
||||
MailBox MailBoxConfiguration
|
||||
WWWRoot string
|
||||
}
|
||||
|
||||
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 same 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
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user