droboticflow/scripts/lib/service-endpoints.sh
2026-06-17 03:27:03 +08:00

43 lines
933 B
Bash

#!/usr/bin/env bash
droboticflow_trim_trailing_slash() {
local value="${1:-}"
while [[ "$value" == */ ]]; do
value="${value%/}"
done
printf '%s\n' "$value"
}
droboticflow_require_http_service_url() {
local raw="${1:-}"
local value
value="$(droboticflow_trim_trailing_slash "$raw")"
if [[ -z "$raw" ]]; then
printf '%s\n' ""
return 0
fi
if [[ -z "$value" || ! "$value" =~ ^https?://[^[:space:]]+$ ]]; then
printf 'ERROR: service URL must be an absolute http(s) URL: %s\n' "$raw" >&2
return 2
fi
printf '%s\n' "$value"
}
droboticflow_first_service_url() {
local candidate
for candidate in "$@"; do
if [[ -n "$candidate" ]]; then
droboticflow_require_http_service_url "$candidate"
return
fi
done
}
droboticflow_default_api_base_url() {
printf '%s\n' "http://127.0.0.1:3001"
}
droboticflow_default_worker_base_url() {
printf '%s\n' "http://127.0.0.1:3002"
}