2024-09-13 03:03:39 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-10-06 14:39:07 +00:00
|
|
|
httpKit "forge.karnov.club/marc/http-api-kit"
|
2024-09-13 03:03:39 +00:00
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
var SharedCache *Datastore
|
|
|
|
|
|
|
|
var routeMap = map[string]http.HandlerFunc{
|
|
|
|
"/": listContent,
|
|
|
|
"/about": about,
|
|
|
|
"/manage": manageContent,
|
|
|
|
"/ping": healthcheck,
|
|
|
|
}
|
|
|
|
|
2024-10-06 14:39:07 +00:00
|
|
|
var bgTasks = []httpKit.BackgroundTask{
|
|
|
|
{Handler: refreshFeeds, Interval: 10 * time.Minute},
|
2024-09-13 04:38:46 +00:00
|
|
|
}
|
|
|
|
|
2024-09-13 03:03:39 +00:00
|
|
|
func main() {
|
|
|
|
SharedCache = &Datastore{
|
|
|
|
Data: map[string]string{},
|
|
|
|
}
|
|
|
|
|
|
|
|
if existingStore := FromFile("datastore.json"); existingStore != nil {
|
|
|
|
SharedCache = existingStore
|
|
|
|
}
|
|
|
|
|
2024-10-06 14:39:07 +00:00
|
|
|
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")
|
2024-09-13 03:03:39 +00:00
|
|
|
}
|