Skip to content

Commit 8c17bde

Browse files
authored
Update README.md
Fix example in README
1 parent 4634691 commit 8c17bde

1 file changed

Lines changed: 23 additions & 13 deletions

File tree

README.md

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,40 @@ Sanitizing a struct will mutate the fields according to rules in the `san` tag.
1212
`go get github.com/go-sanitize/sanitize`
1313

1414

15-
## Usage example
15+
## Example
1616

1717
```go
1818
package main
1919

20-
import "github.com/go-sanitize/sanitize"
20+
import (
21+
"fmt"
22+
23+
"github.com/go-sanitize/sanitize"
24+
)
2125

2226
type Dog struct {
23-
Name string `san:"max=5,trim,lower"`
24-
Breed *string `san:"def=unknown"`
27+
Name string `san:"max=5,trim,lower"`
28+
Breed *string `san:"def=unknown"`
2529
}
2630

2731
func main() {
28-
d := Dog{
29-
Name: "Borky Borkins",
30-
Breed: nil,
31-
}
32+
dog := Dog{
33+
Name: "Borky Borkins",
34+
Breed: nil,
35+
}
36+
fmt.Printf("Raw data -> %+v\n", dog)
37+
38+
s, _ := sanitize.New()
39+
s.Sanitize(&dog)
40+
fmt.Printf("Sanitized data -> Name: %s, Breed: %s\n", dog.Name, *dog.Breed)
41+
}
42+
```
3243

33-
s := sanitizer.New()
34-
s.Sanitize(&d)
44+
Output:
3545

36-
fmt.Printf("Name: %s, Breed: %s", d.Name, d.Breed)
37-
// Name: borky, Breed: unknown
38-
}
46+
```
47+
Raw data -> {Name:Borky Borkins Breed:<nil>}
48+
Sanitized data -> Name: borky, Breed: unknown
3949
```
4050

4151
## Available options

0 commit comments

Comments
 (0)