hashedfield

package module
v0.0.0-...-20c420e Latest Latest
Warning

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

Go to latest
Published: May 27, 2022 License: MIT Imports: 4 Imported by: 0

README

zap-hashed-field

go codecov go-report

See example at example_test.go.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fnv128

func Fnv128(key string, value string) zapcore.Field

Fnv128 generate zapcore.Field with Fnv128Hasher

func Sha512

func Sha512(key string, value string) zapcore.Field

Sha512 generate zapcore.Field with Sha512Hasher

Example
package main

import (
	hashedfield "github.com/sters/zap-hashed-field"
	"go.uber.org/zap"
)

func main() {
	logger := zap.NewExample()
	defer func() { _ = logger.Sync() }()

	key := "sensitive data"
	value := "Hello World!"

	logger.Info(
		"default output",
		zap.String(key, value),
	)

	logger.Info(
		"sha512 output",
		hashedfield.String(key, hashedfield.Sha512Hasher(value)),
	)

	logger.Info(
		"fnv128 output",
		hashedfield.String(key, hashedfield.Fnv128Hasher(value)),
	)

}
Output:

{"level":"info","msg":"default output","sensitive data":"Hello World!"}
{"level":"info","msg":"sha512 output","sensitive data":"861844d6704e8573fec34d967e20bcfef3d424cf48be04e6dc08f2bd58c729743371015ead891cc3cf1c9d34b49264b510751b1ff9e537937bc46b5d6ff4ecc8"}
{"level":"info","msg":"fnv128 output","sensitive data":"3e09e68d3967a18bcfaa7ac886326144"}

func String

func String(key string, value Hasher) zapcore.Field

String generate zapcore.Field with your Hasher

Types

type Fnv128Hasher

type Fnv128Hasher string

Fnv128Hasher is a hasher using the sha1 method

func (Fnv128Hasher) Hash

func (v Fnv128Hasher) Hash() string

Hash generate Sha512 hashed string

type Hasher

type Hasher interface {
	Hash() string
}

Hasher for use hashed field's value

type Sha512Hasher

type Sha512Hasher string

Sha512Hasher is a hasher using the sha1 method

func (Sha512Hasher) Hash

func (v Sha512Hasher) Hash() string

Hash generate Sha512 hashed string

Jump to

Keyboard shortcuts

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