{"id":19884891,"url":"https://github.com/twihike/go-structconv","last_synced_at":"2025-03-01T03:43:49.013Z","repository":{"id":57547514,"uuid":"302668286","full_name":"twihike/go-structconv","owner":"twihike","description":"🌈 A converter between struct and other data","archived":false,"fork":false,"pushed_at":"2021-10-18T14:55:06.000Z","size":22,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-11T18:42:32.753Z","etag":null,"topics":["convert","env","go","golang","map","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/twihike.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-10-09T14:39:16.000Z","updated_at":"2021-10-18T14:55:09.000Z","dependencies_parsed_at":"2022-09-26T18:40:54.432Z","dependency_job_id":null,"html_url":"https://github.com/twihike/go-structconv","commit_stats":null,"previous_names":["tkhiking/go-structconv"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twihike%2Fgo-structconv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twihike%2Fgo-structconv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twihike%2Fgo-structconv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twihike%2Fgo-structconv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/twihike","download_url":"https://codeload.github.com/twihike/go-structconv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241313186,"owners_count":19942417,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["convert","env","go","golang","map","struct"],"created_at":"2024-11-12T17:30:33.381Z","updated_at":"2025-03-01T03:43:48.993Z","avatar_url":"https://github.com/twihike.png","language":"Go","readme":"# go-structconv\n\n[![ci status](https://github.com/twihike/go-structconv/workflows/ci/badge.svg)](https://github.com/twihike/go-structconv/actions) [![license](https://img.shields.io/github/license/twihike/go-structconv)](LICENSE)\n\nA converter between struct and other data.\n\n## Installation\n\n```shell\ngo get -u github.com/twihike/go-structconv\n```\n\n## Usage\n\n`structconv.DecodeMap`\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n\n    \"github.com/twihike/go-structconv/structconv\"\n)\n\ntype example1 struct {\n    A int `map:\"AA,required\"`\n    B []example2\n}\n\ntype example2 struct {\n    C int\n    D string\n    E string `map:\"-\"` // Omitted.\n}\n\nfunc main() {\n    var e example1\n    structconv.DecodeMap(map[string]interface{}{\n        \"AA\": 1,\n        \"B\": []map[string]interface{}{\n            {\n                \"C\": 2,\n                \"D\": \"foo\",\n                \"E\": \"FOO\",\n            },\n            {\n                \"C\": 3,\n                \"D\": \"bar\",\n                \"E\": \"BAR\",\n            },\n        },\n    }, \u0026e, nil)\n    fmt.Println(e) // {1 [{2 foo } {3 bar }]}\n}\n```\n\n`structconv.DecodeStringMap`\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n\n    \"github.com/twihike/go-structconv/structconv\"\n)\n\ntype config struct {\n    AppName string `strmap:\",required\"`\n    AppPort int\n    DB      db\n}\n\ntype db struct {\n    Host     string `strmap:\"DBHost,required\"`\n    Username int    `strmap:\"DBUsername,required\"`\n    Password string `strmap:\"-\"` // Omitted.\n}\n\nfunc main() {\n    m := map[string]string{\n        \"AppName\":    \"myapp\",\n        \"AppPort\":    \"8080\",\n        \"DBHost\":     \"mydb\",\n        \"DBUsername\": \"1234\",\n        \"DBPassword\": \"mypw\",\n    }\n    var conf config\n    conf.AppPort = 80 // Default value.\n    err := structconv.DecodeStringMap(m, \u0026conf, nil)\n    if err != nil {\n        fmt.Println(err)\n    }\n    fmt.Println(conf) //{myapp 8080 {mydb 1234 }}\n}\n```\n\n`structconv.DecodeEnv`\n\n```shell\nexport APP_NAME=awesomeapp\nexport PORT=8080\nexport DB_HOST=mydb\nexport DB_USERNAME=1234\nexport DB_PASSWORD=mypw\n```\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n\n    \"github.com/twihike/go-structconv/structconv\"\n)\n\ntype config struct {\n    AppName string `env:\",required\"`\n    AppPort int    `env:\"PORT\"`\n    DB      db\n}\n\ntype db struct {\n    Host     string `env:\"DB_HOST,required\"`\n    Username int    `env:\"DB_USERNAME,required\"`\n    Password string `env:\"-\"` // Omitted.\n}\n\nfunc main() {\n    var conf config\n    conf.AppPort = 80 // Default value.\n    err := structconv.DecodeEnv(\u0026conf, nil)\n    if err != nil {\n        fmt.Println(err)\n    }\n    fmt.Println(conf) // {awesomeapp 8080 {mydb 1234 }}\n}\n```\n\n## License\n\nCopyright (c) 2020 twihike. All rights reserved.\n\nThis project is licensed under the terms of the MIT license.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwihike%2Fgo-structconv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwihike%2Fgo-structconv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwihike%2Fgo-structconv/lists"}