Skip to content

Commit a5a3805

Browse files
fixed examples in readme
1 parent b4737b0 commit a5a3805

1 file changed

Lines changed: 31 additions & 7 deletions

File tree

README.md

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ You have to call it´s GetSecret() method to get the actual value.
55

66
It is highly inspired by Pydantic´s SecretStr (https://docs.pydantic.dev/usage/types/#secret-types)
77

8+
Example usage:
89
```go
910
package main
1011

@@ -14,20 +15,43 @@ import (
1415
)
1516

1617
func main() {
17-
s := secretstring.SecretString("this_is_a_secret")
18-
// or
19-
// var s SecretString = "this_is_a_secret"
18+
// create a new secret string with default options
19+
s := secretstring.New("this_is_a_secret")
2020

2121
fmt.Println(s)
2222
fmt.Println(s.GetSecret())
23+
24+
// output:
25+
// **********
26+
// this_is_a_secret
2327
}
2428
```
2529

26-
this should output:
30+
Or with custom options:
2731

28-
```
29-
********
30-
this_is_a_secret
32+
```go
33+
package main
34+
35+
import (
36+
"fmt"
37+
"github.com/chmller/secretstring"
38+
)
39+
40+
func main() {
41+
// create a new secret string with custom options
42+
o := secretstring.Options{
43+
MarshallMasked: false,
44+
Mask: "???",
45+
}
46+
s := secretstring.NewWithOptions("this_is_a_secret", o)
47+
48+
fmt.Println(s)
49+
fmt.Println(s.GetSecret())
50+
51+
// output:
52+
// ???
53+
// this_is_a_secret
54+
}
3155
```
3256

3357
It has build in marshaller and unmarshaller for JSON.

0 commit comments

Comments
 (0)