Categorygithub.com/Clever/discovery-go
modulepackage
1.9.1
Repository: https://github.com/clever/discovery-go.git
Documentation: pkg.go.dev

# README

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())
}

cleverComURL, err := discovery.ExternalURL("clever.com")
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 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, 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"

It is also used to look for external urls with the format

EXTERNAL_URL_{URL_HOST}

For example for schools.clever.com catapult will set:

EXTERNAL_URL_SCHOOLS_CLEVER_COM = "https://schools.clever.com:443

# Functions

No description provided by the author
ExternalURL finds the specified URL based on the input URL.
Host finds the specified host for a service based off of the service's name and which interface you are accessing.
HostPort finds the specified host:port combo for a service based off of the service's name and which interface you are accessing.
Port finds the specified port for a service based off of the service's name and which interface you are accessing.
Proto finds the specified protocol for a service based off of the service's name and which interface you are accessing.
ProtoHost finds the specified proto:host combo for a service based off of the service's name and which interface you are accessing.
URL finds the specified URL for a service based off of the service's name and which interface you are accessing.