func Encode(s string, charsToEncode string) string {
	var t strings.Builder
	for _, c := range s {
		if strings.IndexRune(charsToEncode, c) != -1 || c == '%' {
			for _, b := range []byte(string(c)) {
				t.WriteByte('%')
				t.WriteByte(upperhex[b>>4])
				t.WriteByte(upperhex[b&15])
			}
		} else {
			t.WriteRune(c)
		}
	}
	return t.String()
}
Encode escapes the string using percent-encoding, converting the runes found in charsToEncode with hex-encoded %AB sequences
package percent
import (
	"strings"
)
const upperhex = "0123456789ABCDEF"
func unhex(c byte) byte {
	switch {
	case '0' <= c && c <= '9':
		return c - '0'
	case 'a' <= c && c <= 'f':
		return c - 'a' + 10
	case 'A' <= c && c <= 'F':
		return c - 'A' + 10
	}
	return 0
}
func ishex(c byte) bool {
	switch {
	case '0' <= c && c <= '9':
		return true
	case 'a' <= c && c <= 'f':
		return true
	case 'A' <= c && c <= 'F':
		return true
	}
	return false
}