From bfa17633390b7d7074bd584019e808eca4dd59a2 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 3 Jul 2024 11:45:14 +0300 Subject: add no servers configured error --- internal/easyhttp/easyhttp.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'internal/easyhttp/easyhttp.go') diff --git a/internal/easyhttp/easyhttp.go b/internal/easyhttp/easyhttp.go index bb963ad..7b72b9e 100644 --- a/internal/easyhttp/easyhttp.go +++ b/internal/easyhttp/easyhttp.go @@ -1,11 +1,11 @@ package easyhttp import ( - "errors" + "encoding/json" "fmt" "io" "net/http" - "encoding/json" + "sync" ) func Get(uri, apiKey string) ([]byte, error) { @@ -50,14 +50,18 @@ func PostData[T any](uri, apiKey string, data *T, servers ...string) error { if len(servers) == 0 { return fmt.Errorf("no server configured") } - var errs SafeErrors + var errs safErrors + var wg sync.WaitGroup for _, server := range servers { + wg.Add(1) go func(server string){ - errs.Append(postData[T](fmt.Sprintf("%s/%s"), apiKey, data)) + defer wg.Done() + errs.Append(postData[T](fmt.Sprintf("%s/%s", server, uri), apiKey, data)) }(server) } + wg.Wait() return errs.Join() } -- cgit v1.2.3