Documentation
¶
Index ¶
Examples ¶
Constants ¶
View Source
const ( // The default character to use in place of real characters in a redacted string for a Censor created via New. RedactedCharacter rune = '*' // The default maximum length of the redacted string for a Censor created via New. A value of zero (0) means the redacted string will be the same length as the original. RedactedLength uint = 8 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Censor ¶
type Censor struct {
// contains filtered or unexported fields
}
Censor allows you to hide sensitive values. This should be created using New rather than directly.
func New ¶
New creates a new Censor that can be used to redact the provided string
Example ¶
package main
import (
"fmt"
"github.com/andrewheberle/redacted-string"
)
func main() {
s := "this is a string"
censor := redacted.New(s)
fmt.Println(censor)
}
Output: ********
func (*Censor) Set ¶
Set changes (or sets) the string to be redacted
Example ¶
package main
import (
"fmt"
"github.com/andrewheberle/redacted-string"
)
func main() {
s := "this is a string"
censor := redacted.New(s, redacted.WithLength(0))
censor.Set("a new string that we want to be fully replaced with the * character")
fmt.Println(censor)
}
Output: *******************************************************************
type Option ¶
type Option func(*Censor)
Option type to change the behaviour of a Censor
func WithCharacter ¶
WithCharacter sets the character
Example ¶
package main
import (
"fmt"
"github.com/andrewheberle/redacted-string"
)
func main() {
s := "this is a string"
censor := redacted.New(s, redacted.WithCharacter('.'))
fmt.Println(censor)
}
Output: ........
func WithLength ¶
WithLength sets the length of the redacted string. A value of zero means the redacted version is the same length as the original.
Example ¶
package main
import (
"fmt"
"github.com/andrewheberle/redacted-string"
)
func main() {
s := "this is a string"
censor := redacted.New(s, redacted.WithLength(12))
fmt.Println(censor)
}
Output: ************
Click to show internal directories.
Click to hide internal directories.