Skip to content
Permalink
Browse files

bindata instead of packr.

  • Loading branch information...
fiatjaf committed Dec 26, 2018
1 parent 97781a3 commit 9d0cc1376568fd6f0515832ae5311c3868c4a788
Showing with 25 additions and 15 deletions.
  1. +1 −2 .gitignore
  2. +8 −3 Makefile
  3. +2 −2 handlers.go
  4. +14 −8 main.go
@@ -9,5 +9,4 @@ bundle.js
*.DS_Store
*package-lock.json
permissionsfortrello
packrd
main-packr.go
bindata.go
@@ -1,5 +1,10 @@
all:
all: tmpl/bindata.go public/bindata.go
go build

prod:
packr2 build
public/bindata.go: $(shell find public)
mkdir -p public
go-bindata -o public/bindata.go -pkg public public/...

tmpl/bindata.go: $(shell find templates)
mkdir -p tmpl
go-bindata -o tmpl/bindata.go -pkg tmpl templates/...
@@ -11,7 +11,7 @@ import (
)

func ServeIndex(w http.ResponseWriter, r *http.Request) {
err = tmpl.ExecuteTemplate(w, "index.html", nil)
err = parsedtemplates.index.Execute(w, nil)
if err != nil {
log.Warn().Err(err).Msg("failed to render /")
}
@@ -144,7 +144,7 @@ WHERE id = ANY (string_to_array($1, ','))
}
}

err = tmpl.ExecuteTemplate(w, "account.html", struct {
err = parsedtemplates.account.Execute(w, struct {
Username string
Email string
Boards []Board
22 main.go
@@ -4,10 +4,12 @@ import (
"net/http"
"net/url"
"os"
"text/template"
"permissionsfortrello/public"
"permissionsfortrello/tmpl"
"time"

"github.com/gobuffalo/packr/v2"
"github.com/arschles/go-bindata-html-template"
"github.com/elazarl/go-bindata-assetfs"
"github.com/gorilla/mux"
"github.com/gorilla/sessions"
"github.com/graphql-go/graphql"
@@ -39,11 +41,14 @@ var c *oauth.Consumer
var pg *sqlx.DB
var rds *redis.Client
var ms3 *minio.Client
var tmpl *template.Template
var store sessions.Store
var router *mux.Router
var schema graphql.Schema
var log = zerolog.New(os.Stderr).Output(zerolog.ConsoleWriter{Out: os.Stderr})
var parsedtemplates struct {
index *template.Template
account *template.Template
}

func main() {
err = envconfig.Process("", &s)
@@ -66,7 +71,8 @@ func main() {
)

// templates
tmpl = template.Must(template.New("~").ParseGlob("templates/*.html"))
parsedtemplates.index = template.Must(template.New("index", tmpl.Asset).Parse("templates/index.html"))
parsedtemplates.account = template.Must(template.New("account", tmpl.Asset).Parse("templates/account.html"))

// oauth consumer
c = oauth.NewConsumer(
@@ -103,8 +109,8 @@ func main() {
}
}

// static assets
pubBox := packr.New("public", "./public")
// public http assets
httpPublic := &assetfs.AssetFS{Asset: public.Asset, AssetDir: public.AssetDir, Prefix: "public"}

// define routes
router = mux.NewRouter()
@@ -116,11 +122,11 @@ func main() {
router.Path("/setBoard").Methods("POST").HandlerFunc(handleSetupBoard)
router.Path("/_/webhooks/board").Methods("HEAD").HandlerFunc(returnOk)
router.Path("/_/webhooks/board").Methods("POST").HandlerFunc(handleWebhook)
router.PathPrefix("/public/").Methods("GET").Handler(http.FileServer(pubBox))
router.PathPrefix("/public/").Methods("GET").Handler(http.FileServer(httpPublic))
router.Path("/favicon.ico").Methods("GET").HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "image/svg+xml")
iconf, _ := pubBox.Open("icon.svg")
iconf, _ := httpPublic.Open("icon.svg")
fstat, _ := iconf.Stat()
http.ServeContent(w, r, "icon.svg", fstat.ModTime(), iconf)
return

0 comments on commit 9d0cc13

Please sign in to comment.
You can’t perform that action at this time.