aboutsummaryrefslogtreecommitdiff
path: root/cmd/sanguisuga/admin.go
blob: 70c17159d15047abeb054ce34d64442bef4a50d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main

import (
	"embed"
	"log/slog"
	"net/http"
)

var (
	//go:embed tmpl/*
	templates embed.FS

	//go:embed static
	static embed.FS
)

//go:generate tailwindcss --output static/styles.css --minify

func (s *Sanguisuga) AdminIndex(w http.ResponseWriter, r *http.Request) {
	if r.URL.Path != "/" {
		w.WriteHeader(http.StatusNotFound)
		s.tmpl.ExecuteTemplate(w, "404.tmpl", struct {
			Title string
		}{
			Title: "Not found: " + r.URL.Path,
		})

		return
	}
	s.tmpl.ExecuteTemplate(w, "index.html", struct {
		Title string
	}{
		Title: "sanguisuga",
	})
}

func (s *Sanguisuga) AdminAnimeList(w http.ResponseWriter, r *http.Request) {
	err := s.tmpl.ExecuteTemplate(w, "anime_index.html", struct {
		Title string
	}{
		Title: "Anime",
	})
	if err != nil {
		slog.Error("can't render template", "err", err)
	}
}

func (s *Sanguisuga) AdminTVList(w http.ResponseWriter, r *http.Request) {
	err := s.tmpl.ExecuteTemplate(w, "tv_index.html", struct {
		Title string
	}{
		Title: "TV",
	})
	if err != nil {
		slog.Error("can't render template", "err", err)
	}
}