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

fix implementation of IEngineCore functions in Engine struct #300

Merged
merged 1 commit into from
Sep 29, 2023

Conversation

ip75
Copy link

@ip75 ip75 commented Sep 29, 2023

see #299 for description

@gaby
Copy link
Member

gaby commented Sep 29, 2023

@ReneWerner87 this is a breaking change, right? 🤔

@ReneWerner87
Copy link
Member

yes should be, because we lost the real engine type
but thats the only solution currently without a self keyword

@ReneWerner87
Copy link
Member

@ip75
Copy link
Author

ip75 commented Sep 29, 2023

see https://medium.com/@mier85/self-referencing-interfaces-in-golang-1-18-bcd6b5701992 https://stackoverflow.com/questions/41881113/interface-that-returns-its-self-cloneable golang/go#28254

i've gave up to do it with generics
https://go.googlesource.com/proposal/+/refs/heads/master/design/43651-type-parameters.md#no-parameterized-methods

I've made workaround solution with stub struct

var fs embed.FS

func NewTemplatesEngine() template.IEngine {
	mustache := mustache.NewFileSystem(http.FS(fs), ".mustache")
	return &StubEngine{Engine: mustache}
}


type StubEngine struct {
	*mustache.Engine
}

func (e *StubEngine) AddFunc(name string, fn interface{}) template.IEngineCore {
	e.Engine.AddFunc(name, fn)
	return e
}
func (e *StubEngine) AddFuncMap(m map[string]interface{}) template.IEngineCore {
	e.Engine.AddFuncMap(m)
	return e
}
func (e *StubEngine) Debug(enabled bool) template.IEngineCore {
	e.Engine.Debug(enabled)
	return e
}
func (e *StubEngine) Delims(left, right string) template.IEngineCore {
	e.Engine.Delims(left, right)
	return e
}
func (e *StubEngine) FuncMap() map[string]interface{} {
	return e.Engine.FuncMap()
}
func (e *StubEngine) Layout(key string) template.IEngineCore {
	e.Engine.Layout(key)
	return e
}
func (e *StubEngine) Reload(enabled bool) template.IEngineCore {
	e.Engine.Reload(enabled)
	return e
}

@ReneWerner87 ReneWerner87 merged commit 7ca689d into gofiber:master Sep 29, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❗ BreakingChange ☢️ Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🤗 [Question]: How to export mustache engine as a template.IEngine ?
3 participants