-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed
Labels
FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.ProposalProposal-Acceptedhelp wanted
Milestone
Description
The current eq function is limited only to "basic types", and it does not support other Go types that are comparable, like pointers or structs.
Also, it's not possible to decorate it, because it's private. Setting "eq": reflect.DeepEqual won't provide the same functionally, because cases like this:
package main
import (
"log"
"os"
"reflect"
"text/template"
)
func main() {
tmpl, err := template.New("titleTest").
Funcs(template.FuncMap{
"goeq": reflect.DeepEqual,
}).
Parse(`{{ eq .A 1 }} != {{ goeq .A 1 }}`)
if err != nil {
log.Fatalf("parsing: %s", err)
}
err = tmpl.Execute(os.Stdout, struct{ A int64 }{1})
if err != nil {
log.Fatalf("execution: %s", err)
}
// Output: true != false
}https://play.golang.org/p/zTg33Lggq0f
My current solution is just copying the current code from text/template/funcs.go, and adding the support by myself.
I would like to hear what others think about this, because it feels like a basic functionality that is missing when working with Go types.
If this proposal will be accepted, I will be more than happy to contribute my changes.
Metadata
Metadata
Assignees
Labels
FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.ProposalProposal-Acceptedhelp wanted