package main import ( _ "embed" "encoding/json" "fmt" "log" "os" ) //go:embed html/index.tmpl var indexTemplate string //go:embed html/entry.tmpl var entryTemplate string func main() { var err error var configuration BlogConfiguration args := os.Args[1:] home := os.Getenv("HOME") err = os.MkdirAll(fmt.Sprintf("%s/.config/", home), 0600) if err != nil { log.Fatal(err) } configurationFileName := fmt.Sprintf("%s/.config/mailblog.json", home) log.Println("Mailblog starting using", configurationFileName) file, err := os.Open(configurationFileName) if err == nil { defer file.Close() decoder := json.NewDecoder(file) err = decoder.Decode(&configuration) if err != nil { log.Fatal(err) } } if len(args) > 0 { switch args[0] { case "configure": configuration.Prompt() file, err = os.Create(fmt.Sprintf("%s/.config/mailblog.json", home)) if err != nil { log.Fatal(err) } encoder := json.NewEncoder(file) err = encoder.Encode(configuration) if err != nil { log.Fatal(err) } fmt.Printf("Configuration save in %s/.config/mailblob.json\n", home) return } } var blog Blog blog.Lang = "fr-FR" blog.Title = configuration.Title go MailboxFetcher(configuration, &blog) StartServer(&blog) } func MailboxFetcher(configuration BlogConfiguration, blog *Blog) { var mb MailBox mb.Configure(&configuration.MailBox) err := mb.Connect() if err != nil { log.Fatal(err) } defer mb.Close() posts, err := mb.GetMessages() if err != nil { log.Println(err) } blog.mutex.Lock() defer blog.mutex.Unlock() blog.Posts = posts }