Reste à prévoir la pagination et la recherche

This commit is contained in:
Laurent Ulrich
2025-08-20 16:19:55 +02:00
parent 10ebdaad4a
commit 9dd396e95f
8 changed files with 183 additions and 70 deletions

View File

@@ -6,6 +6,7 @@ import (
"fmt"
"log"
"os"
"time"
)
//go:embed html/index.tmpl
@@ -14,6 +15,9 @@ var indexTemplate string
//go:embed html/entry.tmpl
var entryTemplate string
//go:embed html/styles.css
var nativeCSS string
func main() {
var err error
@@ -26,7 +30,6 @@ func main() {
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 {
@@ -60,24 +63,34 @@ func main() {
blog.Lang = "fr-FR"
blog.Title = configuration.Title
go MailboxFetcher(configuration, &blog)
StartServer(&blog)
StartServer(configuration, &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)
for {
err := mb.Connect()
if err != nil {
log.Fatal(err)
}
posts, err := mb.GetMessages()
if err != nil {
log.Println(err)
mb.Close()
time.Sleep(10 * time.Second)
continue
}
mb.Close()
blog.mutex.Lock()
blog.Posts = posts
blog.mutex.Unlock()
time.Sleep(10 * time.Second)
}
blog.mutex.Lock()
defer blog.mutex.Unlock()
blog.Posts = posts
}