tpl: Allow 'Querify' to take lone slice/interface argument

Querify can now take a lone string/interface slice (with string
keys) as a parameter, or multiple string parameters, to build
URL queries.

Querify earlier used 'Dictionary' to add key/value pairs to a
map to build URL queries. Changed to dynamically generate ordered
key/value pairs. Cannot take string slice as key (earlier
possible due to Dictionary).

Added tests and benchmarks for querify.

Closes #6735
This commit is contained in:
Ujjwal Goyal
2021-03-07 00:08:10 +05:30
committed by Bjørn Erik Pedersen
parent 504c78da4b
commit c46fc838a9
3 changed files with 68 additions and 5 deletions

View File

@@ -122,6 +122,10 @@ func init() {
`<a href="https://www.google.com?{{ (querify "q" "test" "page" 3) | safeURL }}">Search</a>`,
`<a href="https://www.google.com?page=3&amp;q=test">Search</a>`,
},
{
`{{ slice "foo" 1 "bar" 2 | querify | safeHTML }}`,
`bar=2&foo=1`,
},
},
)