embed templates #4

Closed
opened 2022-07-16 22:28:33 +02:00 by wanderer · 2 comments
Owner

there are currently issues with accessing the templates directly on the filesystem depending on whether or not we're running unit tests or running the program normally™ (and there is an ugly hack in place to determine that), the overall logic atm also assumes access to the templates at hardcoded places..

this all begs for a rework and the best I can come up with right now is to embed the template files directly into the binary at compile time. that way we can always access them, via some function of sorts, perhaps.

sth like this would do:

...

import _ "embed"

//go:embed report/templates/<sth>.tmpl
var tmplSth []byte

...

tmplSth could then be realised like this (notice the []byte to string conversion):

t, err := tmpl.Parse(string(tmplSth))
there are currently issues with accessing the templates directly on the filesystem depending on whether or not we're running unit tests or running the program *normally™* (and there is an [ugly hack](https://git.dotya.ml/wanderer/math-optim/src/commit/496ddc191abe4dea9253069010bea30e70e7699e/report/pic.go#L49-L58) in place to determine that), the overall logic atm also assumes access to the templates at hardcoded places.. this all begs for a rework and the best I can come up with right now is to embed the template files directly into the binary at compile time. that way we can always access them, via some function of sorts, perhaps. sth like this would do: ```go ... import _ "embed" //go:embed report/templates/<sth>.tmpl var tmplSth []byte ... ``` `tmplSth` could then be realised like this (notice the []byte to string conversion): ```go t, err := tmpl.Parse(string(tmplSth)) ```
wanderer added this to the v0.0.1 milestone 2022-07-16 22:28:33 +02:00
wanderer added the
enhancement
label 2022-07-16 22:28:33 +02:00
wanderer self-assigned this 2022-07-16 22:28:33 +02:00
Author
Owner

partly solved in 446f63b59e

partly solved in https://git.dotya.ml/wanderer/math-optim/commit/446f63b59e751892945bd6e494f702e9a63f5e82
Author
Owner

solved in 7742642e14

what's left for later is to rework the code-generating part to emitting stuff (report.tex) during runtime instead.

solved in https://git.dotya.ml/wanderer/math-optim/commit/7742642e14b0ba90e81310a43a5d3f73430ac773 what's left for later is to rework the code-generating part to emitting stuff (`report.tex`) during runtime instead.
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: wanderer/math-optim#4
No description provided.