morning-coffee/main.go

46 lines
843 B
Go
Raw Permalink Normal View History

package main
import (
httpKit "forge.karnov.club/marc/http-api-kit"
"net/http"
"time"
)
var SharedCache *Datastore
var routeMap = map[string]http.HandlerFunc{
"/": listContent,
"/about": about,
"/manage": manageContent,
"/ping": healthcheck,
}
var bgTasks = []httpKit.BackgroundTask{
{Handler: refreshFeeds, Interval: 10 * time.Minute},
}
func main() {
SharedCache = &Datastore{
Data: map[string]string{},
}
if existingStore := FromFile("datastore.json"); existingStore != nil {
SharedCache = existingStore
}
app := httpKit.NewApp()
for routePath, routeHandler := range routeMap {
app.AddRoute(routePath, routeHandler)
}
for _, bgTask := range bgTasks {
app.AddBackgroundTask(bgTask)
}
app.AddStaticRoute("/static/", "./static")
app.AddMiddleware(httpKit.LoggingMiddleware)
app.Start(":9000")
}