Documentation ¶
Overview ¶
Package cfutil provides a number of convenience functions to apps being developed for use in a Cloudfoundry environment. For local development it can simulate the CF environment variables that your app typically expects. It can also emulate Cloudfoundry services based on environment variables.
Index ¶
- Constants
- func CreateURLFromServiceCatalog(catalog *consul.CatalogService) (string, error)
- func Current() (appEnv *cfenv.App, err error)
- func ForceHTTP() bool
- func GetAppIndex() int
- func GetApplicationName() (string, error)
- func GetHostname() (string, error)
- func Getenv(name string) string
- func IsFirstInstance() bool
- func IsLocal() bool
- func ListenString() string
- func MattermostDSN(serviceName string) (*url.URL, error)
- func Migrate(connectString, path string) ([]error, bool)
- func NewConnection(driver, name string) (conn *sqlx.DB, connectString string, err error)
- func RabbitMQAdminURI(serviceName string) (string, error)
- func SentryDSN(serviceName string) (string, error)
- type ConsulClient
- func (client *ConsulClient) ConsulDatacenter() (string, error)
- func (client *ConsulClient) DiscoverServiceURL(serviceName, tags string) (string, error)
- func (client *ConsulClient) GetConsulKey(mooncoreKey string) (string, error)
- func (client *ConsulClient) GetConsulKeyValue(mooncoreKey string) (string, error)
- func (client *ConsulClient) ServiceRegister(name string, path string, tags ...string) error
- func (client *ConsulClient) Services() ([]string, error)
- type Consumer
- func (c *Consumer) AnnounceQueue(queueName, bindingKey string) (<-chan amqp.Delivery, error)
- func (c *Consumer) Connect() error
- func (c *Consumer) Handle(d <-chan amqp.Delivery, fn ConsumerHandlerFunc, threads int, queue string, ...)
- func (c *Consumer) ReConnect(queueName, bindingKey string) (<-chan amqp.Delivery, error)
- func (c *Consumer) Start() error
- type ConsumerConfig
- type ConsumerHandlerFunc
- type DefaultLogger
- func (l DefaultLogger) Critical(c context.Context, format string, args ...interface{})
- func (l DefaultLogger) Debug(c context.Context, format string, args ...interface{})
- func (l DefaultLogger) Error(c context.Context, format string, args ...interface{})
- func (l DefaultLogger) Info(c context.Context, format string, args ...interface{})
- func (l DefaultLogger) Raw(c context.Context, rawMessage string)
- func (l DefaultLogger) Warning(c context.Context, format string, args ...interface{})
- type HSDPLogger
- func (f HSDPLogger) Critical(c context.Context, format string, args ...interface{})
- func (f HSDPLogger) Debug(c context.Context, format string, args ...interface{})
- func (f HSDPLogger) Error(c context.Context, format string, args ...interface{})
- func (f *HSDPLogger) Format(entry *logrus.Entry) ([]byte, error)
- func (f HSDPLogger) Info(c context.Context, format string, args ...interface{})
- func (f HSDPLogger) Raw(c context.Context, rawString string)
- func (f HSDPLogger) Warning(c context.Context, format string, args ...interface{})
- type Logger
- type LoggerConfig
- type PHService
- type Producer
- type ProducerConfig
- type SMTPService
- type Value
- type VaultClient
Constants ¶
const KeyCorrelationID = "correlationid" // TODO: get rid of this magic
Variables ¶
This section is empty.
Functions ¶
func CreateURLFromServiceCatalog ¶
func CreateURLFromServiceCatalog(catalog *consul.CatalogService) (string, error)
func ForceHTTP ¶
func ForceHTTP() bool
ForceHTTP() returns true if the environment variable `FORCE_HTTP` contains `true`. This is useful for example when you are running your app locally and don't have access to working TLS certificates.
func GetAppIndex ¶
func GetAppIndex() int
GetAppIndex() returns the app index when running in Cloudfoundry.
func GetApplicationName ¶
GetApplicationName() returns the name of the app within Cloudfoundry
func GetHostname ¶
GetHostname() returns the (first) hostname designated to your app within Cloudfoundry
func IsFirstInstance ¶
func IsFirstInstance() bool
IsFirstInstance() returns true if the instance calling it is the first running instance of the app within Cloudfoundry. This is useful if you want to for example trigger database migrations but only want to execute these on the first starting instance.
func ListenString ¶
func ListenString() string
ListenString() returns the listen string based on the `PORT` environment variable value
func Migrate ¶
Migrate() starts a database migration for the given database specified in `connectString`. It looks in the `path` for the migration files.
func NewConnection ¶
NewConnection opens a new database connection given the driver and CF service name. Currently only postgres is supported.
func RabbitMQAdminURI ¶
Types ¶
type ConsulClient ¶ added in v0.2.0
func NewConsulClient ¶
func NewConsulClient(server, namespace, token string) (*ConsulClient, error)
NewConsulClient() returns a new consul client which you can use to access the Consul cluster HTTP API. It uses `CONSUL_MASTER` and `CONSUL_TOKEN` environment variables to set up the HTTP API connection.
func (*ConsulClient) ConsulDatacenter ¶ added in v0.2.0
func (client *ConsulClient) ConsulDatacenter() (string, error)
func (*ConsulClient) DiscoverServiceURL ¶ added in v0.2.0
func (client *ConsulClient) DiscoverServiceURL(serviceName, tags string) (string, error)
func (*ConsulClient) GetConsulKey ¶ added in v0.2.0
func (client *ConsulClient) GetConsulKey(mooncoreKey string) (string, error)
func (*ConsulClient) GetConsulKeyValue ¶ added in v0.2.0
func (client *ConsulClient) GetConsulKeyValue(mooncoreKey string) (string, error)
func (*ConsulClient) ServiceRegister ¶ added in v0.2.0
func (client *ConsulClient) ServiceRegister(name string, path string, tags ...string) error
Use ServiceRegister() to register your app in the Consul cluster Optionally you can provide a health endpoint on your URL and a number of tags to make your service more discoverable
func (*ConsulClient) Services ¶ added in v0.2.0
func (client *ConsulClient) Services() ([]string, error)
Services() returns the list of services available from the Consul cluster
type Consumer ¶
type Consumer struct {
// contains filtered or unexported fields
}
func NewConsumer ¶
func NewConsumer(config ConsumerConfig) (*Consumer, error)
func (*Consumer) AnnounceQueue ¶
AnnounceQueue sets the queue that will be listened to for this connection...
func (*Consumer) Handle ¶
func (c *Consumer) Handle( d <-chan amqp.Delivery, fn ConsumerHandlerFunc, threads int, queue string, routingKey string)
Handle has all the logic to make sure your program keeps running d should be a delievey channel as created when you call AnnounceQueue fn should be a function that handles the processing of deliveries this should be the last thing called in main as code under it will become unreachable unless put int a goroutine. The q and rk params are redundent but allow you to have multiple queue listeners in main without them you would be tied into only using one queue per connection
func (*Consumer) ReConnect ¶
ReConnect is called in places where NotifyClose() channel is called wait 30 seconds before trying to reconnect. Any shorter amount of time will likely destroy the error log while waiting for servers to come back online. This requires two parameters which is just to satisfy the AccounceQueue call and allows greater flexability
type ConsumerConfig ¶
type ConsumerHandlerFunc ¶
type DefaultLogger ¶ added in v0.2.0
type DefaultLogger struct { }
func (DefaultLogger) Critical ¶ added in v0.2.0
func (l DefaultLogger) Critical(c context.Context, format string, args ...interface{})
func (DefaultLogger) Debug ¶ added in v0.2.0
func (l DefaultLogger) Debug(c context.Context, format string, args ...interface{})
func (DefaultLogger) Error ¶ added in v0.2.0
func (l DefaultLogger) Error(c context.Context, format string, args ...interface{})
func (DefaultLogger) Info ¶ added in v0.2.0
func (l DefaultLogger) Info(c context.Context, format string, args ...interface{})
type HSDPLogger ¶
type HSDPLogger struct {
// contains filtered or unexported fields
}
func (HSDPLogger) Critical ¶
func (f HSDPLogger) Critical(c context.Context, format string, args ...interface{})
func (HSDPLogger) Debug ¶
func (f HSDPLogger) Debug(c context.Context, format string, args ...interface{})
func (HSDPLogger) Error ¶
func (f HSDPLogger) Error(c context.Context, format string, args ...interface{})
type Logger ¶
type Logger interface { Debug(c context.Context, format string, args ...interface{}) Info(c context.Context, format string, args ...interface{}) Warning(c context.Context, format string, args ...interface{}) Error(c context.Context, format string, args ...interface{}) Critical(c context.Context, format string, args ...interface{}) Raw(c context.Context, rawMessage string) }
func NewLogger ¶
func NewLogger(config LoggerConfig) Logger
type LoggerConfig ¶ added in v0.2.0
type PHService ¶
type PHService struct { Type string `json:"type"` ApplicationName string `json:"application_name"` PropositionName string `json:"proposition_name"` BaseURL string `json:"base_url"` Client string `json:"client"` Password string `json:"password"` }
func ConnectPHService ¶
type Producer ¶
type Producer struct {
// contains filtered or unexported fields
}
func NewProducer ¶
func NewProducer(config ProducerConfig) (*Producer, error)
type ProducerConfig ¶
type SMTPService ¶
type SMTPService struct { url.URL Authentication string EnableStartTLSAuto string Username string Password string }
func FindSMTPService ¶
func FindSMTPService(serviceName string) (*SMTPService, error)
type VaultClient ¶
type VaultClient struct { vault.Client Endpoint string RoleID string SecretID string ServiceSecretPath string ServiceTransitPath string SpaceSecretPath string OrgSecretPath string Secret *vault.Secret }
func NewVaultClient ¶
func NewVaultClient(serviceName string) (*VaultClient, error)
func (*VaultClient) Login ¶
func (v *VaultClient) Login() (err error)
func (*VaultClient) ReadOrgString ¶
func (v *VaultClient) ReadOrgString(path string) (string, error)
func (*VaultClient) ReadSpaceString ¶
func (v *VaultClient) ReadSpaceString(path string) (string, error)
func (*VaultClient) ReadString ¶
func (v *VaultClient) ReadString(prefix, path string) (string, error)