diff --git a/entrypoint.go b/entrypoint.go index c5bcf16..48c17f2 100644 --- a/entrypoint.go +++ b/entrypoint.go @@ -79,24 +79,6 @@ type LibData struct { Err string `bson:"error" json:"error"` } -// here is the singleton variable to store the paths that api will use -var paths map[LibDataEnum]string = map[LibDataEnum]string{} - -// to get the paths -func GetPaths() map[LibDataEnum]string { - return paths -} - -// to get the path -func GetPath(collection LibDataEnum) string { - return paths[collection] -} - -// to add the path -func AddPath(collection LibDataEnum, path string) { - paths[collection] = path -} - func Init(appName string) { config.SetAppName(appName) // set the app name to the logger to define the main log chan // create a temporary console logger for init diff --git a/models/peer/peer_cache.go b/models/peer/peer_cache.go index f4742c2..6f8debc 100644 --- a/models/peer/peer_cache.go +++ b/models/peer/peer_cache.go @@ -88,7 +88,7 @@ func (p *PeerCache) LaunchPeerExecution(peerID string, dataID string, // If the peer is not reachable, add the execution to the failed executions list pexec := &PeerExecution{ Method: method.String(), - Url: p.urlFormat((mypeer.Url)+meth, dt), + Url: p.urlFormat((mypeer.Url)+"/"+dt.API()+meth, dt), Body: body, DataType: dt.EnumIndex(), DataID: dataID, @@ -98,11 +98,11 @@ func (p *PeerCache) LaunchPeerExecution(peerID string, dataID string, return nil, errors.New("peer is not reachable") } else { // If the peer is reachable, launch the execution - url = p.urlFormat((mypeer.Url)+meth, dt) // Format the URL - tmp := mypeer.FailedExecution // Get the failed executions list - mypeer.FailedExecution = []PeerExecution{} // Reset the failed executions list - mypeer.GetAccessor(nil).UpdateOne(mypeer, peerID) // Update the peer in the db - for _, v := range tmp { // Retry the failed executions + url = p.urlFormat((mypeer.Url)+"/"+dt.API()+meth, dt) // Format the URL + tmp := mypeer.FailedExecution // Get the failed executions list + mypeer.FailedExecution = []PeerExecution{} // Reset the failed executions list + mypeer.GetAccessor(nil).UpdateOne(mypeer, peerID) // Update the peer in the db + for _, v := range tmp { // Retry the failed executions go p.exec(v.Url, tools.ToMethod(v.Method), v.Body, caller) } } @@ -113,7 +113,6 @@ func (p *PeerCache) LaunchPeerExecution(peerID string, dataID string, func (p *PeerCache) exec(url string, method tools.METHOD, body map[string]interface{}, caller *tools.HTTPCaller) error { var b []byte var err error - fmt.Println("executing", url, method, body) if method == tools.POST { // Execute the POST method if it's a POST method b, err = caller.CallPost(url, "", body) } @@ -128,7 +127,6 @@ func (p *PeerCache) exec(url string, method tools.METHOD, body map[string]interf if err != nil { return err } - fmt.Println("response", m["error"], m["error"] != "") if e, ok := m["error"]; ok && e != "" { // Check if there is an error in the response return errors.New(fmt.Sprintf("%v", m["error"])) } diff --git a/models/utils/enums.go b/models/utils/enums.go index 3b32797..417feed 100644 --- a/models/utils/enums.go +++ b/models/utils/enums.go @@ -20,22 +20,30 @@ const ( BOOKING ) +var NOAPI = "" +var CATALOGAPI = "oc-catalog" +var SHAREDAPI = "oc-shared" +var WORKFLOWAPI = "oc-workflow" +var WORKSPACEAPI = "oc-workspace" +var PEERSAPI = "oc-peers" +var DATACENTERAPI = "oc-datacenter" + // Bind the standard API name to the data type var DefaultAPI = [...]string{ - "", - "oc-catalog", - "oc-catalog", - "oc-catalog", - "oc-catalog", - "oc-catalog", - "oc-workflow", - "", - "oc-workspace", - "", - "oc-peers", - "oc-shared", - "oc-shared", - "oc-datacenter", + NOAPI, + CATALOGAPI, + CATALOGAPI, + CATALOGAPI, + CATALOGAPI, + CATALOGAPI, + WORKFLOWAPI, + NOAPI, + WORKSPACEAPI, + NOAPI, + PEERSAPI, + SHAREDAPI, + SHAREDAPI, + DATACENTERAPI, } // Bind the standard data name to the data type