Skip to content

Commit dec19f2

Browse files
committed
Reduce stutter by renaming type to secret.Text
1 parent e3e419d commit dec19f2

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

example_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ import (
1010
func Example() {
1111
type login struct {
1212
User string
13-
Password1 secret.Secret
14-
Password2 secret.Secret
15-
Password3 secret.Secret
16-
Password4 secret.Secret
13+
Password1 secret.Text
14+
Password2 secret.Text
15+
Password3 secret.Text
16+
Password4 secret.Text
1717
}
1818

1919
x := login{
2020
User: "John",
21-
Password1: secret.New("pass1"),
22-
Password2: secret.New("pass2", secret.Redacted),
23-
Password3: secret.New("pass3", secret.FiveXs),
24-
Password4: secret.New("pass4", secret.CustomRedact("^^^^^")),
21+
Password1: secret.NewText("pass1"),
22+
Password2: secret.NewText("pass2", secret.Redacted),
23+
Password3: secret.NewText("pass3", secret.FiveXs),
24+
Password4: secret.NewText("pass4", secret.CustomRedact("^^^^^")),
2525
}
2626

2727
bytes, err := json.Marshal(x)
@@ -37,7 +37,7 @@ func Example() {
3737
// Unmarshaling a plain string into a Secret also works.
3838
y := struct {
3939
User string
40-
Credential secret.Secret
40+
Credential secret.Text
4141
}{}
4242
err = json.Unmarshal([]byte(`{"User": "Doe", "Credential": "secret"}`), &y)
4343
if err != nil {

secret.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import (
77

88
const DefaultRedact string = "*****"
99

10-
type Secret struct {
10+
type Text struct {
1111
v *string
1212
r *string
1313
}
1414

15-
func New(s string, options ...func(*Secret)) Secret {
16-
sec := Secret{}
15+
func NewText(s string, options ...func(*Text)) Text {
16+
sec := Text{}
1717

1818
sec.init()
1919
*sec.v = s
@@ -24,43 +24,43 @@ func New(s string, options ...func(*Secret)) Secret {
2424
return sec
2525
}
2626

27-
func (s *Secret) init() {
27+
func (s *Text) init() {
2828
s.v = new(string)
2929
s.r = new(string)
3030
*s.r = DefaultRedact
3131
}
3232

33-
func CustomRedact(r string) func(*Secret) {
34-
return func(s *Secret) {
33+
func CustomRedact(r string) func(*Text) {
34+
return func(s *Text) {
3535
*s.r = r
3636
}
3737
}
3838

39-
func (s Secret) String() string {
39+
func (s Text) String() string {
4040
return *s.r
4141
}
4242

43-
func (s Secret) Value() string {
43+
func (s Text) Value() string {
4444
return *s.v
4545
}
4646

47-
func (s Secret) MarshalJSON() ([]byte, error) {
47+
func (s Text) MarshalJSON() ([]byte, error) {
4848
return []byte(fmt.Sprintf(`"%s"`, *s.r)), nil
4949
}
5050

51-
func (s *Secret) UnmarshalJSON(b []byte) error {
51+
func (s *Text) UnmarshalJSON(b []byte) error {
5252
s.init()
5353
return json.Unmarshal(b, s.v)
5454
}
5555

56-
func Redacted(s *Secret) {
56+
func Redacted(s *Text) {
5757
*s.r = "[REDACTED]"
5858
}
5959

60-
func FiveXs(s *Secret) {
60+
func FiveXs(s *Text) {
6161
*s.r = "XXXXX"
6262
}
6363

64-
func (s *Secret) Copy() Secret {
65-
return New(*s.v, CustomRedact(*s.r))
64+
func (s *Text) Copy() Text {
65+
return NewText(*s.v, CustomRedact(*s.r))
6666
}

0 commit comments

Comments
 (0)