Documentation
¶
Overview ¶
Package azurearm provides shared HTTP wire-format helpers for Azure Resource Manager (ARM) JSON REST handlers.
ARM URLs share a common shape:
/subscriptions/{sub}/resourceGroups/{rg}/providers/{provider}/{type}/{name}
/subscriptions/{sub}/resourceGroups/{rg}/providers/{provider}/{type}
/subscriptions/{sub}/providers/{provider}/{type}
and an `api-version` query parameter is always present. Real ARM responses are JSON; errors carry an `error.code` / `error.message` envelope.
Index ¶
- Constants
- func BuildResourceID(subscription, resourceGroup, provider, resourceType, name string) string
- func DecodeJSON(w http.ResponseWriter, r *http.Request, v any) bool
- func WriteCErr(w http.ResponseWriter, err error)
- func WriteError(w http.ResponseWriter, status int, code, msg string)
- func WriteJSON(w http.ResponseWriter, status int, v any)
- type ResourcePath
Constants ¶
const ContentType = "application/json"
ContentType is the JSON content type used by all ARM responses.
const MaxBodyBytes = 1 << 20
MaxBodyBytes caps incoming JSON request bodies. Real ARM PUT requests for a VM are ~3 KB; 1 MiB is plenty of headroom.
Variables ¶
This section is empty.
Functions ¶
func BuildResourceID ¶
BuildResourceID constructs an ARM resource ID for the given path components. Used in response bodies so SDKs receive properly-shaped IDs.
func DecodeJSON ¶
DecodeJSON reads a JSON request body into v. Returns false (and writes a 400) on decode error.
func WriteCErr ¶
func WriteCErr(w http.ResponseWriter, err error)
WriteCErr maps a CloudEmu canonical error to the matching ARM HTTP status and code. Used by handlers so error mapping is consistent across services.
func WriteError ¶
func WriteError(w http.ResponseWriter, status int, code, msg string)
WriteError writes an ARM-style JSON error response.
Types ¶
type ResourcePath ¶
type ResourcePath struct {
Subscription string
ResourceGroup string
Provider string // e.g. "Microsoft.Compute"
ResourceType string // e.g. "virtualMachines" or "locations"
ResourceName string // empty for collection paths
SubResource string // e.g. "start", "powerOff", "operationStatuses"
SubResourceName string // e.g. operation GUID for .../operationStatuses/{id}
}
ResourcePath is a parsed ARM URL path. Fields are empty when not present in the path (e.g., a subscription-scoped list has no ResourceGroup).
func ParsePath ¶
func ParsePath(urlPath string) (ResourcePath, bool)
ParsePath extracts the ARM path components from urlPath. Returns ok=false when the path doesn't look like an ARM resource URL.
Recognized shapes:
/subscriptions/{sub}
/subscriptions/{sub}/resourceGroups/{rg}
/subscriptions/{sub}/providers/{prov}/{type}
/subscriptions/{sub}/resourceGroups/{rg}/providers/{prov}/{type}
/subscriptions/{sub}/resourceGroups/{rg}/providers/{prov}/{type}/{name}
/subscriptions/{sub}/resourceGroups/{rg}/providers/{prov}/{type}/{name}/{subResource}