Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃拕 slight refactoring & adding some vague unit tests... #5

Merged
merged 1 commit into from
Jan 24, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,21 @@ func init() {
}
}

func createTemplate() *template.Template {
return template.New("template").Option("missingkey=error")
}

// RunTemplate -
func RunTemplate(in io.Reader, out io.Writer) {
s := bufio.NewScanner(in)
context := &Context{}
for s.Scan() {
tmpl, err := template.New("template").Option("missingkey=error").Parse(s.Text())
tmpl, err := createTemplate().Parse(s.Text())
if err != nil {
log.Fatalf("Line %q: %v\n", s.Text(), err)
}

if err := tmpl.Execute(out, &Context{}); err != nil {
if err := tmpl.Execute(out, context); err != nil {
panic(err)
}
out.Write([]byte("\n"))
Expand Down