Skip to content

Commit

Permalink
Update template.tmpl
Browse files Browse the repository at this point in the history
  • Loading branch information
heppu committed Mar 28, 2020
1 parent 2bc4d14 commit e2466d0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cmd/embdr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func main() {
}

const name = "template.tmpl"
tmpl, err := embdr.LoadTemplate(name)
tmpl, err := embdr.Load(name)
if err != nil {
logAndExitf("Couldn't get template with name: %s", err)
}
Expand Down
2 changes: 2 additions & 0 deletions encoding.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Package embdr provides functions for encoding and decoding data in gz compressed base64 format.
package embdr

//go:generate go run ./cmd/embdr/main.go -p embdr -o template.go template.tmpl

import (
"bytes"
"compress/gzip"
Expand Down
24 changes: 12 additions & 12 deletions template.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions template.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ import (

var ErrTemplateDoesNotExist = errors.New("template doesn't exists")

var templates = map[string]string{
var files = map[string]string{
{{- range $key, $value := .Templates}}
"{{ $key }}": `
{{$value}}`,
{{- end}}
}

// LoadTemplate returns content of embedded template where name is the the path passed to emdbr.
func LoadTemplate(name string) (string, error) {
decoded, ok := templates[name]
// Load returns content of embedded template where name is the the path passed to emdbr.
func Load(name string) (string, error) {
decoded, ok := files[name]
if !ok {
return "", ErrTemplateDoesNotExist
}
Expand Down

0 comments on commit e2466d0

Please sign in to comment.