~emersion/hottub

bcc2fb9027a6a45983b399d4b28b81c5d57a726c — Simon Ser 4 months ago 5f75a29
build: add Makefile
2 files changed, 34 insertions(+), 2 deletions(-)

A Makefile
M main.go
A Makefile => Makefile +27 -0
@@ 0,0 1,27 @@
GO ?= go
GOFLAGS ?=
DESTDIR ?=
PREFIX ?= /usr/local
BINDIR ?= bin
DATADIR ?= share

goldflags = \
	-X 'main.StaticDir=$(PREFIX)/$(DATADIR)/hottub/static' \
	-X 'main.TemplatesDir=$(PREFIX)/$(DATADIR)/hottub/templates'

all: hottub

hottub:
	$(GO) build $(GOFLAGS) -ldflags="$(goldflags)" .

install:
	mkdir -p $(DESTDIR)$(PREFIX)/$(BINDIR)
	mkdir -p $(DESTDIR)$(PREFIX)/$(DATADIR)/hottub
	cp -f hottub $(DESTDIR)$(PREFIX)/$(BINDIR)
	cp -rf static/ $(DESTDIR)$(PREFIX)/$(DATADIR)/hottub/static/
	cp -rf templates/ $(DESTDIR)$(PREFIX)/$(DATADIR)/hottub/templates/

clean:
	rm -f hottub

.PHONY: hottub

M main.go => main.go +7 -2
@@ 27,6 27,11 @@ const (
	srhtGrants         = "builds.sr.ht/PROFILE:RO builds.sr.ht/JOBS:RW"
)

var (
	TemplatesDir = "templates"
	StaticDir    = "static"
)

func main() {
	var addr, dbFilename, appID, privateKeyFilename, webhookSecret, buildssrhtEndpoint, metasrhtEndpoint, srhtClientID, srhtClientSecret string
	flag.StringVar(&addr, "listen", ":3333", "listening address")


@@ 73,14 78,14 @@ func main() {
		log.Fatalf("failed to fetch app: %v", err)
	}

	tpl := template.Must(template.ParseGlob("templates/*.html"))
	tpl := template.Must(template.ParseGlob(TemplatesDir + "/*.html"))

	r := chi.NewRouter()
	r.Use(middleware.Logger)
	r.Use(middleware.Recoverer)
	r.Use(middleware.Timeout(60 * time.Second))

	r.Handle("/static/*", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
	r.Handle("/static/*", http.StripPrefix("/static/", http.FileServer(http.Dir(StaticDir))))

	r.Get("/", func(w http.ResponseWriter, r *http.Request) {
		data := struct {