{"id":19819330,"url":"https://github.com/najibulloshapoatov/config","last_synced_at":"2026-05-31T23:31:04.499Z","repository":{"id":48966967,"uuid":"517058274","full_name":"najibulloShapoatov/config","owner":"najibulloShapoatov","description":"Simple Configuration library Allows the application to load its configuration from .config files or environment variables and automatic watches to changes","archived":false,"fork":false,"pushed_at":"2023-02-06T14:12:59.000Z","size":48,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-02-28T20:19:27.561Z","etag":null,"topics":["config","env","env-to-struct","environment-variables","go","golang","golang-library","java-properties","java-properties-golang"],"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/najibulloShapoatov.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":"2022-07-23T12:57:59.000Z","updated_at":"2023-09-03T15:17:11.000Z","dependencies_parsed_at":"2024-06-21T13:13:21.457Z","dependency_job_id":"e7d5bc7d-03c3-46bb-9eae-5af067b3ab1c","html_url":"https://github.com/najibulloShapoatov/config","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/najibulloShapoatov/config","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/najibulloShapoatov%2Fconfig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/najibulloShapoatov%2Fconfig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/najibulloShapoatov%2Fconfig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/najibulloShapoatov%2Fconfig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/najibulloShapoatov","download_url":"https://codeload.github.com/najibulloShapoatov/config/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/najibulloShapoatov%2Fconfig/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33753923,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-31T02:00:06.040Z","response_time":95,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["config","env","env-to-struct","environment-variables","go","golang","golang-library","java-properties","java-properties-golang"],"created_at":"2024-11-12T10:18:40.698Z","updated_at":"2026-05-31T23:31:04.479Z","avatar_url":"https://github.com/najibulloShapoatov.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple Configuration library\n\nAllows the application to load its configuration from `.config` files or environment variables and automatic watches to changes\n\n## Install\n\nTo install the package\n\n```\n$ go get github.com/najibulloShapoatov/config\n```\n\nMethods for Config struct\n\n| Method                                      |                                                                                  Description                                                                                  |\n|---------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|\n| Load(loaders ...Loader) error               |                Load runs the given loaders in order to load and parse the configuration values. The first loader that returns an error stops the load process                 |\n| Has(key string) bool                        |                                                                   Has returns true if the given key exists                                                                    |\n| SetWatchInterval(duration time.Duration)    |                                   SetWatchInterval sets interval of to automatic load configurations every duration, default interval is 5s                                   |\n| StopWatch()                                 |                                                                        StopWatch stopping all watches                                                                         |\n| Unmarshal(destinationPtr interface{}) error |                                          Unmarshal decodes the configuration in a structure based on the `config` and `default` tags                                          |\n| GetString(key string) (string, bool)        |                    GetString returns the value at the given key as a string and true if the key exists or empty string and false if the key doesn't exist                     |\n| GetFloat(key string) (float64, bool)        |      GetFloat returns the value at the given key parsed as a float and true if the key exists or 0.0 and false if the key doesn't exist or failed to parse as a float64       |\n| GetInt(key string) (int, bool)              |           GetInt returns the value at the given key parsed as a int and true if the key exists or 0 and false if the key doesn't exist or failed to parse as a int            |\n| GetBool(key string) (bool, bool)            | GetDuration returns the value at the given key parsed as Duration and true if the key exists or Duration(0) and false if the key doesn't exist or failed to parse as Duration |\n| GetKeys() (res []string)                    |                                                                        GetKeys return all loaded keys                                                                         |\n\n\nYou can add custom loader like `json` or `yaml`  or `xml` etc. you need implement `Loader` interface and add your loader in load function.\n```go\n// Loader is used to load and parse configuration values from various formats and location\ntype Loader interface {\n\t// Parse method is called\n\tParse() (map[string]string, error)\n\t// IsWatchable method should return true if you need watch this loader\n\tIsWatchable() bool\n}\n```\n\n\n\n## Usage example\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/joho/godotenv\"\n\t\"github.com/najibulloShapoatov/config\"\n\t\"time\"\n)\n\ntype MyConf struct {\n\tDebug         bool          `config:\"APPDEBUG\" default:\"true\"`\n\tName          string        `config:\"key.name\"`\n\tName1         string        `config:\"key.name1\" default:\"name_f\"`\n\tMultiline     string        `config:\"key.multiline\"`\n\tInt           int           `config:\"test.int.value\"`\n\tFloat         float64       `config:\"test.float.value\"`\n\tNegativeFloat float64       `config:\"test.negative.value\"`\n\tHex           int           `config:\"test.hex.number\"`\n\tOctal         int           `config:\"test.octal.number\"`\n\tBinary        int           `config:\"test.binary.number\"`\n\tExp           float64       `config:\"test.exponential.number\"`\n\tNegExp        float64       `config:\"test.negative.exponential.number\"`\n\tB1            bool          `config:\"test.bool.value1\"`\n\tB2            bool          `config:\"test.bool.value2\"`\n\tB3            bool          `config:\"test.bool.value3\"`\n\tB4            bool          `config:\"test.bool.value4\"`\n\tB5            bool          `config:\"test.bool.value5\"`\n\tB6            bool          `config:\"test.bool.value6\"`\n\tB7            bool          `config:\"test.bool.value7\"`\n\tDuration1     time.Duration `config:\"test.duration.value1\" default:\"1h\"`\n\tDuration2     time.Duration `config:\"test.duration.value2\"`\n}\n\nfunc main() {\n\n\terr := godotenv.Load()\n\tif err != nil {\n\t\treturn \n\t}\n\n\t//conf := config.Get()\n\n\tconf, err := config.Load(\n\t\tconfig.NewFileLoader(\"file.conf\", true), // load config from this file\n\t\tconfig.NewEnvLoader(false, \"app\"),       // and also from environment variables\n\t\tconfig.NewStringLoader(`\ntest.int.value = 7\ntest.float.value = 3.17\ntest.negative.value = -1.7\n`),\n\t)\n\tif err != nil {\n\t\tfmt.Println(\"failed to parse\", err)\n\t}\n\n\t// unmarshall directly into a struct\n\tvar cfg MyConf\n\tif err := conf.Unmarshal(\u0026cfg); err != nil {\n\t\tfmt.Println(\"some error\", err)\n\t}\n\n\tfmt.Printf(\"+%v\", cfg)\n\tfmt.Println()\n\n\t// retrieve a value by name\n\tisDebug, exists := conf.GetBool(\"APPDEBUG\")\n\n\tfmt.Println(\"isDebug: \", isDebug, \" exists: \", exists)\n}\n```\n\n## Configuration files\n\nConfiguration files are mostly `key=value` files but with few additions. For example, numbers are evaluated by the parser and booleans can be all truthy values besides true or false. Other files can be included using the `include` directive\n\n```bash\n# String values\nkey.name = \"value\" # this is inline comment\nkey.multiline = \"multi \\\nline \\\nstring\"\n\n# Number values\ntest.int.value = 5\ntest.float.value = 3.14\ntest.negative.value = -1.2\ntest.hex.number = 0x1234 # will parse to 4660\ntest.octal.number = 0o123 # will parse to 83\ntest.binary.number = 0b1010101 # will parse to 85\ntest.exponential.number = 1e3 # will parse to 1000\ntest.negative.exponential.number = 2e-2 # will parse to 0.02\n\n# Boolean values\ntest.bool.value1 = yes       # or no\ntest.bool.value2 = on        # or off\ntest.bool.value3 = set       # or unset\ntest.bool.value4 = active    # or inactive\ntest.bool.value5 = enabled   # or disabled\ntest.bool.value6 = true      # or false\ntest.bool.value6 = 1         # or 0\n\n# Duration\ntest.duration.value1 = \"1h5m\"\ntest.duration.value2 = \"3s\"\n\n# Include other file\ninclude \"sub-config-file.conf\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnajibulloshapoatov%2Fconfig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnajibulloshapoatov%2Fconfig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnajibulloshapoatov%2Fconfig/lists"}