{"id":13411199,"url":"https://github.com/diegomarangoni/typenv","last_synced_at":"2025-03-14T16:34:07.814Z","repository":{"id":57530856,"uuid":"276177953","full_name":"diegomarangoni/typenv","owner":"diegomarangoni","description":"Go minimalist typed environment variables library","archived":false,"fork":false,"pushed_at":"2023-01-19T13:49:20.000Z","size":25,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-07-31T20:45:11.414Z","etag":null,"topics":["go","golang","library"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/diegomarangoni.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-06-30T18:26:09.000Z","updated_at":"2023-11-30T08:36:50.000Z","dependencies_parsed_at":"2023-02-11T02:30:59.339Z","dependency_job_id":null,"html_url":"https://github.com/diegomarangoni/typenv","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diegomarangoni%2Ftypenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diegomarangoni%2Ftypenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diegomarangoni%2Ftypenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diegomarangoni%2Ftypenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/diegomarangoni","download_url":"https://codeload.github.com/diegomarangoni/typenv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243610899,"owners_count":20319047,"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":["go","golang","library"],"created_at":"2024-07-30T20:01:12.108Z","updated_at":"2025-03-14T16:34:07.446Z","avatar_url":"https://github.com/diegomarangoni.png","language":"Go","funding_links":[],"categories":["Configuration","配置","配置管理","配置管理 `配置解析库`","Uncategorized"],"sub_categories":["Standard CLI","Advanced Console UIs","标准CLI","标准 CLI"],"readme":"# Typenv\n\n[![go.dev](https://img.shields.io/static/v1?label=go.dev\u0026message=reference\u0026color=00add8)](https://pkg.go.dev/diegomarangoni.dev/typenv) [![go report](https://goreportcard.com/badge/diegomarangoni.dev/typenv)](https://goreportcard.com/report/diegomarangoni.dev/typenv) [![codecov](https://codecov.io/gh/diegomarangoni/typenv/branch/master/graph/badge.svg)](https://codecov.io/gh/diegomarangoni/typenv)\n\nTypenv is a minimalistic, zero dependency, typed environment variables library.\nIt does support the following types:\n\n* Bool\n* Duration\n* Float64\n* Float32\n* Int64\n* Int32\n* Int8\n* Int\n* String\n\n# Why typenv?\n\nHandling environment variables in other type than strings or even handling fallback values is not a simple task, typenv makes easy to handle string, boolean, integer, float and time duration environment variables and also allows you to easily set default values for then.\n\n# How to use it\n\n## Basic usage\n\nGo get the library:\n\n```shell\ngo get diegomarangoni.dev/typenv\n```\n\nAnd use it:\n\n```go\nif typenv.Bool(\"DEBUG\") {\n\t// do something\n}\n```\n\nIf the environment is **NOT** set, the zero value of the type will return, in this case `false`.\n\n## With default value\n\nYou can fallback to a default value in case the environment variable is not set.\n\n```go\nif typenv.Bool(\"DEBUG\", true) {\n\t// do something\n}\n```\n\nIf the environment is **NOT** set, the return value will be `true`.\n\n## With global default value\n\nYou can also set a global default value for a environment.\nUseful when you use the same environment with same default value several times.\n\n```go\nfunc init() {\n\ttypenv.SetGlobalDefault(\n\t\ttypenv.E(typenv.Bool, \"DEBUG\", true),\n\t)\n}\n\n...\n\nif typenv.Bool(\"DEBUG\") {\n\t// do something\n}\n```\n\nIf the environment is **NOT** set, the return value will be `true`.\n\n## Overriding global default value\n\nYou still can override the global default value by setting a local default.\n\n```go\nfunc init() {\n\ttypenv.SetGlobalDefault(\n\t\ttypenv.E(typenv.Bool, \"DEBUG\", true),\n\t)\n}\n\n...\n\nif typenv.Bool(\"DEBUG\", false) {\n\t// do something\n}\n```\n\nIf environment is **NOT** set, the return value will be `false`, even if global default is telling that is `true`.\n\n\u003c!-- go test -coverprofile coverage.out \u0026\u0026 go tool cover -html=coverage.out -o coverage.html --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiegomarangoni%2Ftypenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdiegomarangoni%2Ftypenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiegomarangoni%2Ftypenv/lists"}