-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
45 lines (38 loc) · 1.06 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"fmt"
"reflect"
"github.com/QuentinPerez/go-encodeUrl"
"github.com/Sirupsen/logrus"
)
type ID struct {
Name string `url:"name,ifStringIsNotEmpty"`
DisplayName string `url:"display-name,ifStringIsNotEmpty"`
}
func nameEqualBadCode(interface{}) (string, bool, error) {
return "0xBadC0de", true, nil
}
func overloadFieldNameAndTag(fieldName string, fieldTag reflect.StructTag) (fieldTagOverloaded reflect.StructTag) {
fieldTagOverloaded = fieldTag
if fieldName == "Name" {
fieldTagOverloaded = `url:"overloaded,nameEqualBadCode"`
}
return
}
// changTag overloads the tag field
func changeNameAndTag() {
encurl.AddEncodeFunc(nameEqualBadCode)
values, errs := encurl.Translate(&ID{"qperez", "Quentin Perez"}, overloadFieldNameAndTag)
if errs != nil {
logrus.Fatal(errs)
}
fmt.Printf("https://example.com/?%v\n", values.Encode())
}
func main() {
values, errs := encurl.Translate(&ID{"qperez", "Quentin Perez"})
if errs != nil {
logrus.Fatal(errs)
}
fmt.Printf("https://example.com/?%v\n", values.Encode())
changeNameAndTag()
}