How to make custom variants of fmt.Printf()
and fmt.Sprintf()
etc.?
Query string: ?invalid-param
values := r.URL.Query()
for k, v := range values {
switch k {
case "valid-query-param":
// some code
default:
fmt.Printf("%s %Tn", k, k)
Customf("Invalid query param: %s", k)
return
}
}
func Customf(s string, args ...any){
fmt.Printf(s, args)
}
Output
invalid-param string
Invalid query param: [invalid-param]
In the output first it says that the query param k
is a string
, but in the second line it looks like it’s an []string
? Why is that?
New contributor
rick001 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.