https://github.com/piszmog/cfservices
Retrieve configurations from Cloud Foundry
https://github.com/piszmog/cfservices
cloudfoundry go golang vcap-services
Last synced: about 2 months ago
JSON representation
Retrieve configurations from Cloud Foundry
- Host: GitHub
- URL: https://github.com/piszmog/cfservices
- Owner: Piszmog
- License: mit
- Created: 2018-07-15T21:19:57.000Z (almost 7 years ago)
- Default Branch: main
- Last Pushed: 2024-05-09T03:01:06.000Z (about 1 year ago)
- Last Synced: 2024-06-20T14:17:19.114Z (11 months ago)
- Topics: cloudfoundry, go, golang, vcap-services
- Language: Go
- Homepage:
- Size: 108 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# CF Services
[](https://pkg.go.dev/github.com/Piszmog/cfservices/v2)
[](https://github.com/Piszmog/cfservices/workflows/Go/badge.svg)
[](https://coveralls.io/github/Piszmog/cfservices?branch=master)
[](https://goreportcard.com/report/github.com/Piszmog/cfservices/v2)
[](https://github.com/Piszmog/cfservices/releases/latest)
[](https://opensource.org/licenses/MIT)This library is aimed at removing the boilerplate code and let developers just worry about using actually connecting to
services they have bounded to their app.`go get github.com/Piszmog/cfservices/v2`
## Retrieving VCAP_SERVICES
Simply use `cfservices.GetServices()`.```go
package main
import "github.com/Piszmog/cfservices/v2"func main() {
services, err := cfservices.GetServices()
if err != nil {
// handle error
}
service := services["serviceA"]
// Use information about service A to perform actions (such as creating an OAuth2 Client)
}
```## Retrieving Credentials of a Service
Call `cfservices.GetServiceCredentials(..)` by passing the `VCAP_SERVICES` marshalled JSON and the name of the service to retrieve the
credentials for. If `VCAP_SERVICES` is guaranteed to be an environment variable use `cfservices.GetServiceCredentialsFromEnvironment(..)`
instead.```go
package main
import "github.com/Piszmog/cfservices/v2"func main() {
var services map[string][]cfservices.Service
// Read the services into the struct
creds, err := cfservices.GetServiceCredentials(services, "serviceB")
if err != nil {
// handle error
}
// Use credentials...
// Retrieve the JSON from the environment
creds, err = cfservices.GetServiceCredentialsFromEnvironment("serviceB")
if err != nil {
// handle error
}
// Use credentials...
}
```