mirror of
https://github.com/valmojr/armatak.git
synced 2026-06-13 16:03:31 +00:00
added delete marker endpoint on dynamic library
This commit is contained in:
@@ -52,3 +52,37 @@ func armatak_controller_args_post_marker(
|
|||||||
|
|
||||||
return armatak_service_post_marker(args)
|
return armatak_service_post_marker(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func armatak_controller_post_marker_debug(
|
||||||
|
ctx a3interface.ArmaExtensionContext,
|
||||||
|
data string,
|
||||||
|
) (string, error) {
|
||||||
|
return invalidCallExtensionMethod("post marker requires args")
|
||||||
|
}
|
||||||
|
|
||||||
|
func armatak_controller_args_post_marker_debug(
|
||||||
|
ctx a3interface.ArmaExtensionContext,
|
||||||
|
command string,
|
||||||
|
args []string,
|
||||||
|
) (string, error) {
|
||||||
|
sanitazeArgs(args)
|
||||||
|
|
||||||
|
return armatak_service_post_marker(args)
|
||||||
|
}
|
||||||
|
|
||||||
|
func armatak_controller_delete_marker(
|
||||||
|
ctx a3interface.ArmaExtensionContext,
|
||||||
|
data string,
|
||||||
|
) (string, error) {
|
||||||
|
return invalidCallExtensionMethod("post marker requires args")
|
||||||
|
}
|
||||||
|
|
||||||
|
func armatak_controller_args_delete_marker(
|
||||||
|
ctx a3interface.ArmaExtensionContext,
|
||||||
|
command string,
|
||||||
|
args []string,
|
||||||
|
) (string, error) {
|
||||||
|
sanitazeArgs(args)
|
||||||
|
|
||||||
|
return armatak_service_delete_marker(args)
|
||||||
|
}
|
||||||
|
|||||||
@@ -26,16 +26,30 @@ func init() {
|
|||||||
Register()
|
Register()
|
||||||
|
|
||||||
a3interface.NewRegistration("get_auth_token").
|
a3interface.NewRegistration("get_auth_token").
|
||||||
SetDefaultResponse("getting uuid4").
|
SetDefaultResponse("getting auth token").
|
||||||
SetRunInBackground(false).
|
SetRunInBackground(false).
|
||||||
SetFunction(armatak_controller_get_auth_token).
|
SetFunction(armatak_controller_get_auth_token).
|
||||||
SetArgsFunction(armatak_controller_args_get_auth_token).
|
SetArgsFunction(armatak_controller_args_get_auth_token).
|
||||||
Register()
|
Register()
|
||||||
|
|
||||||
a3interface.NewRegistration("post_marker").
|
a3interface.NewRegistration("post_marker").
|
||||||
SetDefaultResponse("getting uuid4").
|
SetDefaultResponse("posting marker").
|
||||||
SetRunInBackground(true).
|
SetRunInBackground(true).
|
||||||
SetFunction(armatak_controller_post_marker).
|
SetFunction(armatak_controller_post_marker).
|
||||||
SetArgsFunction(armatak_controller_args_post_marker).
|
SetArgsFunction(armatak_controller_args_post_marker).
|
||||||
Register()
|
Register()
|
||||||
|
|
||||||
|
a3interface.NewRegistration("post_marker_debug").
|
||||||
|
SetDefaultResponse("posting marker (debug mode)").
|
||||||
|
SetRunInBackground(false).
|
||||||
|
SetFunction(armatak_controller_post_marker_debug).
|
||||||
|
SetArgsFunction(armatak_controller_args_post_marker_debug).
|
||||||
|
Register()
|
||||||
|
|
||||||
|
a3interface.NewRegistration("delete_marker").
|
||||||
|
SetDefaultResponse("deleting marker").
|
||||||
|
SetRunInBackground(false).
|
||||||
|
SetFunction(armatak_controller_delete_marker).
|
||||||
|
SetArgsFunction(armatak_controller_args_delete_marker).
|
||||||
|
Register()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,3 +59,19 @@ func armatak_service_post_marker(args []string) (string, error) {
|
|||||||
|
|
||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func armatak_service_delete_marker(args []string) (string, error) {
|
||||||
|
marker, markerError := parseMarkerArgs(args)
|
||||||
|
|
||||||
|
if markerError != nil {
|
||||||
|
return "", markerError
|
||||||
|
}
|
||||||
|
|
||||||
|
response, responseError := deleteRequest(args[8]+"/api/markers?auth_token="+args[9], marker)
|
||||||
|
|
||||||
|
if responseError != nil {
|
||||||
|
return "", responseError
|
||||||
|
}
|
||||||
|
|
||||||
|
return response, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -143,3 +143,41 @@ func postRequest(route string, body any) (string, error) {
|
|||||||
|
|
||||||
return string(parsedBody), nil
|
return string(parsedBody), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func deleteRequest(route string, body any) (string, error) {
|
||||||
|
jsonData, err := json.Marshal(body)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error marshalling payload:", err)
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
client := &http.Client{}
|
||||||
|
|
||||||
|
req, err := http.NewRequest(http.MethodDelete, route, bytes.NewReader(jsonData))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error creating request:", err)
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error sending request:", err)
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
fmt.Println("Error sending request:", resp.Status)
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
parsedBody, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("getting Error reading response body: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(parsedBody), nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user