What\'s the recommended way of encoding and decoding entire URLs in Go? I am aware of the methods url.QueryEscape
and url.QueryUnescape
, but they d
How about this:
template.URLQueryEscaper(path)
If someone wants to get the exact result compare to the JS encodeURIComponent Try my function it's dirty but works well.
https://gist.github.com/czyang/7ae30f4f625fee14cfc40c143e1b78bf
// #Warning! You Should Use this Code Carefully, and As Your Own Risk.
package main
import (
"fmt"
"net/url"
"strings"
)
/*
After hours searching, I can't find any method can get the result exact as the JS encodeURIComponent function.
In my situation I need to write a sign method which need encode the user input exact same as the JS encodeURIComponent.
This function does solved my problem.
*/
func main() {
params := url.Values{
"test_string": {"+!+'( )*-._~0-