~ogham/doom

25ace0490c442dc8957f6d9114679a29f3f6e331 — Benjamin Sago 1 year, 7 months ago 96e8311 v0.6.5
More thorough Consul stacktraces
2 files changed, 15 insertions(+), 0 deletions(-)

M mconsul/kv.go
M mconsul/services.go
M mconsul/kv.go => mconsul/kv.go +7 -0
@@ 15,7 15,14 @@ import (
// and base64-decoding the Value field. Returns an error if there’s a network
// error or a problem with the response from Consul.
func FetchValueFromKvStore(key string) ([]byte, error) {
    result, err := fetchValueFromKvStore(key)
    if err != nil {
        err = fmt.Errorf("failed to fetch K/V value %q: %w", key, err)
    }
    return result, err
}

func fetchValueFromKvStore(key string) ([]byte, error) {
    // Construct the request
    endpoint := fmt.Sprintf("http://%s/v1/kv/%s", GlobalAddress, key)
    req, err := http.NewRequest("GET", endpoint, nil)

M mconsul/services.go => mconsul/services.go +8 -0
@@ 19,6 19,14 @@ type FoundService = string
// selects the closest service to the Consul agent. Returns an error if there’s a
// network error or a problem with the response.
func FetchServiceAddress(serviceName string) (*FoundService, error) {
    result, err := fetchServiceAddress(serviceName)
    if err != nil {
        err = fmt.Errorf("failed to fetch service %q: %w", serviceName, err)
    }
    return result, err
}

func fetchServiceAddress(serviceName string) (*FoundService, error) {

    // Construct the request
    endpoint := fmt.Sprintf("http://%s/v1/catalog/service/%s?near=_agent", GlobalAddress, serviceName)