{"id":16607159,"url":"https://github.com/ryankurte/go-structparse","last_synced_at":"2025-10-12T19:44:21.717Z","repository":{"id":57498082,"uuid":"89555446","full_name":"ryankurte/go-structparse","owner":"ryankurte","description":"A recursive structure/field/map parsing helper for Golang","archived":false,"fork":false,"pushed_at":"2020-09-27T01:17:02.000Z","size":22,"stargazers_count":7,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-01T03:27:49.008Z","etag":null,"topics":["golang","parser","reflection","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/ryankurte.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-27T04:26:04.000Z","updated_at":"2024-05-20T11:44:26.000Z","dependencies_parsed_at":"2022-08-28T17:11:44.291Z","dependency_job_id":null,"html_url":"https://github.com/ryankurte/go-structparse","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryankurte%2Fgo-structparse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryankurte%2Fgo-structparse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryankurte%2Fgo-structparse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryankurte%2Fgo-structparse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ryankurte","download_url":"https://codeload.github.com/ryankurte/go-structparse/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241917982,"owners_count":20042178,"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":["golang","parser","reflection","struct"],"created_at":"2024-10-12T01:11:49.567Z","updated_at":"2025-10-12T19:44:16.686Z","avatar_url":"https://github.com/ryankurte.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-structparse\n\n[![Documentation](https://img.shields.io/badge/docs-godoc-blue.svg)](https://godoc.org/github.com/ryankurte/go-structparse)\n[![GitHub tag](https://img.shields.io/github/tag/ryankurte/go-structparse.svg)](https://github.com/ryankurte/go-structparse)\n[![Build Status](https://travis-ci.org/ryankurte/go-structparse.svg?branch=master)](https://travis-ci.org/ryankurte/go-structparse)\n\nA (deep) recursive field parser for golang. Basically just a reflection wrapper that finds elements in a struct or map and runs the provided function over them when found.\nThis is useful as a sort of \"find and replace\" for fields or types in a structure.\n\nIt was built to allow overriding of configuration variables in a config file with environmental variables, so that you can have one clear source of truth for configuration that explicitly defines any external requirements.\n\nIt is intended that this will be extended with further field / type parsing as required. If you have a need, or an idea, open an issue!\n\n## Usage\n\nSick of passing 4 million command line arguments into your app? Done with configuring unknown / unspecified environmental variables to get your app to work? Well, this might be the project for you!\n\nWhat if you could have one, human readable, source of truth, that also supported the loading of secrets from the environment in an EXPLICIT manner?\n\nDo we have the solution for you! Try our new `EnvironmentMapper` which will parse strings looking for a delimiter, and when the delimiter is found replace the value with the environmental variable defined by the prefix and field value.\nFor example, if you configure the `EnvironmentMapper` with a delimiter of `$` and a prefix of `APP_`, the value `$NAME` in your configuration file will be replaced with the environmental variable `APP_NAME`.\nNow you have a static, explicit configuration file, that supports injection of secrets and other per-instance data. How neat is that!\n\nIf you fancy implementing custom parsers, check out the [godocs](https://godoc.org/github.com/ryankurte/go-structparse) for more information.\n\n\n## Example\n\n### Config file\n\n``` yaml\n---\n\n# strings beginning with $ will be parsed as environmental variables with the provided prefix\nname: $NAME\nhost: \n  name: $HOSTNAME\n  port: $PORT\n\n```\n\n### Code\n``` go\nimport (\n    \"io/ioutil\"\n    \"gopkg.in/yaml.v2\"\n\n    \"github.com/ryankurte/go-structparse\"\n)\n\ntype Config struct {\n    Name string\n    Host struct {\n        Name string\n        Port string\n    }\n}\n\nfunc Main() {\n    c := Config{}\n\n    // Load (yaml) configuration file\n    data, err := ioutil.ReadFile(filename)\n    if err != nil {\n        return err\n    }\n\n    // Unmarshal from yaml to config struct\n    err = yaml.Unmarshal(data, c)\n    if err != nil {\n        return err\n    }\n\n    // Parse struct fields\n    delimiter := \"$\"\n    prefix := \"APP_\"\n    structparse.Strings(structparse.NewEnvironmentMapper(delimiter, prefix), \u0026c)\n\n    // Do something with the parsed structure\n    log.Printf(\"Config: %+v\", c)\n\n}\n\n```\n\n---\n\nIf you have any questions, comments, or suggestions, feel free to open an issue or a pull request.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryankurte%2Fgo-structparse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fryankurte%2Fgo-structparse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryankurte%2Fgo-structparse/lists"}