secret

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 10, 2022 License: MIT Imports: 1 Imported by: 0

README

secret

Documentation

Overview

Example
package main

import (
	"encoding/json"
	"fmt"

	"github.com/rsjethani/secret"
)

func main() {
	type login struct {
		User      string
		Password1 secret.Secret
		Password2 secret.Secret
		Password3 secret.Secret
		Password4 secret.Secret
	}

	x := login{
		User:      "John",
		Password1: secret.New("pass1"),
		Password2: secret.New("pass2", secret.Redacted),
		Password3: secret.New("pass3", secret.FiveXs),
		Password4: secret.New("pass4", secret.CustomRedact("^^^^^")),
	}

	bytes, err := json.Marshal(x)
	if err != nil {
		panic(err)
	}

	fmt.Printf("%+v\n", x)
	fmt.Printf("%v, %v, %v, %v\n", x.Password1, x.Password2, x.Password3, x.Password4)
	fmt.Printf("%v, %v, %v, %v\n", x.Password1.Value(), x.Password2.Value(), x.Password3.Value(), x.Password4.Value())
	fmt.Printf("%v\n", string(bytes))
}
Output:

{User:John Password1:***** Password2:[REDACTED] Password3:XXXXX Password4:^^^^^}
*****, [REDACTED], XXXXX, ^^^^^
pass1, pass2, pass3, pass4
{"User":"John","Password1":"*****","Password2":"[REDACTED]","Password3":"XXXXX","Password4":"^^^^^"}

Index

Examples

Constants

View Source
const DefaultRedact string = "*****"

Variables

This section is empty.

Functions

func CustomRedact

func CustomRedact(r string) func(*Secret)

func FiveXs

func FiveXs(s *Secret)

func Redacted

func Redacted(s *Secret)

Types

type Secret

type Secret struct {
	// contains filtered or unexported fields
}

func New

func New(s string, options ...func(*Secret)) Secret

func (Secret) MarshalJSON

func (s Secret) MarshalJSON() ([]byte, error)

func (Secret) String

func (s Secret) String() string

func (Secret) Value

func (s Secret) Value() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL