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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the go:embed API to lookup templates #2262

Merged
merged 6 commits into from Jun 30, 2022

Conversation

clayne11
Copy link
Contributor

@clayne11 clayne11 commented Jun 29, 2022

Add a new template config option TemplateFS. If this is passed we will use it as the source to lookup files as opposed to trying to read the file system directly.

Fixes #2260

I have:

  • Added tests covering the bug / feature (see testing)
  • Updated any relevant documentation (see docs)

Users are expected to pass in the FS by using the embed API.
Doesn't look like anything has changed though. Maybe just a different
whitespace character.
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.08%) to 75.075% when pulling 5ed1c9f on clayne11:curtis.layne/embed into 53ca207 on 99designs:master.

@StevenACoffman StevenACoffman merged commit 34bbc45 into 99designs:master Jun 30, 2022
@douglaswth douglaswth mentioned this pull request Jul 27, 2023
2 tasks
StevenACoffman pushed a commit that referenced this pull request Jul 27, 2023
- According to the documentation comment for [templates.Options], if the
  `Template` and `TemplateFS` fields are empty, it `Render` should find
  the `.gotpl` files from the calling plugin. However, it looks like
  this is broken since #2262 moved the resolution code to a separate
  helper function. This results in broken behavior in consumers such as
  [infiotinc/gqlgenc](https://github.com/infiotinc/gqlgenc) when they
  use the latest version of `gqlgen` as instead of finding the template
  from the plugin, the test template from this package is used which
  outputs only: `this is my test package`.
- The cause for this is that `runtime.Caller` was still only skipping
  one stack level which means that it was finding the `Render` function
  instead of its caller.

[templates.Options]: https://pkg.go.dev/github.com/99designs/gqlgen@v0.17.35/codegen/templates#Options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Embed templates into source
3 participants