{"id":37211441,"url":"https://github.com/liangyaopei/structmap","last_synced_at":"2026-01-15T00:04:28.203Z","repository":{"id":57539660,"uuid":"281650937","full_name":"liangyaopei/structmap","owner":"liangyaopei","description":"Golang converts a struct to map, including customizing key name, flatterning the sturct and customizing field's independent method.","archived":false,"fork":false,"pushed_at":"2020-09-11T07:51:07.000Z","size":21,"stargazers_count":28,"open_issues_count":1,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-06-20T09:27:29.625Z","etag":null,"topics":["golang","map","marshal","reflect","struct"],"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/liangyaopei.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}},"created_at":"2020-07-22T10:47:40.000Z","updated_at":"2023-12-18T03:00:13.000Z","dependencies_parsed_at":"2022-09-21T05:57:20.848Z","dependency_job_id":null,"html_url":"https://github.com/liangyaopei/structmap","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/liangyaopei/structmap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liangyaopei%2Fstructmap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liangyaopei%2Fstructmap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liangyaopei%2Fstructmap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liangyaopei%2Fstructmap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/liangyaopei","download_url":"https://codeload.github.com/liangyaopei/structmap/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liangyaopei%2Fstructmap/sbom","scorecard":{"id":587643,"data":{"date":"2025-08-11","repo":{"name":"github.com/liangyaopei/structmap","commit":"0e2911025a96b6f3a457fc800bfe83867281c74e"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/11 approved changesets -- score normalized to 0","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":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"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":"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":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"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":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"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":"Dangerous-Workflow","score":-1,"reason":"no workflows found","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":"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 'master'"],"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"}}]},"last_synced_at":"2025-08-20T20:59:14.671Z","repository_id":57539660,"created_at":"2025-08-20T20:59:14.671Z","updated_at":"2025-08-20T20:59:14.671Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28439609,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T22:37:52.437Z","status":"ssl_error","status_checked_at":"2026-01-14T22:37:31.496Z","response_time":107,"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":["golang","map","marshal","reflect","struct"],"created_at":"2026-01-15T00:04:27.149Z","updated_at":"2026-01-15T00:04:27.988Z","avatar_url":"https://github.com/liangyaopei.png","language":"Go","readme":"[![Go Report Card](https://goreportcard.com/badge/github.com/liangyaopei/structmap)](https://goreportcard.com/report/github.com/liangyaopei/structmap)\n[![GoDoc](https://godoc.org/github.com/liangyaopei/structmap?status.svg)](http://godoc.org/github.com/liangyaopei/structmap)\n\n[中文版说明](README_zh.md)\n\nThis repo provides a function convert a struct in Golang to a map(unmarshal a struct to a map).It supports\n1. use tag to define the name of a filed in struct when converted in map. If no tag is specified, it will the name of field as key.\n2. a filed in struct can customize its to map method.\nTo note that the customized method should have `(string,interface{})` as output, with the `string` as key in map and `interface{}` as value in map.\n\nAlso, it skips unexported filed , nil pointer and field without tag.\n\n\n## Tags\nFor now, it supports 4 tags:\n- '-' means ignoring this field\n- 'omitempty' means ignoring this field when it is empty\n- 'dive' means recursively traversing the struct, converting every filed in struct to be a key in map\n- 'wildcard' applies for string value, it returns \"%\" +value +\"%\", which is conveniently for db wildcard query\n\n\n## Example\nFor example,\n```go\ntype User struct {\n\tName      string       `map:\"name,omitempty\"`        // string\n\tGithub    GithubPage   `map:\"github,dive,omitempty\"` // struct dive\n\tNoDive    StructNoDive `map:\"no_dive,omitempty\"`     // no dive struct\n\tMyProfile Profile      `map:\"my_profile,omitempty\"`  // struct implements its own method\n}\n\ntype GithubPage struct {\n\tURL  string `map:\"url\"`\n\tStar int    `map:\"star\"`\n}\n\ntype StructNoDive struct {\n\tNoDive int `map:\"no_dive_int\"`\n}\n\ntype Profile struct {\n\tExperience string    `map:\"experience\"`\n\tDate       time.Time `map:\"time\"`\n}\n\n// its own toMap method\nfunc (p Profile) StructToMap() (key string, value interface{}) {\n\treturn \"time\", p.Date.Format(timeLayout)\n}\n```\nby using \n```go\nres, err := structmap.StructToMap(\u0026user, tag, methodName)\n```\ncan be converted to be\n```go\nmap[string]interface{}{\n\t\"name\":    \"user\",\n\t\"no_dive\":  map[string]int{\"no_dive_int\": 1},\n    // dive struct field\n\t\"url\":     \"https://github.com/liangyaopei\",\n\t\"star\":    1,\n    // customized method\n\t\"time\":    \"2020-07-21 12:00:00\",\n}\n```\n\n## Performance\nCompared with using `marshal`/`unmarshal` function in `json` package, this repo has better performance.\n```go\nfunc BenchmarkStructToMapByJson(b *testing.B) {\n\tuser := newBenchmarkUser()\n\tb.ResetTimer()\n\tfor i := 0; i \u003c b.N; i++ {\n\t\tdata, _ := json.Marshal(\u0026user)\n\t\tm := make(map[string]interface{})\n\t\tjson.Unmarshal(data, \u0026m)\n\t}\n}\n\nfunc BenchmarkStructToMapByToMap(b *testing.B) {\n\tuser := newBenchmarkUser()\n\ttag := \"json\"\n\tmethodName := \"\"\n\tb.ResetTimer()\n\tfor i := 0; i \u003c b.N; i++ {\n\t\tstruct_to_map.StructToMap(\u0026user, tag, methodName)\n\t}\n}\n```\nThe result of using `StructToMap`\n```sh\n$ go test ./... -bench=BenchmarkStructToMapByToMap  -benchmem -run=^$ -count=10\n\nBenchmarkStructToMapByToMap-4            1322222               960 ns/op             488 B/op         14 allocs/op\nBenchmarkStructToMapByToMap-4            1225311               965 ns/op             488 B/op         14 allocs/op\nBenchmarkStructToMapByToMap-4            1201177               947 ns/op             488 B/op         14 allocs/op\nBenchmarkStructToMapByToMap-4            1308039               895 ns/op             488 B/op         14 allocs/op\nBenchmarkStructToMapByToMap-4            1201592               936 ns/op             488 B/op         14 allocs/op\nBenchmarkStructToMapByToMap-4            1351603               882 ns/op             488 B/op         14 allocs/op\nBenchmarkStructToMapByToMap-4            1361508               878 ns/op             488 B/op         14 allocs/op\nBenchmarkStructToMapByToMap-4            1355869               876 ns/op             488 B/op         14 allocs/op\nBenchmarkStructToMapByToMap-4            1353205              1151 ns/op             488 B/op         14 allocs/op\nBenchmarkStructToMapByToMap-4            1278057              1487 ns/op             488 B/op         14 allocs/op\n``` \nThe result of using `json` package\n```sh\n$ go test ./... -bench=BenchmarkStructToMapByJson  -benchmem -run=^$ -count=10 \nBenchmarkStructToMapByJson-4      383409              3171 ns/op             992 B/op         30 allocs/op\nBenchmarkStructToMapByJson-4      314690              3297 ns/op             992 B/op         30 allocs/op\nBenchmarkStructToMapByJson-4      363764              3009 ns/op             992 B/op         30 allocs/op\nBenchmarkStructToMapByJson-4      365799              3122 ns/op             992 B/op         30 allocs/op\nBenchmarkStructToMapByJson-4      361111              3057 ns/op             992 B/op         30 allocs/op\nBenchmarkStructToMapByJson-4      335830              3176 ns/op             992 B/op         30 allocs/op\nBenchmarkStructToMapByJson-4      347206              3069 ns/op             992 B/op         30 allocs/op\nBenchmarkStructToMapByJson-4      380973              3067 ns/op             992 B/op         30 allocs/op\nBenchmarkStructToMapByJson-4      373834              3000 ns/op             992 B/op         30 allocs/op\nBenchmarkStructToMapByJson-4      373597              3206 ns/op             992 B/op         30 allocs/op\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliangyaopei%2Fstructmap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fliangyaopei%2Fstructmap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliangyaopei%2Fstructmap/lists"}