An alias for fmt.Sprintf
println
An alias for fmt.Sprintln
+ url
+ Returns the escaped value of the textual representation of
+ its arguments in a form suitable for embedding in a URL.
The boolean functions take any zero value to be false and a non-zero value to
be true.
// JavaScript.
{"js", `{{js .}}`, `It\'d be nice.`, `It'd be nice.`, true},
+ // URL.
+ {"url", `{{"http://www.example.org/"|url}}`, "http%3A%2F%2Fwww.example.org%2F", nil, true},
+
// Booleans
{"not", "{{not true}} {{not false}}", "false true", nil, true},
{"and", "{{and false 0}} {{and 1 0}} {{and 0 true}} {{and 1 1}}", "false 0 0 1", nil, true},
import (
"bytes"
"fmt"
+ "http"
"io"
"os"
"reflect"
"print": reflect.ValueOf(fmt.Sprint),
"printf": reflect.ValueOf(fmt.Sprintf),
"println": reflect.ValueOf(fmt.Sprintln),
+ "url": reflect.ValueOf(URLEscaper),
}
// addFuncs adds to values the functions in funcs, converting them to reflect.Values.
}
return JSEscapeString(s)
}
+
+// URLEscaper returns the escaped value of the textual representation of its
+// arguments in a form suitable for embedding in a URL.
+func URLEscaper(args ...interface{}) string {
+ s, ok := "", false
+ if len(args) == 1 {
+ s, ok = args[0].(string)
+ }
+ if !ok {
+ s = fmt.Sprint(args...)
+ }
+ return http.URLEscape(s)
+}