password.go (599B)
1 package password 2 3 import "strings" 4 5 // Password is an object that tries to make it hard (or explicit) to leak secrets 6 type Password struct { 7 secret string 8 } 9 10 // New create a new password 11 func New(secret string) Password { 12 return Password{secret: secret} 13 } 14 15 // String prevent leaking secrets by accident 16 func (p Password) String() string { 17 return strings.Repeat("*", len(p.secret)) 18 } 19 20 // Leak make it clear that we are leaking a secret 21 func (p Password) Leak() string { 22 return p.secret 23 } 24 25 // Empty either the password is empty or not 26 func (p Password) Empty() bool { 27 return len(p.secret) == 0 28 }