{"id":21876964,"url":"https://github.com/oarkflow/jenv","last_synced_at":"2026-05-07T20:02:35.926Z","repository":{"id":265112595,"uuid":"895155632","full_name":"oarkflow/jenv","owner":"oarkflow","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-21T09:25:14.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-21T10:39:25.816Z","etag":null,"topics":["env-placeholder","environment-variables","json","json-placeholder","yaml","yaml-placeholder"],"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/oarkflow.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":"2024-11-27T16:54:45.000Z","updated_at":"2025-03-21T09:24:13.000Z","dependencies_parsed_at":"2024-11-27T19:31:37.521Z","dependency_job_id":null,"html_url":"https://github.com/oarkflow/jenv","commit_stats":null,"previous_names":["oarkflow/jenv"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oarkflow%2Fjenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oarkflow%2Fjenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oarkflow%2Fjenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oarkflow%2Fjenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oarkflow","download_url":"https://codeload.github.com/oarkflow/jenv/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244885514,"owners_count":20526293,"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":["env-placeholder","environment-variables","json","json-placeholder","yaml","yaml-placeholder"],"created_at":"2024-11-28T08:07:26.975Z","updated_at":"2026-05-07T20:02:35.801Z","avatar_url":"https://github.com/oarkflow.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jenv\n\n`jenv` is a Go package that simplifies configuration parsing by allowing placeholders in JSON and YAML files to be resolved dynamically using environment variables. The package supports default values and type-safe conversion of fields.\n\n## Features\n* Parse JSON and YAML configurations with environment variable resolution.\n* Support for default values in ${VAR:default} syntax.\n* Type-safe mapping of configuration values to Go structs.\n* Handle complex data types such as time.Time, time.Duration, slices, and maps.\n\n## Installation\n\n\u003e go get github.com/oarkflow/jenv\n\n## Usage\n### Environment Variables\n\nSet environment variables for your configuration:\n\n```bash\nexport SERVICE_NAME=\"MyAppService\"\nexport ENABLE_SERVICE=\"true\"\nexport RATE=\"2.5\"\nexport TIMEOUT=\"15s\"\nexport START_TIME=\"2024-01-01T12:00:00Z\"\nexport DB_HOST=\"db.example.com\"\nexport DB_PORT=\"5432\"\nexport DB_REPLICA_PORT=\"5433\"\n\n```\n\n## Example JSON Configuration\nCreate a JSON configuration file config.json:\n\n```json\n{\n    \"service\": {\n        \"name\": \"${SERVICE_NAME:DefaultService}\",\n        \"enabled\": \"${ENABLE_SERVICE:false}\",\n        \"timeout\": \"${TIMEOUT:30s}\",\n        \"start_time\": \"${START_TIME:2023-01-01T00:00:00Z}\",\n        \"rate\": \"${RATE:1.0}\"\n    },\n    \"database\": {\n        \"hosts\": [\"${DB_HOST:localhost}\"],\n        \"ports\": {\n            \"primary\": \"${DB_PORT:3306}\",\n            \"replica\": \"${DB_REPLICA_PORT:3307}\"\n        }\n    }\n}\n\n```\n\nParse it in your Go code:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"time\"\n\n\t\"github.com/oarkflow/jenv\"\n)\n\ntype Service struct {\n\tName      string        `json:\"name\"`\n\tEnabled   bool          `json:\"enabled\"`\n\tRate      float64       `json:\"rate\"`\n\tTimeout   time.Duration `json:\"timeout\"`\n\tStartTime time.Time     `json:\"start_time\"`\n}\n\ntype Database struct {\n\tHosts []string       `json:\"hosts\"`\n\tPorts map[string]int `json:\"ports\"`\n}\n\ntype Config struct {\n\tService  Service  `json:\"service\"`\n\tDatabase Database `json:\"database\"`\n}\n\nfunc main() {\n\tos.Setenv(\"SERVICE_NAME\", \"MyAppService\")\n\tos.Setenv(\"ENABLE_SERVICE\", \"true\")\n\tos.Setenv(\"RATE\", \"2.5\")\n\tos.Setenv(\"TIMEOUT\", \"15s\")\n\tos.Setenv(\"START_TIME\", \"2024-01-01T12:00:00Z\")\n\tos.Setenv(\"DB_HOST\", \"db.example.com\")\n\tos.Setenv(\"DB_PORT\", \"5432\")\n\tos.Setenv(\"DB_REPLICA_PORT\", \"5433\")\n\n\tjsonData := []byte(`\n\t{\n\t    \"service\": {\n\t        \"name\": \"${SERVICE_NAME:DefaultService}\",\n\t        \"enabled\": \"${ENABLE_SERVICE:false}\",\n\t        \"timeout\": \"${TIMEOUT:30s}\",\n\t        \"start_time\": \"${START_TIME:2023-01-01T00:00:00Z}\",\n\t        \"rate\": \"${RATE:1.0}\"\n\t    },\n\t    \"database\": {\n\t        \"hosts\": [\"${DB_HOST:localhost}\"],\n\t        \"ports\": {\"primary\": \"${DB_PORT:3306}\", \"replica\": \"${DB_REPLICA_PORT:3307}\"}\n\t    }\n\t}`)\n\n\tvar config Config\n\terr := jenv.UnmarshalJSON(jsonData, \u0026config)\n\tif err != nil {\n\t\tfmt.Printf(\"Error: %v\\n\", err)\n\t\treturn\n\t}\n\n\tfmt.Printf(\"Config: %+v\\n\", config)\n}\n\n```\n\n## Example YAML Configuration\nCreate a YAML configuration file config.yaml:\n\n```yaml\nservice:\n  name: \"${SERVICE_NAME:DefaultService}\"\n  enabled: \"${ENABLE_SERVICE:false}\"\n  timeout: \"${TIMEOUT:30s}\"\n  start_time: \"${START_TIME:2023-01-01T00:00:00Z}\"\n  rate: \"${RATE:1.0}\"\ndatabase:\n  hosts:\n    - \"${DB_HOST:localhost}\"\n  ports:\n    primary: \"${DB_PORT:3306}\"\n    replica: \"${DB_REPLICA_PORT:3307}\"\n\n```\n\nParse it in your Go code:\n```go\nyamlData := []byte(`\nservice:\n  name: \"${SERVICE_NAME:DefaultService}\"\n  enabled: \"${ENABLE_SERVICE:false}\"\n  timeout: \"${TIMEOUT:30s}\"\n  start_time: \"${START_TIME:2023-01-01T00:00:00Z}\"\n  rate: \"${RATE:1.0}\"\ndatabase:\n  hosts:\n    - \"${DB_HOST:localhost}\"\n  ports:\n    primary: \"${DB_PORT:3306}\"\n    replica: \"${DB_REPLICA_PORT:3307}\"\n`)\n\nvar config Config\nerr := jenv.UnmarshalYAML(yamlData, \u0026config)\nif err != nil {\n\tfmt.Printf(\"Error: %v\\n\", err)\n\treturn\n}\n\nfmt.Printf(\"Config: %+v\\n\", config)\n\n```\n\nEnsure you have environment variables set for the tests, or mock them in your test code.\n\n## Contributing\nWe welcome contributions! Please follow these steps:\n\n* Fork the repository.\n* Create a feature branch: `git checkout -b feature-name`.\n* Commit your changes: `git commit -m \"Add feature\"`.\n* Push to the branch: `git push origin feature-name`.\n* Open a Pull Request.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foarkflow%2Fjenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foarkflow%2Fjenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foarkflow%2Fjenv/lists"}