Code Monkey home page Code Monkey logo

go-cfenv's Introduction

Go CF Environment Package Build Status - Master

Overview

GoDoc

cfenv is a package to assist you in writing Go apps that run on Cloud Foundry. It provides convenience functions and structures that map to Cloud Foundry environment variable primitives (http://docs.cloudfoundry.org/devguide/deploy-apps/environment-variable.html).

Usage

go get github.com/cloudfoundry-community/go-cfenv

package main

import (
	"github.com/cloudfoundry-community/go-cfenv"
)

func main() {
	appEnv, _ := cfenv.Current()

	fmt.Println("ID:", appEnv.ID)
	fmt.Println("Index:", appEnv.Index)
	fmt.Println("Name:", appEnv.Name)
	fmt.Println("Host:", appEnv.Host)
	fmt.Println("Port:", appEnv.Port)
	fmt.Println("Version:", appEnv.Version)
	fmt.Println("Home:", appEnv.Home)
	fmt.Println("MemoryLimit:", appEnv.MemoryLimit)
	fmt.Println("WorkingDir:", appEnv.WorkingDir)
	fmt.Println("TempDir:", appEnv.TempDir)
	fmt.Println("User:", appEnv.User)
	fmt.Println("Services:", appEnv.Services)
}

Contributing

Pull requests welcomed.

go-cfenv's People

Contributors

arthurhlt avatar davecheney avatar drnic avatar joefitzgerald avatar jsloyer avatar krujos avatar lnguyen avatar teddyking avatar vchrisr avatar wayneeseguin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

cloud-gov

go-cfenv's Issues

Read user provided env

HI,

Is there a way to get the user provided env with this lib ? what I see is the env which is provided by the platform but I didnt get the user provided env ...

Thanks
Jenney

CredentialString(key string) can not deal with multi-layer keys

CredentialString(key string) only can get the first layer string values. It will be nice we can run Credential(key) to get nested credential with any type. for example Credential(protocols.amqp.uri)will get amqp://guest:guest@rabbitmq:5672,Credential(protocols.amqp.ssl) will get false

"VCAP_SERVICES": {
  "p-rabbitmq": [
   {
    "credentials": {
     "protocols": {
      "amqp": {
       "uri": "amqp://guest:guest@rabbitmq:5672"
       "ssl": false
      } }  } }]
}

JSON parsing fails for VCAP_SERVICES with complex credentials

Example env var provided by Redis service broker. Parser fails for "ports" key with

panic: 1 error(s) decoding:

* '[0].Credentials[ports]' expected type 'string', got unconvertible type 'map[string]interface {}' [recovered]
    panic: 1 error(s) decoding:
{
    "redis-lite": [
        {
            "credentials": {
                "hostname": "10.10.10.1",
                "password": "abc",
                "port": "32843",
                "ports": {
                    "6379/tcp": "32843"
                }
            },
            "label": "redis-lite",
            "name": "uptime-redis",
            "plan": "free",
            "tags": [
                "redis28",
                "redis",
                "key-value"
            ]
        }
    ]
}

parsing of VCAP_SERVICES fails when credentials contain non-string values

Using IBM Bluemix (which is a larger CloudFoundry installation) with a Cloudant service produces a VCAP_SERVICES that looks like this:

{
   "cloudantNoSQLDB": [
      {
         "name": "my_cloudant",
         "label": "cloudantNoSQLDB",
         "plan": "Shared",
         "credentials": {
            "username": "18675309-0000-4aaa-bbbb-999999999-bluemix",
            "password": "18675309deadbeefaaaabbbbccccddddeeeeffff000099999999999999999999",
            "host": "01234567-9999-4999-aaaa-abcdefabcdef-bluemix.cloudant.com",
            "port": 443,
            "url": "https://18675309-0000-4aaa-bbbb-999999999-bluemix:18675309deadbeefaaaabbbbccccddddeeeeffff000099999999999999999999@01234567-9999-4999-aaaa-abcdefabcdef-bluemix.cloudant.com"
         }
      }
   ]
}

However, when trying to parse this using cfenv.Current() the following error is thrown:

1 error(s) decoding:

* '[0].Credentials[port]' expected type 'string', got unconvertible type 'float64'

This is because the port field for the cloudant service above is not a string, but a number, and therefore the JSON decoder throws an error because it's expecting all fields of credentials to be strings.

Rename and move to cf-community

[cc @jambay for his visibility and thoughts]

@joefitzgerald I thinking about how we could rename this project (golang client library for access to ENV vars within a CF app) and bring it together with other CF ENV client libraries. @pmuellr has been working on a node.js one. There is a ruby one somewhere with a different name & location too. Probably a Java one too in the https://github.com/cloudfoundry-community/cf-java-component repo somewhere. (I DID SO MUCH RESEARCH FOR THIS EMAIL).

I was thinking that perhaps we rename the repos to have a similar name suffix (<lang>-cf-env) or prefix (cf-env-<lang>) and move them all into cf-community or cf-incubator.

@pmuellr noted that https://github.com/cloudfoundry-community/cf-env perhaps had a name that also claimed to be a client library. Or at least would get in the way of the naming scheme above. Perhaps it can be renamed to show-env.

New Release

Hi,

We are using your project in our code. Thanks for this repository!

Are there any timelines for a new release?

There are 4 commits that were pushed to master after the latest release. We prefer to depend on a release instead of depending on a branch or a commit id.

Can you please create a new release with the latest code?

Regards,
Firas

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.