All Projects → ggwhite → go-masker

ggwhite / go-masker

Licence: MIT license
Simple utility of creating a mask for sensitive information

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to go-masker

Fpgo
Monad, Functional Programming features for Golang
Stars: ✭ 165 (+205.56%)
Mutual labels:  golang-tools
go-typeconv
Bring implicit type conversion into Go in a explicit way
Stars: ✭ 24 (-55.56%)
Mutual labels:  golang-tools
gotests-vim
Vim plugin for https://github.com/cweill/gotests
Stars: ✭ 129 (+138.89%)
Mutual labels:  golang-tools
Sonar Golang
Sonarqube plugin for the golang language.
Stars: ✭ 229 (+324.07%)
Mutual labels:  golang-tools
universalmutator
Regexp based tool for mutating generic source code across numerous languages
Stars: ✭ 105 (+94.44%)
Mutual labels:  golang-tools
gocoverutil
No description or website provided.
Stars: ✭ 25 (-53.7%)
Mutual labels:  golang-tools
Gomod
Go modules analysis tool
Stars: ✭ 139 (+157.41%)
Mutual labels:  golang-tools
GoCurrency
Simple currency converter. Insert an amount, what currency to convert from and what currency to convert to.
Stars: ✭ 29 (-46.3%)
Mutual labels:  golang-tools
nestif
Detect deeply nested if statements in Go source code
Stars: ✭ 30 (-44.44%)
Mutual labels:  golang-tools
bingo
The missing package manager for golang binaries (its homebrew for "go install")
Stars: ✭ 177 (+227.78%)
Mutual labels:  golang-tools
gogh
GO GitHub project manager
Stars: ✭ 29 (-46.3%)
Mutual labels:  golang-tools
go-notebook
Go-Notebook is inspired by Jupyter Project (link) in order to document Golang code.
Stars: ✭ 33 (-38.89%)
Mutual labels:  golang-tools
goreporter
A Golang tool that does static analysis, unit testing, code review and generate code quality report.
Stars: ✭ 3,019 (+5490.74%)
Mutual labels:  golang-tools
Dupl
a tool for code clone detection
Stars: ✭ 228 (+322.22%)
Mutual labels:  golang-tools
brockly
A Visual Go code generator
Stars: ✭ 55 (+1.85%)
Mutual labels:  golang-tools
Tinderonline
Find out which of your friends are online on Tinder
Stars: ✭ 155 (+187.04%)
Mutual labels:  golang-tools
gobrew
Go version manager. Super simple tool to install and manage Go versions. Install go without root. Gobrew doesn't require shell rehash.
Stars: ✭ 171 (+216.67%)
Mutual labels:  golang-tools
n3dr
Nexus3 Disaster Recovery (N3DR) is a tool that is capable of downloading all artifacts from a Nexus3 server and to migrate them to another Nexus3 server. Note that some repository formats are not supported at the moment.
Stars: ✭ 110 (+103.7%)
Mutual labels:  golang-tools
gomakegen
Utility for generating makefiles for Golang applications
Stars: ✭ 16 (-70.37%)
Mutual labels:  golang-tools
gvm
Go Version Manager (written in Go for cross-platform usability)
Stars: ✭ 117 (+116.67%)
Mutual labels:  golang-tools

Golang Masker

Build Status codecov Go Report Card License GoDoc Release

Golang Masker is a simple utility of creating a mask for sensitive information.

Getting Started

$ go get -u github.com/ggwhite/go-masker

Demo

There are two ways to get a masker instance:

1. Get a instance directly from go-masker package

package main

import (
	masker "github.com/ggwhite/go-masker"
)

func main() {
	masker.Name("ggwhite")
	masker.ID("A123456789")
	masker.Mobile("0978978978")
}

2. Get a instance via masker.New()

package main

import (
	masker "github.com/ggwhite/go-masker"
)

func main() {
	m := masker.New()
	m.Name("ggwhite")
	m.ID("A123456789")
	m.Mobile("0978978978")
}

Mask Types

Type Const Tag Description
Name MName name mask the second letter and the third letter
Password MPassword password always return ************
Address MAddress addr keep first 6 letters, mask the rest
Email MEmail email keep domain and the first 3 letters
Mobile MMobile mobile mask 3 digits from the 4'th digit
Telephone MTelephone tel remove (, ), , - chart, and mask last 4 digits of telephone number, format to (??)????-????
ID MID id mask last 4 digits of ID number
CreditCard MCreditCard credit mask 6 digits from the 7'th digit
Struct MStruct struct mask the struct

Mask the String

String methomd requires two parameters, a mask type CONST and a string:

package main

import (
	masker "github.com/ggwhite/go-masker"
)

func main() {
	masker.String(masker.MName, "ggwhite")
	masker.String(masker.MID, "A123456789")
	masker.String(masker.MMobile, "0987987987")
}

Result:

g**hite
A12345****
0987***987

Custom Mask

package main

import (
	masker "github.com/ggwhite/go-masker"
)

func main() {
	masker.String(masker.MName, "ggwhite")
	masker.String(masker.MID, "A123456789")
	masker.SetMask("-")
	masker.String(masker.MMobile, "0987987987")
}

Result:

g**hite
A12345****
0987---987

Mask the Struct

You can define your struct and add tag mask to let masker know what kind of the format to mask.

Field must be public in the struct.

package main

import (
	"log"
	masker "github.com/ggwhite/go-masker"
)

type Foo struct {
	Name   string `mask:"name"`
	Mobile string `mask:"mobile"`
}

func main() {
	foo := &Foo{
		Name:   "ggwhite",
		Mobile: "0987987987",
	}
	t, err := masker.Struct(foo)
	log.Println(t)
	log.Println(t.(*Foo))
	log.Println(err)
}

Result:

t = &{g**hite 0987***987} 
err = <nil>

Struct contain struct

package main

import (
	masker "github.com/ggwhite/go-masker"
)

type Foo struct {
	Name   string `mask:"name"`
	Mobile string `mask:"mobile"`
	Qoo    *Qoo   `mask:"struct"`
}

type Qoo struct {
	Name      string `mask:"name"`
	Telephone string `mask:"tel"`
}

func main() {
	foo := &Foo{
		Name:   "ggwhite",
		Mobile: "0987987987",
		Qoo: &Qoo{
			Name:      "gino",
			Telephone: "0287658765",
		},
	}
	t, err := masker.Struct(foo)
	log.Println(t)
	log.Println(t.(*Foo).Qoo)
	log.Println(err)
}

Result:

t = &{g**hite 0987***987 0xc00000a080}
t.Qoo = &{g**o (02)8765-****}
err = <nil>

Struct contain string slice

package main

import (
	masker "github.com/ggwhite/go-masker"
)

type Foo struct {
	Name   string `mask:"name"`
	Mobile string `mask:"mobile"`
	IDs    []string   `mask:"id"`
}

func main() {
	foo := &Foo{
		Name:   "ggwhite",
		Mobile: "0987987987",
		IDs: []string{
			"A123456789",
			"A987654321",
		},
	}
	t, err := masker.Struct(foo)
	log.Println(t)
	log.Println(err)
}

Result:

t = &{g**hite 0987***987 [A12345**** A98765****]}
err = <nil>
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].