Files
schreifuchs.ch/internal/handlers/restgallery/resource.go
T
2026-05-31 10:46:07 +02:00

41 lines
843 B
Go

package restgallery
import (
"context"
"fmt"
"io"
"net/http"
"net/url"
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/components/images"
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/pkg/config"
"github.com/a-h/templ"
)
type Handler struct {
http.Handler
srv galleryService
r renderer
cfg *config.Gallery
}
func New(renderer renderer, srv galleryService, cfg *config.Gallery) *Handler {
mux := http.NewServeMux()
h := &Handler{
Handler: mux,
srv: srv,
r: renderer,
cfg: cfg,
}
mux.HandleFunc(fmt.Sprintf("GET /%s", url.PathEscape(cfg.Path)), h.gallery)
return h
}
type galleryService interface {
GetImages(ctx context.Context) (imgs []images.Image, err error)
}
type renderer interface {
Render(ctx context.Context, w io.Writer, r *http.Request, component templ.Component)
}