Browse Source

Cast function to the appropriate signal otherwise it won't match the

expected runtime type.

This is a limitation of signals using Go's runtime type conversion.
signals-integration
Benjamin Shelton 4 weeks ago
parent
commit
5708d1fd85
1 changed files with 8 additions and 6 deletions
  1. +8
    -6
      funcs.go

+ 8
- 6
funcs.go View File

@ -23,17 +23,19 @@ func DependencyMapper() *mappers.DependencyMapper {
// AttachTemplateVar attaches a variable to the global template context with the
// specified name and value.
func AttachTemplateVar(name string, val interface{}) {
signals.Connect(SigEachRoute, func(r *Router, rt *Route) {
rt.Renderer.GlobalContext(name, val)
})
signals.Connect(SigEachRoute,
OnEachRoute(func(r *Router, rt *Route) {
rt.Renderer.GlobalContext(name, val)
}))
}
// AttachTemplateFunc attaches a function or callable to the global template
// context using the provided name.
func AttachTemplateFunc(name string, fn interface{}) {
signals.Connect(SigEachRoute, func(r *Router, rt *Route) {
rt.Renderer.SetFunc(name, fn)
})
signals.Connect(SigEachRoute,
OnEachRoute(func(r *Router, rt *Route) {
rt.Renderer.SetFunc(name, fn)
}))
}
// Private method for binding individual routers to the backend Chi muxer.


Loading…
Cancel
Save