wisski-cloud-distillery/internal/dis/component/server/logo/logo.go
2023-02-10 12:01:06 +01:00

58 lines
1 KiB
Go

package logo
import (
"context"
"net/http"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
"github.com/FAU-CDI/wisski-distillery/pkg/httpx"
_ "embed"
)
type Logo struct {
component.Base
}
var (
_ component.Routeable = (*Logo)(nil)
)
func (*Logo) Routes() component.Routes {
return component.Routes{
Prefix: "/logo/",
Aliases: []string{"/favicon.ico", "/logo.svg"},
Exact: true,
}
}
var (
//go:embed favicon.ico
faviconICO []byte
//go:embed logo.svg
logoSVG []byte
)
var faviconRoute = httpx.Response{
ContentType: "image/x-icon",
Body: faviconICO,
}
var logoSVGRoute = httpx.Response{
ContentType: "image/svg+xml",
Body: httpx.MinifySVG(logoSVG),
}
func (*Logo) HandleRoute(ctx context.Context, path string) (http.Handler, error) {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/favicon.ico":
faviconRoute.ServeHTTP(w, r)
case "/logo.svg":
logoSVGRoute.ServeHTTP(w, r)
default:
http.NotFound(w, r)
}
}), nil
}