Last active
October 13, 2015 11:56
-
-
Save pote/79265bc8e09a9571a60e to your computer and use it in GitHub Desktop.
Golang binary embeddable views
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
echo "package views | |
const $(echo "$1" | tr a-z A-Z) = \`$(cat views/$1.html)\`" > src/views/$1.go |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# This Makefile is a slimmed down version from an actual project, to make deployment | |
# easier all the html files in `views/` are copied into Go files as constants and | |
# placed under `src/views/`, assuming `GOPATH="$PWD/.deps:$PWD" (1) this means that in | |
# your code you can get the contents of `views/index.html` as `views.INDEX`. | |
# | |
# There is also how I handle dependencies with gpm, which is unrelated, but I though | |
# I'd leave it for the hell of it. | |
# | |
# (1) You don't need to have that exact GOPATH, but "$PWD" does need to be included in | |
# it so you can import "views" from `src/views` and use it. | |
VIEWS = $(patsubst views/%.html,src/views/%.go,$(wildcard views/*.html)) | |
.deps/.installed: Godeps | |
gpm install && touch $@ | |
build: *.go .deps/.installed $(VIEWS) | |
go build -o <your_binary_name> | |
## | |
# Views -> Go files | |
## | |
src/views: | |
mkdir -p $@ | |
src/views/%.go: views/%.html | |
#echo 'package views\n\nconst $(shell echo $* | tr a-z A-Z) = `$(shell cat views/$*.html)`' > $@ | |
./asset_to_go "$*" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tené en
echo
a secas no interpreta los\n
:Para eso necesitás usar
-e
, así: