Skip to content

Clever/discovery-go

Repository files navigation

discovery-go

This library programmatically finds endpoints for dependencies. Similar to discovery-node and disocvery-python.

See Service Discovery for more details.

API

Godoc Documentation

Examples

gearmanAdminURLString, err := discovery.URL("gearman-admin", "http")
if err != nil {
    log.Fatal("ERROR: " + err.Error())
}

stokedHostPort, err := discovery.HostPort("stoked", "thrift")
if err != nil {
    logger.Fatal("ERROR: " + err.Error())
}

stokedHost, err := discovery.Host("stoked", "thrift")
if err != nil {
    logger.Fatal("ERROR: " + err.Error())
}

stokedPort, err := discovery.Port("stoked", "thrift")
if err != nil {
    logger.Fatal("ERROR: " + err.Error())
}

Implementation Details

Currently, discovery-{go,node,python} looks for environment variables with the following format:

SERVICE_{SERVICE_NAME}_{EXPOSE_NAME}_{PROTO,HOST,PORT}

These environment variables are autogenerated by fab and catapult during app deployment. Three env-vars are created for each app listed in the dependencies section of caller's launch yaml.

For example, if an app lists district-authorizations as a dependency, fab and catapult will generate this env-vars triplet:

SERVICE_DISTRICT_AUTHORIZATIONS_HTTP_PROTO = "http"
SERVICE_DISTRICT_AUTHORIZATIONS_HTTP_HOST = "district-authorizations.ops.clever.com"
SERVICE_DISTRICT_AUTHORIZATIONS_HTTP_PORT = "80"