We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
currently you can implement fmt.Fprintf like this:
fmt.Fprintf
package main import ( "io" "os" "text/template" ) func fprintf(w io.Writer, format string, a any) error { text, err := new(template.Template).Parse(format) if err != nil { return err } return text.Execute(w, a) } func main() { var a struct { Hello string World string } a.Hello = "hello" a.World = "world" fprintf(os.Stdout, "http://example.com/{{.Hello}}/{{.World}}", a) }
but you cannot do the opposite. ideally some method like this would exist:
func (t *Template) Scan(rd io.Reader, data any) error
then you could implement fmt.Fscanf:
fmt.Fscanf
package main import ( "io" "os" "text/template" ) func fscanf(r io.Reader, format string, a any) error { text, err := new(template.Template).Parse(format) if err != nil { return err } return text.Scan(r, a) } func main() { r := strings.NewReader("http://example.com/hello/world") var a struct { Hello string World string } fscanf(r, "http://example.com/{{.Hello}}/{{.World}}", &a) }
The text was updated successfully, but these errors were encountered:
I think this is a duplicate of #52473.
Sorry, something went wrong.
No branches or pull requests
Proposal Details
currently you can implement
fmt.Fprintf
like this:but you cannot do the opposite. ideally some method like this would exist:
then you could implement
fmt.Fscanf
:The text was updated successfully, but these errors were encountered: