quick out addPAth
This commit is contained in:
parent
4ec32bafa7
commit
f26249ab8b
@ -79,24 +79,6 @@ type LibData struct {
|
|||||||
Err string `bson:"error" json:"error"`
|
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) {
|
func Init(appName string) {
|
||||||
config.SetAppName(appName) // set the app name to the logger to define the main log chan
|
config.SetAppName(appName) // set the app name to the logger to define the main log chan
|
||||||
// create a temporary console logger for init
|
// create a temporary console logger for init
|
||||||
|
@ -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
|
// If the peer is not reachable, add the execution to the failed executions list
|
||||||
pexec := &PeerExecution{
|
pexec := &PeerExecution{
|
||||||
Method: method.String(),
|
Method: method.String(),
|
||||||
Url: p.urlFormat((mypeer.Url)+meth, dt),
|
Url: p.urlFormat((mypeer.Url)+"/"+dt.API()+meth, dt),
|
||||||
Body: body,
|
Body: body,
|
||||||
DataType: dt.EnumIndex(),
|
DataType: dt.EnumIndex(),
|
||||||
DataID: dataID,
|
DataID: dataID,
|
||||||
@ -98,11 +98,11 @@ func (p *PeerCache) LaunchPeerExecution(peerID string, dataID string,
|
|||||||
return nil, errors.New("peer is not reachable")
|
return nil, errors.New("peer is not reachable")
|
||||||
} else {
|
} else {
|
||||||
// If the peer is reachable, launch the execution
|
// If the peer is reachable, launch the execution
|
||||||
url = p.urlFormat((mypeer.Url)+meth, dt) // Format the URL
|
url = p.urlFormat((mypeer.Url)+"/"+dt.API()+meth, dt) // Format the URL
|
||||||
tmp := mypeer.FailedExecution // Get the failed executions list
|
tmp := mypeer.FailedExecution // Get the failed executions list
|
||||||
mypeer.FailedExecution = []PeerExecution{} // Reset the failed executions list
|
mypeer.FailedExecution = []PeerExecution{} // Reset the failed executions list
|
||||||
mypeer.GetAccessor(nil).UpdateOne(mypeer, peerID) // Update the peer in the db
|
mypeer.GetAccessor(nil).UpdateOne(mypeer, peerID) // Update the peer in the db
|
||||||
for _, v := range tmp { // Retry the failed executions
|
for _, v := range tmp { // Retry the failed executions
|
||||||
go p.exec(v.Url, tools.ToMethod(v.Method), v.Body, caller)
|
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 {
|
func (p *PeerCache) exec(url string, method tools.METHOD, body map[string]interface{}, caller *tools.HTTPCaller) error {
|
||||||
var b []byte
|
var b []byte
|
||||||
var err error
|
var err error
|
||||||
fmt.Println("executing", url, method, body)
|
|
||||||
if method == tools.POST { // Execute the POST method if it's a POST method
|
if method == tools.POST { // Execute the POST method if it's a POST method
|
||||||
b, err = caller.CallPost(url, "", body)
|
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 {
|
if err != nil {
|
||||||
return err
|
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
|
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"]))
|
return errors.New(fmt.Sprintf("%v", m["error"]))
|
||||||
}
|
}
|
||||||
|
@ -20,22 +20,30 @@ const (
|
|||||||
BOOKING
|
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
|
// Bind the standard API name to the data type
|
||||||
var DefaultAPI = [...]string{
|
var DefaultAPI = [...]string{
|
||||||
"",
|
NOAPI,
|
||||||
"oc-catalog",
|
CATALOGAPI,
|
||||||
"oc-catalog",
|
CATALOGAPI,
|
||||||
"oc-catalog",
|
CATALOGAPI,
|
||||||
"oc-catalog",
|
CATALOGAPI,
|
||||||
"oc-catalog",
|
CATALOGAPI,
|
||||||
"oc-workflow",
|
WORKFLOWAPI,
|
||||||
"",
|
NOAPI,
|
||||||
"oc-workspace",
|
WORKSPACEAPI,
|
||||||
"",
|
NOAPI,
|
||||||
"oc-peers",
|
PEERSAPI,
|
||||||
"oc-shared",
|
SHAREDAPI,
|
||||||
"oc-shared",
|
SHAREDAPI,
|
||||||
"oc-datacenter",
|
DATACENTERAPI,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bind the standard data name to the data type
|
// Bind the standard data name to the data type
|
||||||
|
Loading…
Reference in New Issue
Block a user