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

Raising error on missing keys #221

Open
bbl opened this issue Feb 15, 2023 · 1 comment
Open

Raising error on missing keys #221

bbl opened this issue Feb 15, 2023 · 1 comment
Labels
🤔 Question Further information is requested

Comments

@bbl
Copy link

bbl commented Feb 15, 2023

Hello!

We're using the default HTML engine middleware. We want to return an error if a variable is not passed as a parameter.
It is possible to configure this behavior with a plain text/template package using the template.Option("missingkey=error") method here.

Is there a way to raise an error if there's no variable defined using Fiber's engine?

@iredmail
Copy link
Contributor

iredmail commented Mar 9, 2023

Did a quick check, current fiber html template engine doesn't support specifying options.

Would you like a send a PR for review? (btw, i'm not team member and don't have privilege to review and merge PR.)

  • Add a new internal field, e.g. options []string inside type Engine struct {}
  • Add a public method for Engine struct to set options. e.g.
type Engine struct {
	// ...

	// options for the template
	// FYI https://pkg.go.dev/html/template#Template.Option
	options []string
}

// Option sets 
func (e *Engine) SetOption(opts []string) {
	return e.options = opts
}
  • In method Render():
    • replace return lay.Execute(out, binding) by lay.Option(e.options...).Execute(out, binding).
    • replace return tmpl.Execute(out, binding) by return tmpl.Option(e.options...).Execute(out, binding)

@ReneWerner87 ReneWerner87 added the 🤔 Question Further information is requested label Mar 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤔 Question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants