Improve LaunchPeerExecution() URL's parameters handling #11

Open
opened 2025-03-13 12:26:47 +01:00 by pb · 0 comments
Owner

We are currently only replacing the value of ":id" in the method, limiting the number of parameters in a URL, which could be very limiting in the future :

func (p *PeerCache) LaunchPeerExecution(peerID string, dataID string,
	dt tools.DataType, method tools.METHOD, body interface{}, caller *tools.HTTPCaller) (*PeerExecution, error) {
	fmt.Println("Launching peer execution on", caller.URLS, dt, method)
	methods := caller.URLS[dt] // Get the methods url of the data type
	if m, ok := methods[method]; !ok || m == "" {
		return nil, errors.New("Requested method " + method.String() + " not declared in HTTPCaller")
	}
	path := methods[method]                        // Get the path corresponding to the action we want to execute
	path = strings.ReplaceAll(path, ":id", dataID) // Replace the id in the path in case of a DELETE / UPDATE method (it's a standard naming in OC)
	url := ""
...
}

Maybe we could pass the method a map[string]string of the parameters and the value we want to give them.

We are currently only replacing the value of ":id" in the method, limiting the number of parameters in a URL, which could be very limiting in the future : ``` func (p *PeerCache) LaunchPeerExecution(peerID string, dataID string, dt tools.DataType, method tools.METHOD, body interface{}, caller *tools.HTTPCaller) (*PeerExecution, error) { fmt.Println("Launching peer execution on", caller.URLS, dt, method) methods := caller.URLS[dt] // Get the methods url of the data type if m, ok := methods[method]; !ok || m == "" { return nil, errors.New("Requested method " + method.String() + " not declared in HTTPCaller") } path := methods[method] // Get the path corresponding to the action we want to execute path = strings.ReplaceAll(path, ":id", dataID) // Replace the id in the path in case of a DELETE / UPDATE method (it's a standard naming in OC) url := "" ... } ``` Maybe we could pass the method a map[string]string of the parameters and the value we want to give them.
pb added the
Kind/Feature
Priority/Medium
labels 2025-03-13 12:26:47 +01:00
pb self-assigned this 2025-03-13 12:26:47 +01:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: core/oc-lib#11
No description provided.