You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use this option to specify which date format we should use.
60
+
61
+
The `Input` field tells us which date formats we can accept (such as RFC3339 and RFC3339Nano).
62
+
63
+
The `KeepFormat` field tells us if we should keep the date format unchanged, or if we want to force them into another format.
64
+
65
+
The `Output` field tells us which format we should use for the output if `KeepFormat` is set to false.
66
+
67
+
If a date can not be parsed by the formats specified in the `Input` field, the field will be converted into an empty string.
68
+
69
+
Example:
70
+
- If `Input = [RFC1123, RFC3339Nano]`, `KeepFormat: false`, and `Output = RFC3339`, we will accept dates in the RFC1123 and RFC3339Nano formats and convert them to RFC3339 format. Any other formats will be converted into an empty string.
71
+
- If `Input = [RFC1123, RFC3339Nano]` and `KeepFormat: true`, we will accept dates in the RFC1123 and RFC3339Nano formats and keep them in the same format. Any other formats will be converted into an empty string.
72
+
- If `Input = []`, the field will be converted into an empty string, since there are no allowed input formats.
73
+
74
+
```go
75
+
s:= sanitizer.New(sanitizer.OptionDateFormat{
76
+
Input: []string{
77
+
time.RFC3339,
78
+
time.RFC3339Nano,
79
+
},
80
+
KeepFormat: false,
81
+
Output: time.RFC1123,
82
+
})
83
+
```
84
+
85
+
41
86
## Available tags
42
87
43
88
### string
@@ -49,8 +94,10 @@ func main() {
49
94
1.**title** - First character of every word is changed to uppercase, the rest to lowercase
50
95
1.**cap** - Only the first letter of the string will be changed to uppercase, the rest to lowercase
51
96
1.**def=`<n>`** (only available for pointers) - Sets a default `<n>` value in case the pointer is `nil`
97
+
1.**xss** - Will remove brackets such as <>[](){} and the characters !=? from the string
98
+
1.**date** - Will parse the string using the input formats provided in the options and print it using the output format provided in the options. If the string can not be parsed, it will be left empty.
52
99
53
-
The order of precedence will be: **trim** -> **max** -> **lower**
100
+
The order of precedence will be: **xss** -> **trim** -> **date** -> **max** -> **lower** -> **upper** -> **title** -> **cap**
0 commit comments