mirror of
https://github.com/qdm12/ddns-updater.git
synced 2026-08-02 02:28:40 -04:00
- Added: asasalint, bidichk, containedctx, cyclop, decorder, durationcheck, errchkjson, errname, errorlint, execinquery, forcetypeassert, gomoddirectives, grouper, interfacebloat, maintidx, makezero, nilnil, nosprintfhostport, promlinter, reassign, tenv, usestdlibvars
50 lines
914 B
Go
50 lines
914 B
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"embed"
|
|
"net/http"
|
|
"text/template"
|
|
"time"
|
|
|
|
"github.com/go-chi/chi"
|
|
"github.com/go-chi/chi/middleware"
|
|
)
|
|
|
|
type handlers struct {
|
|
ctx context.Context //nolint:containedctx
|
|
// Objects
|
|
db Database
|
|
runner UpdateForcer
|
|
indexTemplate *template.Template
|
|
// Mockable functions
|
|
timeNow func() time.Time
|
|
}
|
|
|
|
//go:embed ui/*
|
|
var uiFS embed.FS
|
|
|
|
func newHandler(ctx context.Context, rootURL string,
|
|
db Database, runner UpdateForcer) http.Handler {
|
|
indexTemplate := template.Must(template.ParseFS(uiFS, "ui/index.html"))
|
|
|
|
handlers := &handlers{
|
|
ctx: ctx,
|
|
db: db,
|
|
indexTemplate: indexTemplate,
|
|
// TODO build information
|
|
timeNow: time.Now,
|
|
runner: runner,
|
|
}
|
|
|
|
router := chi.NewRouter()
|
|
|
|
router.Use(middleware.Logger)
|
|
|
|
router.Get(rootURL+"/", handlers.index)
|
|
|
|
router.Get(rootURL+"/update", handlers.update)
|
|
|
|
return router
|
|
}
|