quick out addPAth

This commit is contained in:
mr 2024-10-02 10:18:33 +02:00
parent 4ec32bafa7
commit f26249ab8b
3 changed files with 28 additions and 40 deletions

View File

@ -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

View File

@ -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"] != "<nil>")
if e, ok := m["error"]; ok && e != "<nil>" { // Check if there is an error in the response
return errors.New(fmt.Sprintf("%v", m["error"]))
}

View File

@ -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