github.com/grafana/synthetic-monitoring-agent@v0.64.2/cmd/synthetic-monitoring-agent/secret.go (about)

     1  package main
     2  
     3  // Secret represents a string that shouldn't be logged.
     4  type Secret string
     5  
     6  // String returns a redacted version of the secret.
     7  func (s Secret) String() string {
     8  	return "<redacted>"
     9  }
    10  
    11  // Set sets the value of the secret.
    12  func (s *Secret) Set(value string) error {
    13  	*s = Secret(value)
    14  	return nil
    15  }
    16  
    17  // MarshalText returns a text representation of the redacted version of the
    18  // secret.
    19  //
    20  // This method implements the necessary interface to use Secret in the
    21  // encoding/text and encoding/json packages, which are used by zerolog to
    22  // control the output of the log messages.
    23  func (s Secret) MarshalText() ([]byte, error) {
    24  	return []byte(s.String()), nil
    25  }