Skip to content

Commit

Permalink
switch to go embed and do some cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
equinox0815 committed Dec 22, 2023
1 parent ee9342f commit 667282d
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 457 deletions.
19 changes: 11 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ endif
EXECUTEABLE := whawty-auth

all: build
.PHONY: vet format ui build clean distclean
.PHONY: format vet cover serve-cover clean distclean

format:
$(GOCMD) fmt ./...
Expand All @@ -47,24 +47,27 @@ vet:
test: vet
$(GOCMD) test `$(GOCMD) list ./... | grep -v 'sasl/examples'`

test-verbose: vet
$(GOCMD) test -v `$(GOCMD) list ./... | grep -v 'sasl/examples'`

cover:
$(GOCMD) test `$(GOCMD) list ./... | grep -v 'sasl/examples'` -covermode=count -coverprofile=.coverprofile
$(GOCMD) tool cover -html=.coverprofile
mkdir -p ./.coverage
$(GOCMD) test -v `$(GOCMD) list ./... | grep -v 'sasl/examples'` -covermode=count -coverprofile=./.coverage/profile
$(GOCMD) tool cover -html=./.coverage/profile -o ./.coverage/index.html

ui:
$(GOCMD) generate ./ui
serve-cover:
cd ./.coverage; python3 -m http.server

build: test ui
build: test
$(GOCMD) build -o $(EXECUTEABLE) ./cmd/whawty-auth

dev:
dev: test
$(GOCMD) build -o $(EXECUTEABLE) -tags=dev ./cmd/whawty-auth

clean:
rm -f $(EXECUTEABLE)

distclean: clean
rm -f ui/assets_vfsdata.go
rm -f doc/man/$(EXECUTEABLE).8

manpage: doc/man/$(EXECUTEABLE).8
Expand Down
2 changes: 1 addition & 1 deletion cmd/whawty-auth/web_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ func runWebApi(listener *net.TCPListener, config *webConfig, store *Store) (err
mux.Handle("/api/list", webHandler{store, sessions, handleWebList})
mux.Handle("/api/list-full", webHandler{store, sessions, handleWebListFull})

mux.Handle("/admin/", http.StripPrefix("/admin/", http.FileServer(ui.Assets)))
mux.Handle("/admin/", http.StripPrefix("/admin/", http.FileServer(http.FS(ui.Assets))))

mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spreadspace/tlsconfig v0.0.0-20230726215100-56bbcafa5d60 h1:YtR/I+Q4cFIg0Hy7F+EbIw5uhf3NtZnW5O9y87U+71U=
github.com/spreadspace/tlsconfig v0.0.0-20230726215100-56bbcafa5d60/go.mod h1:taZ6lrQmZk4/XnC6stKWRIFSnj6SeBvtZ4nyAjN4nig=
github.com/spreadspace/tlsconfig v0.0.0-20231204130624-c2b29e15e371 h1:fvsj77T5rb+uUJleTcnRZcEPIBLzovfDPfUHD8xe9HU=
github.com/spreadspace/tlsconfig v0.0.0-20231204130624-c2b29e15e371/go.mod h1:taZ6lrQmZk4/XnC6stKWRIFSnj6SeBvtZ4nyAjN4nig=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
6 changes: 3 additions & 3 deletions ui/assets.go → ui/assets_dev.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build dev
// +build dev

//
// Copyright (c) 2016-2019 whawty contributors (see AUTHORS file)
Expand Down Expand Up @@ -34,7 +33,8 @@
package ui

import (
"net/http"
"io/fs"
"os"
)

var Assets http.FileSystem = http.Dir("ui/assets")
var Assets fs.FS = os.DirFS("ui/assets")
21 changes: 20 additions & 1 deletion ui/ui.go → ui/assets_embed.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//go:generate go run assets_generate.go
//go:build !dev

//
// Copyright (c) 2016-2019 whawty contributors (see AUTHORS file)
// All rights reserved.
Expand Down Expand Up @@ -30,3 +31,21 @@
//

package ui

import (
"embed"
"io/fs"
)

//go:embed assets
var embeddedAssets embed.FS

var Assets fs.FS

func init() {
var err error
Assets, err = fs.Sub(embeddedAssets, "assets")
if err != nil {
panic(err)
}
}
53 changes: 0 additions & 53 deletions ui/assets_generate.go

This file was deleted.

389 changes: 0 additions & 389 deletions ui/assets_vfsdata.go

This file was deleted.

0 comments on commit 667282d

Please sign in to comment.