From 5f4fc1e1c2153519715e88a07de6a9e34dfd1cea Mon Sep 17 00:00:00 2001 From: Nandan Sridhar Date: Tue, 6 Aug 2019 13:00:23 -0700 Subject: [PATCH] refactor getasyncentity --- cmd/apps/expapp/expapp.go | 6 ++++-- cmd/products/expprod/expprod.go | 4 +++- cmd/shared/shared.go | 12 ++++++------ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/cmd/apps/expapp/expapp.go b/cmd/apps/expapp/expapp.go index 6ad6926c..9fbfec1b 100644 --- a/cmd/apps/expapp/expapp.go +++ b/cmd/apps/expapp/expapp.go @@ -42,7 +42,7 @@ func init() { } -//batch created a batch of products to query +//batch created a batch of apps to query func batch(entities []app, entityType string, pwg *sync.WaitGroup, mu *sync.Mutex) { defer pwg.Done() @@ -52,7 +52,9 @@ func batch(entities []app, entityType string, pwg *sync.WaitGroup, mu *sync.Mute bwg.Add(len(entities)) for _, entity := range entities { - go shared.GetAsyncEntity(entity.AppID, entityType, &bwg, mu) + u, _ := url.Parse(shared.BaseURL) + u.Path = path.Join(u.Path, shared.RootArgs.Org, entityType, entity.AppID) + go shared.GetAsyncEntity(u.String(), &bwg, mu) } bwg.Wait() } diff --git a/cmd/products/expprod/expprod.go b/cmd/products/expprod/expprod.go index 4b5ae1e9..4f409819 100644 --- a/cmd/products/expprod/expprod.go +++ b/cmd/products/expprod/expprod.go @@ -52,7 +52,9 @@ func batch(entities []apiProduct, entityType string, pwg *sync.WaitGroup, mu *sy bwg.Add(len(entities)) for _, entity := range entities { - go shared.GetAsyncEntity(url.PathEscape(entity.Name), entityType, &bwg, mu) + u, _ := url.Parse(shared.BaseURL) + u.Path = path.Join(u.Path, shared.RootArgs.Org, entityType, url.PathEscape(entity.Name)) + go shared.GetAsyncEntity(u.String(), &bwg, mu) } bwg.Wait() } diff --git a/cmd/shared/shared.go b/cmd/shared/shared.go index 15d86cc8..4945889b 100644 --- a/cmd/shared/shared.go +++ b/cmd/shared/shared.go @@ -537,19 +537,19 @@ func WriteByteArrayToFile(exportFile string, fileAppend bool, payload []byte) er } //GetAsync stores results for each entity in a list -func GetAsyncEntity(entityName string, entityType string, wg *sync.WaitGroup, mu *sync.Mutex) { +func GetAsyncEntity(entityURL string, wg *sync.WaitGroup, mu *sync.Mutex) { //this is a two step process - 1) get entity details 2) store in byte[][] defer wg.Done() var respBody []byte - u, _ := url.Parse(BaseURL) - u.Path = path.Join(u.Path, RootArgs.Org, entityType, entityName) + //u, _ := url.Parse(BaseURL) + //u.Path = path.Join(u.Path, RootArgs.Org, entityType, entityName) //don't print to sysout - respBody, err := HttpClient(false, u.String()) + respBody, err := HttpClient(false, entityURL) if err != nil { - Error.Fatalln("Error with entity: %s", entityName) + Error.Fatalln("Error with entity: %s", entityURL) Error.Fatalln(err) return } @@ -557,7 +557,7 @@ func GetAsyncEntity(entityName string, entityType string, wg *sync.WaitGroup, mu mu.Lock() EntityPayloadList = append(EntityPayloadList, respBody) mu.Unlock() - Info.Printf("Completed entity: %s", entityName) + Info.Printf("Completed entity: %s", entityURL) } //FetchAyncBundle can download a shared flow or a proxy bundle