Files
mailblog/mailblog.go
2025-07-31 17:06:30 +02:00

73 lines
1.3 KiB
Go

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)
}
file, err := os.Open(fmt.Sprintf("%s/.config/mailblog.json", home))
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 mb MailBox
mb.Configure(&configuration.MailBox)
err = mb.Connect()
if err != nil {
log.Fatal(err)
}
defer mb.Close()
var blog Blog
blog.Lang = "fr-FR"
blog.Title = configuration.Title
blog.Posts, err = mb.GetMessages()
if err != nil {
log.Fatal(err)
}
StartServer(&blog)
}