{"id":41921195,"url":"https://github.com/things-go/structs","last_synced_at":"2026-01-25T16:41:29.599Z","repository":{"id":39491360,"uuid":"424046555","full_name":"things-go/structs","owner":"things-go","description":"Go library for encoding native Go structures into generic map values. go struct to map[string]interface{}","archived":false,"fork":false,"pushed_at":"2024-06-13T10:24:04.000Z","size":85,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-06-21T13:21:31.037Z","etag":null,"topics":[],"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/things-go.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":"2021-11-03T00:56:05.000Z","updated_at":"2024-05-15T10:25:20.000Z","dependencies_parsed_at":"2023-07-12T15:52:54.437Z","dependency_job_id":"cd7bcdf3-4df6-4545-99b2-1a959b38ef55","html_url":"https://github.com/things-go/structs","commit_stats":null,"previous_names":["things-go/mapstruct"],"tags_count":7,"template":false,"template_full_name":"things-labs/cicd-go-template","purl":"pkg:github/things-go/structs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/things-go%2Fstructs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/things-go%2Fstructs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/things-go%2Fstructs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/things-go%2Fstructs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/things-go","download_url":"https://codeload.github.com/things-go/structs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/things-go%2Fstructs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28755558,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-25T16:32:25.380Z","status":"ssl_error","status_checked_at":"2026-01-25T16:32:09.189Z","response_time":113,"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":[],"created_at":"2026-01-25T16:41:28.840Z","updated_at":"2026-01-25T16:41:29.587Z","avatar_url":"https://github.com/things-go.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# structs\n\nGo library for encoding native Go structures into generic map values.\n\n[![GoDoc](https://godoc.org/github.com/things-go/structs?status.svg)](https://godoc.org/github.com/things-go/structs)\n[![Go.Dev reference](https://img.shields.io/badge/go.dev-reference-blue?logo=go\u0026logoColor=white)](https://pkg.go.dev/github.com/things-go/structs?tab=doc)\n[![Tests](https://github.com/things-go/structs/actions/workflows/ci.yml/badge.svg)](https://github.com/things-go/structs/actions/workflows/ci.yml)\n[![Go Report Card](https://goreportcard.com/badge/github.com/things-go/structs)](https://goreportcard.com/report/github.com/things-go/structs)\n[![Licence](https://img.shields.io/github/license/things-go/structs)](https://raw.githubusercontent.com/things-go/structs/main/LICENSE)\n[![Tag](https://img.shields.io/github/v/tag/things-go/structs)](https://github.com/things-go/structs/tags)\n\n### Installation\n\nUse go get.\n\n```bash\n    go get -u github.com/things-go/structs\n```\n\nThen import the structs package into your own code.\n\n```go\n    import \"github.com/things-go/structs\"\n```\n\n### Usage \u0026\u0026 Example\n\n#### API\n\nJust like the standard lib strings, bytes and co packages, structs has many global functions to manipulate or organize your struct data. Lets define and declare a struct:\n\n```go\ntype Server struct {\n    Name        string `json:\"name,omitempty\"`\n    ID          int\n    Enabled     bool\n    users       []string // not exported\n    http.Server          // embedded\n}\n\nserver := \u0026Server{\n    Name:    \"gopher\",\n    ID:      123456,\n    Enabled: true,\n}\n```\n\nHere is an example:\n\n```go\n// Convert a struct to a map[string]interface{}\n// =\u003e {\"Name\":\"gopher\", \"ID\":123456, \"Enabled\":true}\nm := structs.Map(server)\n\n// Convert the values of a struct to a []interface{}\n// =\u003e [\"gopher\", 123456, true]\nv := structs.Values(server)\n\n// Convert the names of a struct to a []string\n// (see \"Names methods\" for more info about fields)\nn := structs.Names(server)\n\n// Convert the values of a struct to a []*Field\n// (see \"Field methods\" for more info about fields)\nf := structs.Fields(server)\n\n// Return the struct name =\u003e \"Server\"\nn := structs.Name(server)\n\n// Check if any field of a struct is initialized or not.\nh := structs.HasZero(server)\n\n// Check if all fields of a struct is initialized or not.\nz := structs.IsZero(server)\n\n// Check if server is a struct or a pointer to struct\ni := structs.IsStruct(server)\n```\n\nOnly [public fields](https://golang.org/doc/effective_go.html#names) will be processed. So **fields\nstarting with lowercase will be ignored**.\n\n#### Name Tags\n\n```go\ntype AA struct {\n    Id        int64    `map:\"id\"`\n    Name      string   `map:\"name\"`\n}\n```\nWe can give the field a tag to specify another name to be used as the key.\n\n#### Ignore Field\n\n```go\ntype AA struct {\n    Ignore string `map:\"-\"`\n}\n```\nIf we give the special tag \"-\" to a field, it will be ignored.\n\n#### Omit Empty\n\n```go\ntype AA struct {\n    Desc        string    `map:\"desc,omitempty\"`\n}\n```\nIf tag option is \"omitempty\", this field will not appear in the map if the value is empty.\nEmpty values are 0, false, \"\", nil, empty array and empty map.\n\n#### Omit Nested\n\n```go\ntype AA struct {\n    // Field is not processed further by this package.\n    Field *http.Request `map:\",omitnested\"`\n}\n```\nA value with the option of \"omitnested\" stops iterating further if the type\nis a struct. it do not converted value if a value are no exported fields, ie: time.Time\n\n#### To String\n\n```go\ntype AA struct {\n    Id        int64    `map:\"id,string\"`\n    Price     float32  `map:\"price,string\"`\n}\n```\nIf tag option is \"string\", this field will be converted to string type. Encode will put the\noriginal value to the map if the conversion is failed.\n\n## References\n\n- [mapstructure](https://github.com/mitchellh/mapstructure)\n- [structs](github.com/fatih/structs)\n\n## License\n\nThis project is under MIT License. See the [LICENSE](LICENSE) file for the full license text.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthings-go%2Fstructs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthings-go%2Fstructs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthings-go%2Fstructs/lists"}