{"id":19866071,"url":"https://github.com/showa-93/go-mask","last_synced_at":"2026-01-17T09:01:36.058Z","repository":{"id":151694135,"uuid":"624454644","full_name":"showa-93/go-mask","owner":"showa-93","description":"go-mask is a simple, customizable Go library for masking sensitive information.","archived":false,"fork":false,"pushed_at":"2024-07-20T18:21:44.000Z","size":90,"stargazers_count":193,"open_issues_count":0,"forks_count":14,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-02T05:47:07.220Z","etag":null,"topics":["go","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/showa-93.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-06T13:59:51.000Z","updated_at":"2025-04-30T08:11:02.000Z","dependencies_parsed_at":"2024-11-12T15:32:14.947Z","dependency_job_id":"d5b1aa05-a62f-41a6-afa0-8e94b1e352c5","html_url":"https://github.com/showa-93/go-mask","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/showa-93/go-mask","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/showa-93%2Fgo-mask","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/showa-93%2Fgo-mask/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/showa-93%2Fgo-mask/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/showa-93%2Fgo-mask/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/showa-93","download_url":"https://codeload.github.com/showa-93/go-mask/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/showa-93%2Fgo-mask/sbom","scorecard":{"id":820897,"data":{"date":"2025-08-11","repo":{"name":"github.com/showa-93/go-mask","commit":"be66234ff7d63db41b6dd695350b2d0e8691d863"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.5,"checks":[{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Code-Review","score":1,"reason":"Found 3/27 approved changesets -- score normalized to 1","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/go.yml:1","Warn: no topLevel permission defined: .github/workflows/test.yaml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/showa-93/go-mask/go.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/showa-93/go-mask/go.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/go.yml:28: update your workflow using https://app.stepsecurity.io/secureworkflow/showa-93/go-mask/go.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yaml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/showa-93/go-mask/test.yaml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yaml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/showa-93/go-mask/test.yaml/main?enable=pin","Info:   0 out of   4 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 6 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-23T15:32:49.952Z","repository_id":151694135,"created_at":"2025-08-23T15:32:49.952Z","updated_at":"2025-08-23T15:32:49.952Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28504596,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T06:57:29.758Z","status":"ssl_error","status_checked_at":"2026-01-17T06:56:03.931Z","response_time":85,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang"],"created_at":"2024-11-12T15:24:55.594Z","updated_at":"2026-01-17T09:01:35.991Z","avatar_url":"https://github.com/showa-93.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# go-mask\n\n[![Documentation](https://img.shields.io/badge/godoc-reference-blue.svg)](https://godoc.org/github.com/showa-93/go-mask)\n![Go Tests](https://github.com/coredns/coredns/actions/workflows/go.test.yml/badge.svg)\n[![codecov](https://codecov.io/gh/showa-93/go-mask/branch/main/graph/badge.svg)](https://codecov.io/gh/showa-93/go-mask)\n[![Go Report Card](https://goreportcard.com/badge/github.com/showa-93/go-mask)](https://goreportcard.com/report/github.com/showa-93/go-mask)\n\ngo-mask is a simple, customizable Go library for masking sensitive information.\n\n- [go-mask](#go-mask)\n\t- [Features](#features)\n\t- [Installation](#installation)\n\t- [Mask Tags](#mask-tags)\n\t- [How to use](#how-to-use)\n\t\t- [string](#string)\n\t\t- [int / float64 / uint](#int--float64--uint)\n\t\t- [slice / array](#slice--array)\n\t\t- [map](#map)\n\t\t- [JSON](#json)\n\t\t- [nested struct](#nested-struct)\n\t\t- [field name / map key](#field-name--map-key)\n\t\t- [custom mask function](#custom-mask-function)\n\n## Features\n\n- You can mask any field of a structure using the struct's tags. (example → [How to use](#how-to-use))\n- It is also possible to mask using field names or map keys without using tags. (example → [field name / map key](#field-name--map-key))\n- Users can make use of their own custom-created masking functions. (example → [custom mask function](#custom-mask-function))\n- The masked object is a copied object, so it does not overwrite the original data before masking(although it's not perfect...)\n  - Private fields are not copied\n  - It is moderately fast in performing deep copies.\n\n## Installation\n\n```sh\ngo get github.com/showa-93/go-mask\n```\n\n## Mask Tags\n\ngo-mask does not provide many tags by default.  \nThis is because it is believed that users should create their own necessary masking functions.  \n\n| tag | type | description |\n| :-- | :-- | :-- |\n| mask:\"filled\" | string | Masks the string with the same number of masking characters. |\n| mask:\"filledXXX\" | string | XXX = number of masking characters. Masks with a fixed number of characters. `mask:\"filled3\"`→`***` |\n| mask:\"fixed\" | string | Masks with a fixed number of characters. `*******` |\n| mask:\"hash\" | string | Masks the string by converting it to a value using sha1. |\n| mask:\"randomXXX\" | int / float64 | XXX = numeric value. Masks with a random value in the range of 0 to the XXX. |\n| mask:\"zero\" | any | It can be applied to any type, masking it with the zero value of that type. |\n\n## How to use\n\n### string\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\tmask \"github.com/showa-93/go-mask\"\n)\n\nfunc main() {\n\t{\n\t\tmaskValue, _ := mask.String(mask.MaskTypeFixed, \"Hello World!!\")\n\t\tfmt.Println(maskValue)\n\t}\n\t{\n\t\tvalue := struct {\n\t\t\tTitle string   `mask:\"filled\"`\n\t\t\tCasts []string `mask:\"fixed\"`\n\t\t}{\n\t\t\tTitle: \"Catch Me If You Can\",\n\t\t\tCasts: []string{\n\t\t\t\t\"Thomas Jeffrey \\\"Tom\\\" Hanks\",\n\t\t\t\t\"Leonardo Wilhelm DiCaprio\",\n\t\t\t},\n\t\t}\n\t\tmasker := mask.NewMasker()\n\t\tmasker.SetMaskChar(\"-\")\n\t\tmasker.RegisterMaskStringFunc(mask.MaskTypeFilled, masker.MaskFilledString)\n\t\tmasker.RegisterMaskStringFunc(mask.MaskTypeFixed, masker.MaskFixedString)\n\n\t\tmaskValue, _ := mask.Mask(value)\n\t\tmaskValue2, _ := masker.Mask(value)\n\n\t\tfmt.Printf(\"%+v\\n\", value)\n\t\tfmt.Printf(\"%+v\\n\", maskValue)\n\t\tfmt.Printf(\"%+v\\n\", maskValue2)\n\t}\n}\n```\n```\n********\n{Title:Catch Me If You Can Casts:[Thomas Jeffrey \"Tom\" Hanks Leonardo Wilhelm DiCaprio]}\n{Title:******************* Casts:[******** ********]}\n{Title:------------------- Casts:[-------- --------]}\n```\n\n### int / float64 / uint\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\tmask \"github.com/showa-93/go-mask\"\n)\n\nfunc main() {\n\t{\n\t\tmaskValue, _ := mask.Int(\"random100\", 10)\n\t\tfmt.Println(maskValue)\n\t}\n\t{\n\t\tmaskValue, _ := mask.Float64(\"random100.2\", 12.3)\n\t\tfmt.Println(maskValue)\n\t}\n\n\t{\n\t\tvalue := struct {\n\t\t\tPrice   int     `mask:\"random1000\"`\n\t\t\tPercent float64 `mask:\"random1.3\"`\n\t\t}{\n\t\t\tPrice:   300,\n\t\t\tPercent: 0.80,\n\t\t}\n\t\tmasker := mask.NewMasker()\n\t\tmasker.RegisterMaskIntFunc(mask.MaskTypeRandom, masker.MaskRandomInt)\n\t\tmasker.RegisterMaskFloat64Func(mask.MaskTypeRandom, masker.MaskRandomFloat64)\n\n\t\tmaskValue, _ := mask.Mask(value)\n\t\tmaskValue2, _ := masker.Mask(value)\n\n\t\tfmt.Printf(\"%+v\\n\", maskValue)\n\t\tfmt.Printf(\"%+v\\n\", maskValue2)\n\t}\n}\n```\n```\n29\n50.45\n{Price:917 Percent:0.183}\n{Price:733 Percent:0.241}\n```\n\n### slice / array\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/showa-93/go-mask\"\n)\n\ntype Value struct {\n\tName string `mask:\"filled\"`\n\tType int    `mask:\"random10\"`\n}\n\nfunc main() {\n\tvalues := []Value{\n\t\t{\n\t\t\tName: \"Thomas Jeffrey \\\"Tom\\\" Hanks\",\n\t\t\tType: 1,\n\t\t},\n\t\t{\n\t\t\tName: \"Leonardo Wilhelm DiCaprio\",\n\t\t\tType: 2,\n\t\t},\n\t}\n\tmasker := mask.NewMasker()\n\tmasker.SetMaskChar(\"+\")\n\tmasker.RegisterMaskStringFunc(mask.MaskTypeFilled, masker.MaskFilledString)\n\tmasker.RegisterMaskIntFunc(mask.MaskTypeRandom, masker.MaskRandomInt)\n\n\tmaskValues, _ := mask.Mask(values)\n\tmaskValues2, _ := masker.Mask(values)\n\n\tfmt.Printf(\"%+v\\n\", values)\n\tfmt.Printf(\"%+v\\n\", maskValues)\n\tfmt.Printf(\"%+v\\n\", maskValues2)\n}\n```\n```\n[{Name:Thomas Jeffrey \"Tom\" Hanks Type:1} {Name:Leonardo Wilhelm DiCaprio Type:2}]\n[{Name:************************** Type:8} {Name:************************* Type:9}]\n[{Name:++++++++++++++++++++++++++ Type:4} {Name:+++++++++++++++++++++++++ Type:8}]\n```\n\n### map\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/showa-93/go-mask\"\n)\n\ntype Value struct {\n\tName string `mask:\"filled\"`\n\tType int    `mask:\"random10\"`\n}\n\nfunc main() {\n\tvalues := map[string]Value{\n\t\t\"one\": {\n\t\t\tName: \"Thomas Jeffrey \\\"Tom\\\" Hanks\",\n\t\t\tType: 1,\n\t\t},\n\t\t\"two\": {\n\t\t\tName: \"Leonardo Wilhelm DiCaprio\",\n\t\t\tType: 2,\n\t\t},\n\t}\n\tmasker := mask.NewMasker()\n\tmasker.SetMaskChar(\"\")\n\tmasker.RegisterMaskStringFunc(mask.MaskTypeFilled, masker.MaskFilledString)\n\tmasker.RegisterMaskIntFunc(mask.MaskTypeRandom, masker.MaskRandomInt)\n\n\tmaskValues, _ := mask.Mask(values)\n\tmaskValues2, _ := masker.Mask(values)\n\n\tfmt.Printf(\"%+v\\n\", values)\n\tfmt.Printf(\"%+v\\n\", maskValues)\n\tfmt.Printf(\"%+v\\n\", maskValues2)\n}\n```\n```\nmap[one:{Name:Thomas Jeffrey \"Tom\" Hanks Type:1} two:{Name:Leonardo Wilhelm DiCaprio Type:2}]\nmap[one:{Name:************************** Type:8} two:{Name:************************* Type:6}]\nmap[one:{Name: Type:6} two:{Name: Type:2}]\n```\n\n### JSON\n\n```go\npackage main\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n\n\tmask \"github.com/showa-93/go-mask\"\n)\n\nfunc main() {\n\tmasker := mask.NewMasker()\n\tmasker.RegisterMaskStringFunc(mask.MaskTypeFilled, masker.MaskFilledString)\n\tmasker.RegisterMaskField(\"S\", \"filled4\")\n\n\tv := `{\n\t\t\"S\": \"Hello world\",\n\t\t\"I\": 1,\n\t\t\"O\": {\n\t\t\t\"S\": \"Second\",\n\t\t\t\"S2\": \"豚汁\"\n\t\t}\n\t}`\n\tvar target any\n\tjson.Unmarshal([]byte(v), \u0026target)\n\tmasked, _ := masker.Mask(target)\n\tmv, _ := json.Marshal(masked)\n\tfmt.Println(string(mv))\n}\n```\n```\n{\"I\":1,\"O\":{\"S\":\"****\",\"S2\":\"豚汁\"},\"S\":\"****\"}\n```\n\n### nested struct\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/showa-93/go-mask\"\n)\n\ntype Node struct {\n\tValue string `mask:\"filled\"`\n\tNext  *Node\n}\n\nfunc main() {\n\tnode := Node{\n\t\tValue: \"first\",\n\t\tNext: \u0026Node{\n\t\t\tValue: \"second\",\n\t\t\tNext: \u0026Node{\n\t\t\t\tValue: \"third\",\n\t\t\t},\n\t\t},\n\t}\n\n\tmasker := mask.NewMasker()\n\tmasker.SetMaskChar(\"🤗\")\n\tmasker.RegisterMaskStringFunc(mask.MaskTypeFilled, masker.MaskFilledString)\n\n\tmaskNode, _ := mask.Mask(node)\n\tmaskNode2, _ := masker.Mask(node)\n\n\tfmt.Printf(\"first=%+v,second=%+v,third=%+v\\n\", node, node.Next, node.Next.Next)\n\tfmt.Printf(\"first=%+v,second=%+v,third=%+v\\n\", maskNode, maskNode.Next, maskNode.Next.Next)\n\tfmt.Printf(\"first=%+v,second=%+v,third=%+v\\n\", maskNode2.(Node), maskNode2.(Node).Next, maskNode2.(Node).Next.Next)\n}\n```\n```\nfirst={Value:first Next:0xc000010048},second=\u0026{Value:second Next:0xc000010060},third=\u0026{Value:third Next:\u003cnil\u003e}\nfirst={Value:***** Next:0xc0000100a8},second=\u0026{Value:****** Next:0xc0000100c0},third=\u0026{Value:***** Next:\u003cnil\u003e}\nfirst={Value:🤗🤗🤗🤗🤗 Next:0xc000010120},second=\u0026{Value:🤗🤗🤗🤗🤗🤗 Next:0xc000010138},third=\u0026{Value:🤗🤗🤗🤗🤗 Next:\u003cnil\u003e}\n```\n\n### field name / map key\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\tmask \"github.com/showa-93/go-mask\"\n)\n\ntype User struct {\n\tID      string // no tag\n\tName    string\n\tGender  string\n\tAge     int\n\tExtData map[string]string\n}\n\nfunc main() {\n\tmasker := mask.NewMasker()\n\n\tmasker.RegisterMaskStringFunc(mask.MaskTypeFilled, masker.MaskFilledString)\n\tmasker.RegisterMaskIntFunc(mask.MaskTypeRandom, masker.MaskRandomInt)\n\n\t// registered field name\n\tmasker.RegisterMaskField(\"Name\", \"filled4\")\n\tmasker.RegisterMaskField(\"Animal\", \"filled6\")\n\tmasker.RegisterMaskField(\"Age\", mask.MaskTypeRandom+\"100\")\n\n\tu := User{\n\t\tID:     \"1\",\n\t\tName:   \"タマ\",\n\t\tGender: \"Male\",\n\t\tAge:    4,\n\t\tExtData: map[string]string{\n\t\t\t\"Animal\": \"Cat\",\n\t\t},\n\t}\n\tmaskedUser, _ := masker.Mask(u)\n\tfmt.Printf(\"%+v\", maskedUser)\n}\n```\n```\n{ID:1 Name:**** Gender:Male Age:10 ExtData:map[Animal:******]}\n```\n\n### custom mask function\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"regexp\"\n\t\"strings\"\n\n\tmask \"github.com/showa-93/go-mask\"\n)\n\nfunc init() {\n\tmaskTypeRegExp := \"regexp\"\n\tmask.RegisterMaskStringFunc(maskTypeRegExp, MaskRegExp)\n}\n\n// MaskRegExp is sample to add a custom mask function\nfunc MaskRegExp(arg, value string) (string, error) {\n\tvar (\n\t\treg *regexp.Regexp\n\t\terr error\n\t)\n\treg, err = regexp.Compile(arg)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\tindexes := reg.FindStringSubmatchIndex(value)\n\tif len(indexes) \u003e= 4 \u0026\u0026 indexes[2] \u003e= 0 \u0026\u0026 indexes[3] \u003e= 0 {\n\t\tvar sb strings.Builder\n\t\tsb.WriteString(value[:indexes[2]])\n\t\tsb.WriteString(mask.MaskChar())\n\t\tsb.WriteString(value[indexes[3]:])\n\t\treturn sb.String(), nil\n\t}\n\n\treturn value, nil\n}\n\nfunc main() {\n\tmask.SetMaskChar(\"cat\")\n\ttype Hachiware struct {\n\t\tMessage string `mask:\"regexp(gopher).\"`\n\t}\n\n\tinput := Hachiware{Message: \"I love gopher!\"}\n\tgot, _ := mask.Mask(input)\n\tfmt.Printf(\"%+v\\n\", input)\n\tfmt.Printf(\"%+v\\n\", got)\n\n\t// The Masker initialized with NewMasker does not have\n\t// any custom masking functions registered, so no masking will occur\n\tmasker := mask.NewMasker()\n\tgot2, _ := masker.Mask(input)\n\tfmt.Printf(\"%+v\\n\", got2)\n}\n```\n```\n{Message:I love gopher!}\n{Message:I love cat!}\n{Message:I love gopher!}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshowa-93%2Fgo-mask","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshowa-93%2Fgo-mask","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshowa-93%2Fgo-mask/lists"}