Skip to content

Commit

Permalink
refactor: from packr2 to statik
Browse files Browse the repository at this point in the history
  • Loading branch information
tympanix committed Mar 18, 2019
1 parent becdd0d commit 25a41ab
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ coverage.txt
/docs/resources
/docs/public

# Packd
/packrd
*-packr.go
# Statik
statik

# Web
/web/build
11 changes: 4 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,23 @@ TAG := $(shell git tag -l --points-at @)
setup:
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
go get -u golang.org/x/tools/cmd/cover
go get -u github.com/gobuffalo/packr/v2/packr2
go get -u github.com/rakyll/statik
npm install
dep ensure

build:
npm run build
go generate

clean:
rm -rf web/build
rm -rf docs/public
rm -rf dist
packr2 clean

mest:
go test -race -coverpkg=./... -coverprofile=coverage.txt -covermode=atomic ./...

prerelease:
packr2

release: prerelease
release:
ifdef TAG
git status
curl -sL http://git.io/goreleaser | bash
Expand All @@ -40,7 +37,7 @@ docs:
git submodule update --recursive --remote
cd docs && hugo && cd ..

dist: clean build prerelease
dist: clean build
goreleaser release --skip-publish --skip-validate

ci: build test codecov release
Expand Down
20 changes: 14 additions & 6 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ package app

import (
"errors"
"log"
"net/http"
"os"
"path"
"path/filepath"
"strings"
"time"

packr "github.com/gobuffalo/packr/v2"
"github.com/rakyll/statik/fs"

_ "github.com/tympanix/supper/statik"

"github.com/tympanix/supper/api"
"github.com/tympanix/supper/app/cfg"
"github.com/tympanix/supper/media"
Expand All @@ -27,7 +31,6 @@ var filetypes = []string{
type Application struct {
types.Provider
*http.ServeMux
box *packr.Box
cfg types.Config
scrapers []types.Scraper
}
Expand All @@ -36,7 +39,6 @@ type Application struct {
func New(cfg types.Config) *Application {
app := &Application{
Provider: cfg.Providers()[0],
box: packr.New("webfiles", webRoot),
cfg: cfg,
ServeMux: http.NewServeMux(),
scrapers: cfg.Scrapers(),
Expand All @@ -61,12 +63,18 @@ func (a *Application) Config() types.Config {
}

func (a *Application) webAppHandler() http.Handler {
const index = "index.html"
webfs, err := fs.New()

if err != nil {
log.Fatal(err)
}

const index = "/index.html"

return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
f, err := a.box.Open(r.URL.Path)
f, err := webfs.Open(r.URL.Path)
if len(path.Ext(r.URL.Path)) == 0 || err != nil {
if f, err = a.box.Open(index); err != nil {
if f, err = webfs.Open(index); err != nil {
http.Error(w, "404: not found", http.StatusNotFound)
return
}
Expand Down
2 changes: 2 additions & 0 deletions supper.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:generate statik -src=web/build

package main

import "github.com/tympanix/supper/app/cli"
Expand Down

0 comments on commit 25a41ab

Please sign in to comment.