aboutsummaryrefslogtreecommitdiff
path: root/resources.go
blob: 30b0de5b4222042a1ae6ef10da06b1698f64618f (plain) (blame)
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
package main

import (
	"embed"
	"html/template"
	"io/fs"
	"net/http"
)

//go:embed .gitignore LICENSE README.md
//go:embed *.go go.mod go.sum
//go:embed *.scfg
//go:embed static/* templates/*
var source_fs embed.FS

func serve_source() {
	http.Handle("/source/",
		http.StripPrefix(
			"/source/",
			http.FileServer(http.FS(source_fs)),
		),
	)
}

//go:embed templates/* static/*
var resources_fs embed.FS

var templates *template.Template

func load_templates() (err error) {
	templates, err = template.New("templates").Funcs(template.FuncMap{
		"first_line": first_line,
		"base_name":  base_name,
	}).ParseFS(resources_fs, "templates/*")
	return err
}

func serve_static() (err error) {
	static_fs, err := fs.Sub(resources_fs, "static")
	if err != nil {
		return err
	}
	http.Handle("/static/",
		http.StripPrefix(
			"/static/",
			http.FileServer(http.FS(static_fs)),
		),
	)
	return nil
}