{"id":14985678,"url":"https://github.com/goreflect/gostructor","last_synced_at":"2025-04-11T22:06:46.952Z","repository":{"id":55968118,"uuid":"233617426","full_name":"goreflect/gostructor","owner":"goreflect","description":"Go configurator structures library","archived":false,"fork":false,"pushed_at":"2022-02-02T18:03:30.000Z","size":585,"stargazers_count":12,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T22:06:46.600Z","etag":null,"topics":["configuration","default-values","environment-variables","fetching-secrets","golang","golang-library","hocon","json","slice","spring-config-server","vault","yaml","yml"],"latest_commit_sha":null,"homepage":"https://goreflect.github.io/gostructor/","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/goreflect.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-01-13T14:41:38.000Z","updated_at":"2023-10-20T10:09:24.000Z","dependencies_parsed_at":"2022-08-15T10:31:11.005Z","dependency_job_id":null,"html_url":"https://github.com/goreflect/gostructor","commit_stats":null,"previous_names":["goreflect/go_structor"],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goreflect%2Fgostructor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goreflect%2Fgostructor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goreflect%2Fgostructor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goreflect%2Fgostructor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/goreflect","download_url":"https://codeload.github.com/goreflect/gostructor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248487716,"owners_count":21112191,"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":["configuration","default-values","environment-variables","fetching-secrets","golang","golang-library","hocon","json","slice","spring-config-server","vault","yaml","yml"],"created_at":"2024-09-24T14:11:28.423Z","updated_at":"2025-04-11T22:06:46.920Z","avatar_url":"https://github.com/goreflect.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\r\n# Gostructor [![Actions Status](https://github.com/goreflect/gostructor/workflows/CI_dev/badge.svg)](https://github.com/goreflect/gostructor/actions?query=workflow%3ACI_dev) [![Go Report Card](https://goreportcard.com/badge/github.com/goreflect/gostructor)](https://goreportcard.com/report/github.com/goreflect/gostructor) [![codecov](https://codecov.io/gh/goreflect/gostructor/branch/master/graph/badge.svg)](https://codecov.io/gh/goreflect/gostructor)\r\n\r\n____\r\n\r\n\r\n\u003cimg src=\"https://github.com/goreflect/gostructor/raw/master/LogotypeGostructor.png\"/\u003e\r\n\r\n## Version: v0.7\r\n\r\nUniversal configuration library by tags\r\n\r\n## Current supporting input formats\r\n\r\n- hocon values\r\n- default values\r\n- environment variables\r\n- vault configs\r\n- json values\r\n- yaml values\r\n- ini values \r\n- toml values \r\n\r\n## Current supporting types\r\n\r\n- int, int8, int16, int32, int64\r\n- uint, uint8, uint16, uint32, uint64\r\n- float32, float64\r\n- string\r\n- bool\r\n- map[string\\int]string\\int\\float32\\float64\r\n- slices of any types from (int32, int64, int, string, bool, float32, float64)\r\n\r\n## Plan of upgrading\r\n0.8:\r\n1. Adding support file store fetching\r\n0.9:\r\n1. adding support key\\value store backends (with callback)\r\n2. adding support config server fetching content like Spring Cloud Config Server\r\n\r\n1.0:\r\n1. adding support uint types (done 0.6.6)\r\n2. change transition dependencies like go-yaml, lfjson by native map[string]interface{}\\string\r\n\r\n## Ideas for future\r\n\r\n1. Live watching for contract by git (maybe mechanism for watching changes like do it spring)\r\n2. CodeGen plugin for protoc for generating models with predefined tags\r\n\r\n### Tags\r\n\r\n- [x] cf_hocon - setup value for this field from hocon\r\n- [x] cf_default - setup default value for this field\r\n- [x] cf_env - setup value from env variable by name in this tag\r\n- [x] cf_yaml - setup value for this field from yaml \r\n- [x] cf_json - setup value for this field from json\r\n- [x] cf_ini - setup value for this field from ini\r\n- [x] cf_toml - setup value for this field from toml \r\n- [x] cf_vault - setup secret for this field from hashi corp vault\r\n\r\n## Running configuring by smart variant\r\n\r\nFor Run configuration by smart variant autostart analysing of using tags. Library will start configuring  your structure by pipeline with all founded tags.\r\n\r\n```go\r\ntype Test struct {\r\n    MyValue1 string `cf_default:\"turur\" cf_hocon:\"mySourceValue1\"`\r\n    MySlice1 []bool `cf_default:\"true,false,false,true\" cf_env:\"MY_SIGNALS\"`\r\n}\r\n\r\n// in this example do use 3 tags: cf_default (using default values which setup inline tag)\r\n// cf_env - using environment variable\r\n// cf_hocon - using hocon source file \r\n\r\n//....\r\n\r\nfunc myConfigurator() {\r\n    os.Setenv(tags.HoconFile, , \"testhocon.hocon\")\r\n    myStruct, errConfiguring := gostructir.ConfigureSmart(\u0026Test{})\r\n    // check errConfiguring for any errors\r\n    if errConfiguring != nil {\r\n        /// action for error\r\n    }\r\n\r\n    // cast interface{} into Test structure\r\n    myValues := myStruct.(*Test)\r\n    // now, u structure already filled\r\n} \r\n\r\n```\r\n\r\n## Running configuring by setup\r\n\r\nYou can also setting configuring pipeline like this:\r\n\r\n```go\r\ntype Test struct {\r\n    MyValue1 string `cf_default:\"turur\" cf_hocon:\"mySourceValue1\"`\r\n    MySlice1 []bool `cf_default:\"true,false,false,true\" cf_env:\"MY_SIGNALS\"`\r\n}\r\n\r\nfunc myConfigurator() {\r\n    os.Setenv(tags.HoconFile, , \"testhocon.hocon\")\r\n    myStruct, errConfiguring := gostructir.ConfigureSetup(\u0026Test{}, []infra.FuncType{\r\n        infra.FunctionSetupEnvironment,\r\n    })// you should setup only by order configure\r\n    // check errConfiguring for any errors\r\n    if errConfiguring != nil {\r\n        /// action for error\r\n    }\r\n\r\n    // cast interface{} into Test structure\r\n    myValues := myStruct.(*Test)\r\n    // now, u structure already filled\r\n} \r\n\r\n```\r\n\r\n## Fetching secrets from vault\r\n\r\nFor fetching secrets you should add 2 environment variables: VAULT_ADDRESS, VAULT_TOKEN. After all, you can add cf_vault tag into your structure tags. \r\n\r\nNow vault configure support all basic types and also complex type: slice\r\n\r\nFor Example:\r\n\r\n```go\r\ntype Test struct {\r\n    MySecretKey string `cf_vault:\"my-secret-service/stage/tururu#my-key\"`\r\n    MyCustomIntKey int16 `cf_vault:\"my-secret-service/stage/tururur#my-key2\"`\r\n    TestSda []int32 `cf_vault:\"my-secret-service/stage/tururu#my-key3\"`\r\n}\r\n```\r\n\r\n## Setting up files or any other sources\r\n\r\nBy the way u can configuring files by environment variables:\r\n\r\n1. For hocon files - GOSTRUCTOR_HOCON\r\n2. For json files - GOSTRUCTOR_JSON\r\n3. For yaml files - GOSTRUCTOR_YAML\r\n4. For ini files - GOSTRUCTOR_INI\r\n5. For toml files - GOSTRUCTOR_TOML\r\n\r\n## Infrastructure\r\n\r\nFor the best way to automatic publish versions of patch added github workflow for publish in master changes\r\n\r\n## Configuration. Step By Step\r\n\r\n1. Chose pool needed sources, and writed them into target field tag.\r\n2. Configuring environment.\r\n\r\n\r\n## For fetching from remote Spring Cloud Config Server\r\n\r\n1. Needed setting up env variable","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoreflect%2Fgostructor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoreflect%2Fgostructor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoreflect%2Fgostructor/lists"}