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)