{"id":25274539,"url":"https://github.com/piszmog/cloudconfigclient","last_synced_at":"2025-10-27T11:31:07.041Z","repository":{"id":34099513,"uuid":"143647129","full_name":"Piszmog/cloudconfigclient","owner":"Piszmog","description":"Go client library for Spring Config Server","archived":false,"fork":false,"pushed_at":"2024-10-17T08:39:10.000Z","size":304,"stargazers_count":18,"open_issues_count":0,"forks_count":6,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-10-19T13:09:16.225Z","etag":null,"topics":["cloud-foundry","cloudfoundry","config","config-server","go","golang","pcf","pivotal-cloud-foundry","spring"],"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/Piszmog.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-05T20:57:30.000Z","updated_at":"2024-10-17T08:39:14.000Z","dependencies_parsed_at":"2023-11-15T01:43:14.986Z","dependency_job_id":"4c64c2eb-5582-42f2-9dcb-67d353337ea2","html_url":"https://github.com/Piszmog/cloudconfigclient","commit_stats":null,"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Piszmog%2Fcloudconfigclient","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Piszmog%2Fcloudconfigclient/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Piszmog%2Fcloudconfigclient/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Piszmog%2Fcloudconfigclient/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Piszmog","download_url":"https://codeload.github.com/Piszmog/cloudconfigclient/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238488455,"owners_count":19480766,"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":["cloud-foundry","cloudfoundry","config","config-server","go","golang","pcf","pivotal-cloud-foundry","spring"],"created_at":"2025-02-12T14:30:37.687Z","updated_at":"2025-10-27T11:31:07.035Z","avatar_url":"https://github.com/Piszmog.png","language":"Go","readme":"# Go Config Server Client\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/Piszmog/cloudconfigclient.svg)](https://pkg.go.dev/github.com/Piszmog/cloudconfigclient/v2)\n[![Build Status](https://github.com/Piszmog/cloudconfigclient/workflows/Go/badge.svg)](https://github.com/Piszmog/cloudconfigclient/workflows/Go/badge.svg)\n[![Coverage Status](https://coveralls.io/repos/github/Piszmog/cloudconfigclient/badge.svg?branch=main)](https://coveralls.io/github/Piszmog/cloudconfigclient?branch=main)\n[![Go Report Card](https://goreportcard.com/badge/github.com/Piszmog/cloudconfigclient)](https://goreportcard.com/report/github.com/Piszmog/cloudconfigclient/v2)\n[![GitHub release](https://img.shields.io/github/release/Piszmog/cloudconfigclient.svg)](https://github.com/Piszmog/cloudconfigclient/releases/latest)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nGo library for Spring Config Server. Inspired by the Java\nlibrary [Cloud Config Client](https://github.com/Piszmog/cloud-config-client).\n\n`go get github.com/Piszmog/cloudconfigclient/v2`\n\n#### V2 Migration\n\nSee [V2 Migration](https://github.com/Piszmog/cloudconfigclient/wiki/V2-Migration) for details on how to migrate from V1\nto V2\n\n## Description\n\nSpring's Config Server provides way to externalize configurations of applications. Spring's\n[Spring Cloud Config Client](https://github.com/spring-cloud/spring-cloud-config/tree/master/spring-cloud-config-client)\ncan be used to load the base configurations that an application requires to properly function.\n\nThis library provides clients the ability to load Configurations and Files from the Config Server.\n\n### Compatibility\n\nThis library is compatible with versions of Spring Config Server greater than or equal to `1.4.x.RELEASE`. Prior\nversions of the Config Server do not provide the endpoint necessary to retrieve files for the Config Server's default\nbranch.\n\n#### Spring Cloud Config Server v3.x\n\nSince Spring Cloud Services v3.0, the service name in `VCAP_SERVICES` has changed from `p-config-server` to\nbe `p.config-server`.\n\nTo help mitigate migration difficulties, `cloudconfigclient.New(cloudconfigclient.DefaultCFService())` will first search\nfor the service `p.config-server` (v3.x). If the v3.x service could not be found,\n`p-config-server` (v2.x) will be search for.\n\nSee [Spring Cloud Services Differences](https://docs.pivotal.io/spring-cloud-services/3-1/common/config-server/managing-service-instances.html#differences-between-3-0-and-earlier)\nfor more details.\n\n## Example Usage\n\nBelow is an example usage of the library to retrieve a file from the Config Server and to retrieve the application's\nconfigurations\n\n* For local config client, there are two options (`Option`) the create a client\n    1. Call `LocalEnv()`. Set the environment variable `CONFIG_SERVER_URLS`. It is a comma separated list of all the\n       base URLs\n    2. Call `Local(baseUrls ...string)`. Provide the array of base URLs of Config Servers.\n* If the config server is protected with basic auth, call `Basic` with the username and password.\n* For running in Cloud Foundry, ensure a Config Server is bounded to the application. `VCAP_SERVICES` will be provided\n  as an environment variables with the credentials to access the Config Server\n* For connecting to a Config Server via OAuth2 and not deployed to Cloud Foundry, an OAuth2 Client can be created\n  with `OAuth2(baseURL string, clientId string, secret string, tokenURI string)`\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/Piszmog/cloudconfigclient/v2\"\n\t\"net/http\"\n)\n\ntype File struct {\n\tExample Example `json:\"example\"`\n}\n\ntype Example struct {\n\tField string `json:\"field\"`\n}\n\nfunc main() {\n\t// To create a Client for a locally running Spring Config Server\n\tconfigClient, err := cloudconfigclient.New(cloudconfigclient.LocalEnv(\u0026http.Client{}))\n\t// Or\n\tconfigClient, err = cloudconfigclient.New(cloudconfigclient.Local(\u0026http.Client{}, \"http://localhost:8888\"))\n\t// or to create a Client for a Spring Config Server using Basic Authentication\n\tconfigClient, err = cloudconfigclient.New(cloudconfigclient.Basic(\u0026http.Client{}, \"username\", \"password\" \"http://localhost:8888\"))\n\t// or to create a Client for a Spring Config Server in Cloud Foundry\n\tconfigClient, err = cloudconfigclient.New(cloudconfigclient.DefaultCFService())\n\t// or to create a Client for a Spring Config Server with OAuth2\n\tconfigClient, err = cloudconfigclient.New(cloudconfigclient.OAuth2(\"config server uri\", \"client id\", \"client secret\",\n\t\t\"access token uri\"))\n\t// or a combination of local, Cloud Foundry, and OAuth2\n\tconfigClient, err = cloudconfigclient.New(\n\t\tcloudconfigclient.Local(\u0026http.Client{}, \"http://localhost:8888\"),\n\t\tcloudconfigclient.DefaultCFService(),\n\t\tcloudconfigclient.OAuth2(\"config server uri\", \"client id\", \"client secret\", \"access token uri\"),\n\t)\n\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\tvar file File\n\t// Retrieves a 'temp1.json' from the Config Server's default branch in directory 'temp' and deserialize to File\n\terr = configClient.GetFile(\"temp\", \"temp1.json\", \u0026file)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\tfmt.Printf(\"%+v\\n\", file)\n\t// Retrieves a 'temp2.txt' from the Config Server's default branch in directory 'temp' as a byte slice ([]byte)\n\tb, err := configClient.GetFileRaw(\"temp\", \"temp2.txt\")\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\tfmt.Println(string(b))\n\n\t// Retrieves the configurations from the Config Server based on the application name and active profiles\n\tconfig, err := configClient.GetConfiguration(\"testApp\", \"dev\")\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\tfmt.Printf(\"%+v\", config)\n\t// if we want, we can convert the config to a struct\n\tvar configStruct Config\n\terr = config.Unmarshal(\u0026configStruct)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n}\n\ntype Config struct {\n\tField1 string `json:\"example\"`\n\tField2 int    `json:\"field2\"`\n}\n```\n\n#### VCAP_SERVICES\n\nWhen an application is deployed to Cloud Foundry, services can be bounded to the application. When a service is bounded\nto an application, the application will have the necessary connection information provided in the environment\nvariable `VCAP_SERVICES`.\n\nStructure of the `VCAP_SERVICES` value\n\n```json\n{\n  \"\u003cservice type :: e.g. p-config-server\u003e\": [\n    {\n      \"name\": \"\u003cthe service name\u003e\",\n      \"instance_name\": \"\u003cservice name\u003e\",\n      \"binding_name\": \"\u003cbounded name of the service\u003e\",\n      \"credentials\": {\n        \"uri\": \"\u003cURI of the service :: used to connect to the service\u003e\",\n        \"client_secret\": \"\u003cOAuth2 client secret\u003e\",\n        \"client_id\": \"\u003cOAuth2 client id\u003e\",\n        \"access_token_uri\": \"\u003cOAuth2 token URI\u003e\"\n      },\n      ...\n    }\n  ]\n}\n```\n\n##### CredHub Reference\n\nNewer versions of PCF (\u003e=2.6) may have services that use a CredHub Reference to store credential information.\n\nWhen viewing the Environment Variables of an application via the UI, the credentials may appear as the following\n\n```json\n{\n  \"credentials\": {\n    \"credhub-ref\": \"/c/example-service-broker/example-service/faa677f5-25cd-4f1e-8921-14a9d5ab48b8/credentials\"\n  }\n}\n```\n\nWhen the application starts up, the `credhub-ref` is replaced with the actual credential values that application will\nneed to connect to the service.\n\n## Configurations\n\nThe Config Server allows the ability to retrieve configurations for an application. Only files that follow a strict\nnaming convention will be loaded,\n\n| File Name | \n| :---: |\n|`application.{yml/properties}`|\n|`application-{profile}.{yml/properties}`|\n|`{application name}.{yml/properties}`|\n|`{application name}-{profile}.{yml/properties}`|\n\nThe loaded configurations are in the following JSON format,\n\n```json\n{\n  \"name\": \"\u003cname of application\u003e\",\n  \"profiles\": \"\u003cprofiles passed in request\u003e\",\n  \"label\": \"\u003cGIT branch configurations loaded from\u003e\",\n  \"version\": \"\u003cversion\u003e\",\n  \"state\": \"\u003cstate\u003e\",\n  \"propertySources\": [\n    {\n      \"\u003cpropertySourceName\u003e\": {\n        \"name\": \"\u003cproperty source name\u003e\",\n        \"source\": {\n          \"\u003csource path in .properties format\u003e\": \"\u003cvalue\u003e\"\n        }\n      }\n    }\n  ]\n}\n```\n\nTo use the library to retrieve configurations, create a `Client` and invoke the\nmethod `GetConfiguration(applicationName string, profiles ...string)`. The return will be the struct representation of\nthe configuration JSON - `client.Configuration`.\n\n## Resources\n\nSpring's Config Server allows two ways to retrieve files from a backing repository.\n\n| URL Path | \n| :---: |\n|`/\u003cappName\u003e/\u003cprofiles\u003e/\u003cdirectory\u003e/\u003cfile\u003e?useDefaultLabel=true`|\n|`/\u003cappName\u003e/\u003cprofiles\u003e/\u003cbranch\u003e/\u003cdirectory\u003e/\u003cfile\u003e`|\n\n* When retrieving a file from the Config Server's default branch, the file must not exist at the root of the repository.\n* If the `directory` is in the `searchPath`, it does not have to be specified (depending on SCCS version)\n\nThe functions available to retrieve resource files\nare `GetFile(directory string, file string, interfaceType interface{})` and\n`GetFileFromBranch(branch string, directory string, file string, interfaceType interface{})`. To retrieve the data from\nthe files, the functions available are `GetFileRaw(directory string, file string)` and\n`GetFileFromBranchRaw(branch string, directory string, file string)`\n\n* The `interfaceType` is the object to deserialize the file to\n\n### Spring Cloud Config Server v3.x Changes\n\nThe following is only for certain versions of SCCS v3.x. If a file is not being found by the client, the following may\nbe true.\n\nSCCS v3.x slightly changed how files are retrieved. If the Config Server specified a directory in the `searchPaths`, the\npath should be excluded from the `GetFile(..)` invocation.\n\nFor example if `common` has been specified in the `searchPaths` and the file `common/foo.txt` needs to be retrieved,\nthen the `directory` to provide to `GetFile(..)`\nshould be `\"\"` (blank).\n\nThis differs with SCS v2.x where the directory in `searchPaths` did not impact the `directory` provided\nto `GetFile(..)` (e.g. to retrieve file `common/foo.txt`,\n`directory` would be `\"common\"`).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiszmog%2Fcloudconfigclient","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpiszmog%2Fcloudconfigclient","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiszmog%2Fcloudconfigclient/lists"}