1127 lines
39 KiB
Go
1127 lines
39 KiB
Go
//go:build go1.22
|
|
|
|
// Package controlapi provides primitives to interact with the openapi HTTP API.
|
|
//
|
|
// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.8.0 DO NOT EDIT.
|
|
package controlapi
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/oapi-codegen/runtime"
|
|
)
|
|
|
|
// Defines values for ActualState.
|
|
const (
|
|
ActualStateFailed ActualState = "failed"
|
|
ActualStateOffline ActualState = "offline"
|
|
ActualStateOnline ActualState = "online"
|
|
ActualStatePending ActualState = "pending"
|
|
)
|
|
|
|
// Valid indicates whether the value is a known member of the ActualState enum.
|
|
func (e ActualState) Valid() bool {
|
|
switch e {
|
|
case ActualStateFailed:
|
|
return true
|
|
case ActualStateOffline:
|
|
return true
|
|
case ActualStateOnline:
|
|
return true
|
|
case ActualStatePending:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
// Defines values for AdapterStatus.
|
|
const (
|
|
AdapterStatusAdapterNotReady AdapterStatus = "adapter_not_ready"
|
|
AdapterStatusAuthenticationFailed AdapterStatus = "authentication_failed"
|
|
AdapterStatusPending AdapterStatus = "pending"
|
|
AdapterStatusReady AdapterStatus = "ready"
|
|
AdapterStatusUnavailable AdapterStatus = "unavailable"
|
|
)
|
|
|
|
// Valid indicates whether the value is a known member of the AdapterStatus enum.
|
|
func (e AdapterStatus) Valid() bool {
|
|
switch e {
|
|
case AdapterStatusAdapterNotReady:
|
|
return true
|
|
case AdapterStatusAuthenticationFailed:
|
|
return true
|
|
case AdapterStatusPending:
|
|
return true
|
|
case AdapterStatusReady:
|
|
return true
|
|
case AdapterStatusUnavailable:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
// Defines values for BatchItemResultStatus.
|
|
const (
|
|
BatchItemResultStatusAccepted BatchItemResultStatus = "accepted"
|
|
BatchItemResultStatusFailed BatchItemResultStatus = "failed"
|
|
BatchItemResultStatusRejected BatchItemResultStatus = "rejected"
|
|
BatchItemResultStatusSucceeded BatchItemResultStatus = "succeeded"
|
|
)
|
|
|
|
// Valid indicates whether the value is a known member of the BatchItemResultStatus enum.
|
|
func (e BatchItemResultStatus) Valid() bool {
|
|
switch e {
|
|
case BatchItemResultStatusAccepted:
|
|
return true
|
|
case BatchItemResultStatusFailed:
|
|
return true
|
|
case BatchItemResultStatusRejected:
|
|
return true
|
|
case BatchItemResultStatusSucceeded:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
// Defines values for BatchOperationStatus.
|
|
const (
|
|
BatchOperationStatusFailed BatchOperationStatus = "failed"
|
|
BatchOperationStatusPartiallySucceeded BatchOperationStatus = "partially_succeeded"
|
|
BatchOperationStatusQueued BatchOperationStatus = "queued"
|
|
BatchOperationStatusRunning BatchOperationStatus = "running"
|
|
BatchOperationStatusSucceeded BatchOperationStatus = "succeeded"
|
|
)
|
|
|
|
// Valid indicates whether the value is a known member of the BatchOperationStatus enum.
|
|
func (e BatchOperationStatus) Valid() bool {
|
|
switch e {
|
|
case BatchOperationStatusFailed:
|
|
return true
|
|
case BatchOperationStatusPartiallySucceeded:
|
|
return true
|
|
case BatchOperationStatusQueued:
|
|
return true
|
|
case BatchOperationStatusRunning:
|
|
return true
|
|
case BatchOperationStatusSucceeded:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
// Defines values for Capability.
|
|
const (
|
|
AudioCapture Capability = "audio_capture"
|
|
SpatialRule Capability = "spatial_rule"
|
|
Telemetry Capability = "telemetry"
|
|
VideoCapture Capability = "video_capture"
|
|
)
|
|
|
|
// Valid indicates whether the value is a known member of the Capability enum.
|
|
func (e Capability) Valid() bool {
|
|
switch e {
|
|
case AudioCapture:
|
|
return true
|
|
case SpatialRule:
|
|
return true
|
|
case Telemetry:
|
|
return true
|
|
case VideoCapture:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
// Defines values for DesiredState.
|
|
const (
|
|
Disabled DesiredState = "disabled"
|
|
Enabled DesiredState = "enabled"
|
|
)
|
|
|
|
// Valid indicates whether the value is a known member of the DesiredState enum.
|
|
func (e DesiredState) Valid() bool {
|
|
switch e {
|
|
case Disabled:
|
|
return true
|
|
case Enabled:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
// Defines values for ErrorCode.
|
|
const (
|
|
ErrorCodeAdapterNotReady ErrorCode = "adapter_not_ready"
|
|
ErrorCodeAreaPolicyDenied ErrorCode = "area_policy_denied"
|
|
ErrorCodeAreaPolicyUnavailable ErrorCode = "area_policy_unavailable"
|
|
ErrorCodeAuthenticationFailed ErrorCode = "authentication_failed"
|
|
ErrorCodeBatchTooLarge ErrorCode = "batch_too_large"
|
|
ErrorCodeConflict ErrorCode = "conflict"
|
|
ErrorCodeDuplicateSerialNumber ErrorCode = "duplicate_serial_number"
|
|
ErrorCodeEndpointCredentialsForbidden ErrorCode = "endpoint_credentials_forbidden"
|
|
ErrorCodeEtagMismatch ErrorCode = "etag_mismatch"
|
|
ErrorCodeForbidden ErrorCode = "forbidden"
|
|
ErrorCodeIdempotencyConflict ErrorCode = "idempotency_conflict"
|
|
ErrorCodeInternalError ErrorCode = "internal_error"
|
|
ErrorCodeInvalidRequest ErrorCode = "invalid_request"
|
|
ErrorCodeNotFound ErrorCode = "not_found"
|
|
ErrorCodePreconditionRequired ErrorCode = "precondition_required"
|
|
ErrorCodeQuotaExceeded ErrorCode = "quota_exceeded"
|
|
ErrorCodeQuotaProjectionInvalid ErrorCode = "quota_projection_invalid"
|
|
ErrorCodeQuotaProjectionUnavailable ErrorCode = "quota_projection_unavailable"
|
|
ErrorCodeServiceUnavailable ErrorCode = "service_unavailable"
|
|
ErrorCodeUnauthenticated ErrorCode = "unauthenticated"
|
|
)
|
|
|
|
// Valid indicates whether the value is a known member of the ErrorCode enum.
|
|
func (e ErrorCode) Valid() bool {
|
|
switch e {
|
|
case ErrorCodeAdapterNotReady:
|
|
return true
|
|
case ErrorCodeAreaPolicyDenied:
|
|
return true
|
|
case ErrorCodeAreaPolicyUnavailable:
|
|
return true
|
|
case ErrorCodeAuthenticationFailed:
|
|
return true
|
|
case ErrorCodeBatchTooLarge:
|
|
return true
|
|
case ErrorCodeConflict:
|
|
return true
|
|
case ErrorCodeDuplicateSerialNumber:
|
|
return true
|
|
case ErrorCodeEndpointCredentialsForbidden:
|
|
return true
|
|
case ErrorCodeEtagMismatch:
|
|
return true
|
|
case ErrorCodeForbidden:
|
|
return true
|
|
case ErrorCodeIdempotencyConflict:
|
|
return true
|
|
case ErrorCodeInternalError:
|
|
return true
|
|
case ErrorCodeInvalidRequest:
|
|
return true
|
|
case ErrorCodeNotFound:
|
|
return true
|
|
case ErrorCodePreconditionRequired:
|
|
return true
|
|
case ErrorCodeQuotaExceeded:
|
|
return true
|
|
case ErrorCodeQuotaProjectionInvalid:
|
|
return true
|
|
case ErrorCodeQuotaProjectionUnavailable:
|
|
return true
|
|
case ErrorCodeServiceUnavailable:
|
|
return true
|
|
case ErrorCodeUnauthenticated:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
// Defines values for Modality.
|
|
const (
|
|
Button Modality = "button"
|
|
Contact Modality = "contact"
|
|
Other Modality = "other"
|
|
Radar Modality = "radar"
|
|
Video Modality = "video"
|
|
Wearable Modality = "wearable"
|
|
)
|
|
|
|
// Valid indicates whether the value is a known member of the Modality enum.
|
|
func (e Modality) Valid() bool {
|
|
switch e {
|
|
case Button:
|
|
return true
|
|
case Contact:
|
|
return true
|
|
case Other:
|
|
return true
|
|
case Radar:
|
|
return true
|
|
case Video:
|
|
return true
|
|
case Wearable:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
// Defines values for SiteQuotaStatusStatus.
|
|
const (
|
|
SiteQuotaStatusStatusCurrent SiteQuotaStatusStatus = "current"
|
|
SiteQuotaStatusStatusInvalid SiteQuotaStatusStatus = "invalid"
|
|
SiteQuotaStatusStatusUnavailable SiteQuotaStatusStatus = "unavailable"
|
|
)
|
|
|
|
// Valid indicates whether the value is a known member of the SiteQuotaStatusStatus enum.
|
|
func (e SiteQuotaStatusStatus) Valid() bool {
|
|
switch e {
|
|
case SiteQuotaStatusStatusCurrent:
|
|
return true
|
|
case SiteQuotaStatusStatusInvalid:
|
|
return true
|
|
case SiteQuotaStatusStatusUnavailable:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
// ActualState defines model for ActualState.
|
|
type ActualState string
|
|
|
|
// AdapterStatus defines model for AdapterStatus.
|
|
type AdapterStatus string
|
|
|
|
// BatchDesiredStateItem defines model for BatchDesiredStateItem.
|
|
type BatchDesiredStateItem struct {
|
|
DesiredState DesiredState `json:"desired_state"`
|
|
DeviceId LogicalID `json:"device_id"`
|
|
Etag string `json:"etag"`
|
|
}
|
|
|
|
// BatchDesiredStateRequest defines model for BatchDesiredStateRequest.
|
|
type BatchDesiredStateRequest struct {
|
|
Items []BatchDesiredStateItem `json:"items"`
|
|
Reason string `json:"reason"`
|
|
}
|
|
|
|
// BatchItemResult defines model for BatchItemResult.
|
|
type BatchItemResult struct {
|
|
DeviceId LogicalID `json:"device_id"`
|
|
ErrorCode *ErrorCode `json:"error_code"`
|
|
Generation *int64 `json:"generation"`
|
|
Message *string `json:"message"`
|
|
Status BatchItemResultStatus `json:"status"`
|
|
}
|
|
|
|
// BatchItemResultStatus defines model for BatchItemResult.Status.
|
|
type BatchItemResultStatus string
|
|
|
|
// BatchOperation defines model for BatchOperation.
|
|
type BatchOperation struct {
|
|
CompletedAt *time.Time `json:"completed_at"`
|
|
Id string `json:"id"`
|
|
Results []BatchItemResult `json:"results"`
|
|
Status BatchOperationStatus `json:"status"`
|
|
SubmittedAt time.Time `json:"submitted_at"`
|
|
TraceId string `json:"trace_id"`
|
|
}
|
|
|
|
// BatchOperationStatus defines model for BatchOperation.Status.
|
|
type BatchOperationStatus string
|
|
|
|
// Capability defines model for Capability.
|
|
type Capability string
|
|
|
|
// DesiredState defines model for DesiredState.
|
|
type DesiredState string
|
|
|
|
// DesiredStateChange defines model for DesiredStateChange.
|
|
type DesiredStateChange struct {
|
|
DesiredState DesiredState `json:"desired_state"`
|
|
Reason string `json:"reason"`
|
|
}
|
|
|
|
// Device defines model for Device.
|
|
type Device struct {
|
|
ActualState ActualState `json:"actual_state"`
|
|
AdapterStatus AdapterStatus `json:"adapter_status"`
|
|
AreaId LogicalID `json:"area_id"`
|
|
Capabilities *[]Capability `json:"capabilities,omitempty"`
|
|
|
|
// Converged 期望代已被观察且当前无待重试;不等价于所有外部系统健康。
|
|
Converged *bool `json:"converged,omitempty"`
|
|
CreatedAt *time.Time `json:"created_at,omitempty"`
|
|
CredentialConfigured *bool `json:"credential_configured,omitempty"`
|
|
DesiredState DesiredState `json:"desired_state"`
|
|
EndpointConfigured *bool `json:"endpoint_configured,omitempty"`
|
|
FailureCount *int `json:"failure_count,omitempty"`
|
|
Generation *int64 `json:"generation,omitempty"`
|
|
Id LogicalID `json:"id"`
|
|
LastErrorCode *string `json:"last_error_code,omitempty"`
|
|
Modality Modality `json:"modality"`
|
|
Name string `json:"name"`
|
|
NextAttemptAt *time.Time `json:"next_attempt_at,omitempty"`
|
|
ObservedGeneration *int64 `json:"observed_generation,omitempty"`
|
|
ProjectionVersions ProjectionVersions `json:"projection_versions"`
|
|
SerialNumber string `json:"serial_number"`
|
|
SiteId LogicalID `json:"site_id"`
|
|
|
|
// TenantId 只用于回显已授权上下文,不得由客户端写入。
|
|
TenantId *LogicalID `json:"tenant_id,omitempty"`
|
|
UpdatedAt *time.Time `json:"updated_at,omitempty"`
|
|
}
|
|
|
|
// DeviceCreate defines model for DeviceCreate.
|
|
type DeviceCreate struct {
|
|
AreaId LogicalID `json:"area_id"`
|
|
|
|
// Capabilities 请求接入的能力集合;适配器探测不支持时以稳定错误拒绝或标记 adapter_not_ready。
|
|
Capabilities []Capability `json:"capabilities"`
|
|
|
|
// CredentialRef 不透明密钥引用,不是用户名、密码或 token。
|
|
CredentialRef *string `json:"credential_ref,omitempty"`
|
|
DesiredState *DesiredState `json:"desired_state,omitempty"`
|
|
|
|
// EndpointRef 绝对 URI,禁止 userinfo;只在受控写路径使用。
|
|
EndpointRef *string `json:"endpoint_ref,omitempty"`
|
|
Modality Modality `json:"modality"`
|
|
Name string `json:"name"`
|
|
ProfileToken *string `json:"profile_token,omitempty"`
|
|
SerialNumber string `json:"serial_number"`
|
|
}
|
|
|
|
// DevicePage defines model for DevicePage.
|
|
type DevicePage struct {
|
|
Items []Device `json:"items"`
|
|
Page PageInfo `json:"page"`
|
|
Quota SiteQuotaStatus `json:"quota"`
|
|
}
|
|
|
|
// DevicePatch defines model for DevicePatch.
|
|
type DevicePatch struct {
|
|
AreaId *LogicalID `json:"area_id,omitempty"`
|
|
CredentialRef *string `json:"credential_ref,omitempty"`
|
|
|
|
// EndpointRef 绝对 URI,禁止 userinfo。
|
|
EndpointRef *string `json:"endpoint_ref,omitempty"`
|
|
Name *string `json:"name,omitempty"`
|
|
ProfileToken *string `json:"profile_token,omitempty"`
|
|
}
|
|
|
|
// ErrorCode defines model for ErrorCode.
|
|
type ErrorCode string
|
|
|
|
// FieldError defines model for FieldError.
|
|
type FieldError struct {
|
|
Code string `json:"code"`
|
|
Field string `json:"field"`
|
|
Message string `json:"message"`
|
|
}
|
|
|
|
// LogicalID defines model for LogicalID.
|
|
type LogicalID = string
|
|
|
|
// Modality defines model for Modality.
|
|
type Modality string
|
|
|
|
// MutationReceipt defines model for MutationReceipt.
|
|
type MutationReceipt struct {
|
|
AcceptedAt time.Time `json:"accepted_at"`
|
|
Device Device `json:"device"`
|
|
TraceId string `json:"trace_id"`
|
|
}
|
|
|
|
// PageInfo defines model for PageInfo.
|
|
type PageInfo struct {
|
|
HasMore bool `json:"has_more"`
|
|
Limit int `json:"limit"`
|
|
NextCursor *string `json:"next_cursor"`
|
|
}
|
|
|
|
// Problem defines model for Problem.
|
|
type Problem struct {
|
|
Code ErrorCode `json:"code"`
|
|
FieldErrors []FieldError `json:"field_errors"`
|
|
Message string `json:"message"`
|
|
Status int `json:"status"`
|
|
Title string `json:"title"`
|
|
TraceId string `json:"trace_id"`
|
|
Type string `json:"type"`
|
|
}
|
|
|
|
// ProjectionVersions defines model for ProjectionVersions.
|
|
type ProjectionVersions struct {
|
|
AreaPolicySourceVersion *int64 `json:"area_policy_source_version,omitempty"`
|
|
QuotaSourceVersion *int64 `json:"quota_source_version,omitempty"`
|
|
SyncedAt *time.Time `json:"synced_at,omitempty"`
|
|
}
|
|
|
|
// SiteQuotaStatus defines model for SiteQuotaStatus.
|
|
type SiteQuotaStatus struct {
|
|
AvailableVideoChannels *int `json:"available_video_channels"`
|
|
MaxVideoChannels *int `json:"max_video_channels"`
|
|
OverLimit bool `json:"over_limit"`
|
|
SourceVersion *int64 `json:"source_version"`
|
|
Status SiteQuotaStatusStatus `json:"status"`
|
|
SyncedAt *time.Time `json:"synced_at"`
|
|
UsedVideoChannels int `json:"used_video_channels"`
|
|
}
|
|
|
|
// SiteQuotaStatusStatus defines model for SiteQuotaStatus.Status.
|
|
type SiteQuotaStatusStatus string
|
|
|
|
// ActualStateFilter defines model for ActualStateFilter.
|
|
type ActualStateFilter = ActualState
|
|
|
|
// CapabilityFilter defines model for CapabilityFilter.
|
|
type CapabilityFilter = Capability
|
|
|
|
// Cursor defines model for Cursor.
|
|
type Cursor = string
|
|
|
|
// DesiredStateFilter defines model for DesiredStateFilter.
|
|
type DesiredStateFilter = DesiredState
|
|
|
|
// DeviceID defines model for DeviceID.
|
|
type DeviceID = LogicalID
|
|
|
|
// IdempotencyKey defines model for IdempotencyKey.
|
|
type IdempotencyKey = string
|
|
|
|
// IfMatch defines model for IfMatch.
|
|
type IfMatch = string
|
|
|
|
// Limit defines model for Limit.
|
|
type Limit = int
|
|
|
|
// ModalityFilter defines model for ModalityFilter.
|
|
type ModalityFilter = Modality
|
|
|
|
// OperationID defines model for OperationID.
|
|
type OperationID = string
|
|
|
|
// SiteID defines model for SiteID.
|
|
type SiteID = LogicalID
|
|
|
|
// AcceptedMutation defines model for AcceptedMutation.
|
|
type AcceptedMutation = MutationReceipt
|
|
|
|
// CreatedDevice defines model for CreatedDevice.
|
|
type CreatedDevice = Device
|
|
|
|
// CurrentDevice defines model for CurrentDevice.
|
|
type CurrentDevice = Device
|
|
|
|
// ErrorResponse defines model for ErrorResponse.
|
|
type ErrorResponse = Problem
|
|
|
|
// ListDevicesParams defines parameters for ListDevices.
|
|
type ListDevicesParams struct {
|
|
// Cursor 不透明游标;客户端不得解析或构造
|
|
Cursor *Cursor `form:"cursor,omitempty" json:"cursor,omitempty"`
|
|
Limit *Limit `form:"limit,omitempty" json:"limit,omitempty"`
|
|
Modality *ModalityFilter `form:"modality,omitempty" json:"modality,omitempty"`
|
|
Capability *CapabilityFilter `form:"capability,omitempty" json:"capability,omitempty"`
|
|
DesiredState *DesiredStateFilter `form:"desired_state,omitempty" json:"desired_state,omitempty"`
|
|
ActualState *ActualStateFilter `form:"actual_state,omitempty" json:"actual_state,omitempty"`
|
|
}
|
|
|
|
// CreateDeviceParams defines parameters for CreateDevice.
|
|
type CreateDeviceParams struct {
|
|
// IdempotencyKey 同一认证主体、站点、operationId、key 和规范化 body 在 24 小时内返回同一结果;key 相同而 body 不同返回 idempotency_conflict。
|
|
IdempotencyKey IdempotencyKey `json:"Idempotency-Key"`
|
|
}
|
|
|
|
// UpdateDeviceParams defines parameters for UpdateDevice.
|
|
type UpdateDeviceParams struct {
|
|
// IfMatch 使用最近一次 GET/写响应的 opaque ETag;不匹配返回 412 etag_mismatch。
|
|
IfMatch IfMatch `json:"If-Match"`
|
|
}
|
|
|
|
// SetDeviceDesiredStateParams defines parameters for SetDeviceDesiredState.
|
|
type SetDeviceDesiredStateParams struct {
|
|
// IfMatch 使用最近一次 GET/写响应的 opaque ETag;不匹配返回 412 etag_mismatch。
|
|
IfMatch IfMatch `json:"If-Match"`
|
|
}
|
|
|
|
// BatchSetDeviceDesiredStateParams defines parameters for BatchSetDeviceDesiredState.
|
|
type BatchSetDeviceDesiredStateParams struct {
|
|
// IdempotencyKey 同一认证主体、站点、operationId、key 和规范化 body 在 24 小时内返回同一结果;key 相同而 body 不同返回 idempotency_conflict。
|
|
IdempotencyKey IdempotencyKey `json:"Idempotency-Key"`
|
|
}
|
|
|
|
// CreateDeviceJSONRequestBody defines body for CreateDevice for application/json ContentType.
|
|
type CreateDeviceJSONRequestBody = DeviceCreate
|
|
|
|
// UpdateDeviceApplicationMergePatchPlusJSONRequestBody defines body for UpdateDevice for application/merge-patch+json ContentType.
|
|
type UpdateDeviceApplicationMergePatchPlusJSONRequestBody = DevicePatch
|
|
|
|
// SetDeviceDesiredStateJSONRequestBody defines body for SetDeviceDesiredState for application/json ContentType.
|
|
type SetDeviceDesiredStateJSONRequestBody = DesiredStateChange
|
|
|
|
// BatchSetDeviceDesiredStateJSONRequestBody defines body for BatchSetDeviceDesiredState for application/json ContentType.
|
|
type BatchSetDeviceDesiredStateJSONRequestBody = BatchDesiredStateRequest
|
|
|
|
// ServerInterface represents all server handlers.
|
|
type ServerInterface interface {
|
|
// GetOperation 查询批量写入和逐项结果
|
|
// (GET /api/v1/operations/{operation_id})
|
|
GetOperation(w http.ResponseWriter, r *http.Request, operationId OperationID)
|
|
// ListDevices 分页查询当前认证租户下的站点设备
|
|
// (GET /api/v1/sites/{site_id}/devices)
|
|
ListDevices(w http.ResponseWriter, r *http.Request, siteId SiteID, params ListDevicesParams)
|
|
// CreateDevice 创建待探测设备
|
|
// (POST /api/v1/sites/{site_id}/devices)
|
|
CreateDevice(w http.ResponseWriter, r *http.Request, siteId SiteID, params CreateDeviceParams)
|
|
// GetDevice 读取设备期望态、实际态和收敛进度
|
|
// (GET /api/v1/sites/{site_id}/devices/{device_id})
|
|
GetDevice(w http.ResponseWriter, r *http.Request, siteId SiteID, deviceId DeviceID)
|
|
// UpdateDevice 按 ETag 修改设备可编辑配置
|
|
// (PATCH /api/v1/sites/{site_id}/devices/{device_id})
|
|
UpdateDevice(w http.ResponseWriter, r *http.Request, siteId SiteID, deviceId DeviceID, params UpdateDeviceParams)
|
|
// SetDeviceDesiredState 启用或停用设备接入期望态
|
|
// (PUT /api/v1/sites/{site_id}/devices/{device_id}/desired-state)
|
|
SetDeviceDesiredState(w http.ResponseWriter, r *http.Request, siteId SiteID, deviceId DeviceID, params SetDeviceDesiredStateParams)
|
|
// BatchSetDeviceDesiredState 批量提交最多 128 个设备期望态变更
|
|
// (POST /api/v1/sites/{site_id}/devices:batchDesiredState)
|
|
BatchSetDeviceDesiredState(w http.ResponseWriter, r *http.Request, siteId SiteID, params BatchSetDeviceDesiredStateParams)
|
|
}
|
|
|
|
// ServerInterfaceWrapper converts contexts to parameters.
|
|
type ServerInterfaceWrapper struct {
|
|
Handler ServerInterface
|
|
HandlerMiddlewares []MiddlewareFunc
|
|
ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
|
|
}
|
|
|
|
type MiddlewareFunc func(http.Handler) http.Handler
|
|
|
|
// GetOperation operation middleware
|
|
func (siw *ServerInterfaceWrapper) GetOperation(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var err error
|
|
_ = err
|
|
|
|
// ------------- Path parameter "operation_id" -------------
|
|
var operationId OperationID
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "operation_id", r.PathValue("operation_id"), &operationId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true, Type: "string", Format: "", ValueIsUnescaped: true})
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "operation_id", Err: err})
|
|
return
|
|
}
|
|
|
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.GetOperation(w, r, operationId)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
// ListDevices operation middleware
|
|
func (siw *ServerInterfaceWrapper) ListDevices(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var err error
|
|
_ = err
|
|
|
|
// ------------- Path parameter "site_id" -------------
|
|
var siteId SiteID
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "site_id", r.PathValue("site_id"), &siteId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true, Type: "string", Format: "", ValueIsUnescaped: true})
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "site_id", Err: err})
|
|
return
|
|
}
|
|
|
|
// Parameter object where we will unmarshal all parameters from the context
|
|
var params ListDevicesParams
|
|
|
|
// ------------- Optional query parameter "cursor" -------------
|
|
|
|
err = runtime.BindQueryParameterWithOptions("form", true, false, "cursor", r.URL.Query(), ¶ms.Cursor, runtime.BindQueryParameterOptions{Type: "string", Format: ""})
|
|
if err != nil {
|
|
var requiredError *runtime.RequiredParameterError
|
|
if errors.As(err, &requiredError) {
|
|
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "cursor"})
|
|
} else {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "cursor", Err: err})
|
|
}
|
|
return
|
|
}
|
|
|
|
// ------------- Optional query parameter "limit" -------------
|
|
|
|
err = runtime.BindQueryParameterWithOptions("form", true, false, "limit", r.URL.Query(), ¶ms.Limit, runtime.BindQueryParameterOptions{Type: "integer", Format: ""})
|
|
if err != nil {
|
|
var requiredError *runtime.RequiredParameterError
|
|
if errors.As(err, &requiredError) {
|
|
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "limit"})
|
|
} else {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "limit", Err: err})
|
|
}
|
|
return
|
|
}
|
|
|
|
// ------------- Optional query parameter "modality" -------------
|
|
|
|
err = runtime.BindQueryParameterWithOptions("form", true, false, "modality", r.URL.Query(), ¶ms.Modality, runtime.BindQueryParameterOptions{Type: "string", Format: ""})
|
|
if err != nil {
|
|
var requiredError *runtime.RequiredParameterError
|
|
if errors.As(err, &requiredError) {
|
|
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "modality"})
|
|
} else {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "modality", Err: err})
|
|
}
|
|
return
|
|
}
|
|
|
|
// ------------- Optional query parameter "capability" -------------
|
|
|
|
err = runtime.BindQueryParameterWithOptions("form", true, false, "capability", r.URL.Query(), ¶ms.Capability, runtime.BindQueryParameterOptions{Type: "string", Format: ""})
|
|
if err != nil {
|
|
var requiredError *runtime.RequiredParameterError
|
|
if errors.As(err, &requiredError) {
|
|
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "capability"})
|
|
} else {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "capability", Err: err})
|
|
}
|
|
return
|
|
}
|
|
|
|
// ------------- Optional query parameter "desired_state" -------------
|
|
|
|
err = runtime.BindQueryParameterWithOptions("form", true, false, "desired_state", r.URL.Query(), ¶ms.DesiredState, runtime.BindQueryParameterOptions{Type: "string", Format: ""})
|
|
if err != nil {
|
|
var requiredError *runtime.RequiredParameterError
|
|
if errors.As(err, &requiredError) {
|
|
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "desired_state"})
|
|
} else {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "desired_state", Err: err})
|
|
}
|
|
return
|
|
}
|
|
|
|
// ------------- Optional query parameter "actual_state" -------------
|
|
|
|
err = runtime.BindQueryParameterWithOptions("form", true, false, "actual_state", r.URL.Query(), ¶ms.ActualState, runtime.BindQueryParameterOptions{Type: "string", Format: ""})
|
|
if err != nil {
|
|
var requiredError *runtime.RequiredParameterError
|
|
if errors.As(err, &requiredError) {
|
|
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "actual_state"})
|
|
} else {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "actual_state", Err: err})
|
|
}
|
|
return
|
|
}
|
|
|
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.ListDevices(w, r, siteId, params)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
// CreateDevice operation middleware
|
|
func (siw *ServerInterfaceWrapper) CreateDevice(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var err error
|
|
_ = err
|
|
|
|
// ------------- Path parameter "site_id" -------------
|
|
var siteId SiteID
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "site_id", r.PathValue("site_id"), &siteId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true, Type: "string", Format: "", ValueIsUnescaped: true})
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "site_id", Err: err})
|
|
return
|
|
}
|
|
|
|
// Parameter object where we will unmarshal all parameters from the context
|
|
var params CreateDeviceParams
|
|
|
|
headers := r.Header
|
|
|
|
// ------------- Required header parameter "Idempotency-Key" -------------
|
|
if valueList, found := headers[http.CanonicalHeaderKey("Idempotency-Key")]; found {
|
|
var IdempotencyKey IdempotencyKey
|
|
n := len(valueList)
|
|
if n != 1 {
|
|
siw.ErrorHandlerFunc(w, r, &TooManyValuesForParamError{ParamName: "Idempotency-Key", Count: n})
|
|
return
|
|
}
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "Idempotency-Key", valueList[0], &IdempotencyKey, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationHeader, Explode: false, Required: true, Type: "string", Format: ""})
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "Idempotency-Key", Err: err})
|
|
return
|
|
}
|
|
|
|
params.IdempotencyKey = IdempotencyKey
|
|
|
|
} else {
|
|
err := fmt.Errorf("Header parameter Idempotency-Key is required, but not found")
|
|
siw.ErrorHandlerFunc(w, r, &RequiredHeaderError{ParamName: "Idempotency-Key", Err: err})
|
|
return
|
|
}
|
|
|
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.CreateDevice(w, r, siteId, params)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
// GetDevice operation middleware
|
|
func (siw *ServerInterfaceWrapper) GetDevice(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var err error
|
|
_ = err
|
|
|
|
// ------------- Path parameter "site_id" -------------
|
|
var siteId SiteID
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "site_id", r.PathValue("site_id"), &siteId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true, Type: "string", Format: "", ValueIsUnescaped: true})
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "site_id", Err: err})
|
|
return
|
|
}
|
|
|
|
// ------------- Path parameter "device_id" -------------
|
|
var deviceId DeviceID
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "device_id", r.PathValue("device_id"), &deviceId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true, Type: "string", Format: "", ValueIsUnescaped: true})
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "device_id", Err: err})
|
|
return
|
|
}
|
|
|
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.GetDevice(w, r, siteId, deviceId)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
// UpdateDevice operation middleware
|
|
func (siw *ServerInterfaceWrapper) UpdateDevice(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var err error
|
|
_ = err
|
|
|
|
// ------------- Path parameter "site_id" -------------
|
|
var siteId SiteID
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "site_id", r.PathValue("site_id"), &siteId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true, Type: "string", Format: "", ValueIsUnescaped: true})
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "site_id", Err: err})
|
|
return
|
|
}
|
|
|
|
// ------------- Path parameter "device_id" -------------
|
|
var deviceId DeviceID
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "device_id", r.PathValue("device_id"), &deviceId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true, Type: "string", Format: "", ValueIsUnescaped: true})
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "device_id", Err: err})
|
|
return
|
|
}
|
|
|
|
// Parameter object where we will unmarshal all parameters from the context
|
|
var params UpdateDeviceParams
|
|
|
|
headers := r.Header
|
|
|
|
// ------------- Required header parameter "If-Match" -------------
|
|
if valueList, found := headers[http.CanonicalHeaderKey("If-Match")]; found {
|
|
var IfMatch IfMatch
|
|
n := len(valueList)
|
|
if n != 1 {
|
|
siw.ErrorHandlerFunc(w, r, &TooManyValuesForParamError{ParamName: "If-Match", Count: n})
|
|
return
|
|
}
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "If-Match", valueList[0], &IfMatch, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationHeader, Explode: false, Required: true, Type: "string", Format: ""})
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "If-Match", Err: err})
|
|
return
|
|
}
|
|
|
|
params.IfMatch = IfMatch
|
|
|
|
} else {
|
|
err := fmt.Errorf("Header parameter If-Match is required, but not found")
|
|
siw.ErrorHandlerFunc(w, r, &RequiredHeaderError{ParamName: "If-Match", Err: err})
|
|
return
|
|
}
|
|
|
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.UpdateDevice(w, r, siteId, deviceId, params)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
// SetDeviceDesiredState operation middleware
|
|
func (siw *ServerInterfaceWrapper) SetDeviceDesiredState(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var err error
|
|
_ = err
|
|
|
|
// ------------- Path parameter "site_id" -------------
|
|
var siteId SiteID
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "site_id", r.PathValue("site_id"), &siteId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true, Type: "string", Format: "", ValueIsUnescaped: true})
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "site_id", Err: err})
|
|
return
|
|
}
|
|
|
|
// ------------- Path parameter "device_id" -------------
|
|
var deviceId DeviceID
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "device_id", r.PathValue("device_id"), &deviceId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true, Type: "string", Format: "", ValueIsUnescaped: true})
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "device_id", Err: err})
|
|
return
|
|
}
|
|
|
|
// Parameter object where we will unmarshal all parameters from the context
|
|
var params SetDeviceDesiredStateParams
|
|
|
|
headers := r.Header
|
|
|
|
// ------------- Required header parameter "If-Match" -------------
|
|
if valueList, found := headers[http.CanonicalHeaderKey("If-Match")]; found {
|
|
var IfMatch IfMatch
|
|
n := len(valueList)
|
|
if n != 1 {
|
|
siw.ErrorHandlerFunc(w, r, &TooManyValuesForParamError{ParamName: "If-Match", Count: n})
|
|
return
|
|
}
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "If-Match", valueList[0], &IfMatch, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationHeader, Explode: false, Required: true, Type: "string", Format: ""})
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "If-Match", Err: err})
|
|
return
|
|
}
|
|
|
|
params.IfMatch = IfMatch
|
|
|
|
} else {
|
|
err := fmt.Errorf("Header parameter If-Match is required, but not found")
|
|
siw.ErrorHandlerFunc(w, r, &RequiredHeaderError{ParamName: "If-Match", Err: err})
|
|
return
|
|
}
|
|
|
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.SetDeviceDesiredState(w, r, siteId, deviceId, params)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
// BatchSetDeviceDesiredState operation middleware
|
|
func (siw *ServerInterfaceWrapper) BatchSetDeviceDesiredState(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var err error
|
|
_ = err
|
|
|
|
// ------------- Path parameter "site_id" -------------
|
|
var siteId SiteID
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "site_id", r.PathValue("site_id"), &siteId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true, Type: "string", Format: "", ValueIsUnescaped: true})
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "site_id", Err: err})
|
|
return
|
|
}
|
|
|
|
// Parameter object where we will unmarshal all parameters from the context
|
|
var params BatchSetDeviceDesiredStateParams
|
|
|
|
headers := r.Header
|
|
|
|
// ------------- Required header parameter "Idempotency-Key" -------------
|
|
if valueList, found := headers[http.CanonicalHeaderKey("Idempotency-Key")]; found {
|
|
var IdempotencyKey IdempotencyKey
|
|
n := len(valueList)
|
|
if n != 1 {
|
|
siw.ErrorHandlerFunc(w, r, &TooManyValuesForParamError{ParamName: "Idempotency-Key", Count: n})
|
|
return
|
|
}
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "Idempotency-Key", valueList[0], &IdempotencyKey, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationHeader, Explode: false, Required: true, Type: "string", Format: ""})
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "Idempotency-Key", Err: err})
|
|
return
|
|
}
|
|
|
|
params.IdempotencyKey = IdempotencyKey
|
|
|
|
} else {
|
|
err := fmt.Errorf("Header parameter Idempotency-Key is required, but not found")
|
|
siw.ErrorHandlerFunc(w, r, &RequiredHeaderError{ParamName: "Idempotency-Key", Err: err})
|
|
return
|
|
}
|
|
|
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.BatchSetDeviceDesiredState(w, r, siteId, params)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
type UnescapedCookieParamError struct {
|
|
ParamName string
|
|
Err error
|
|
}
|
|
|
|
func (e *UnescapedCookieParamError) Error() string {
|
|
return fmt.Sprintf("error unescaping cookie parameter '%s'", e.ParamName)
|
|
}
|
|
|
|
func (e *UnescapedCookieParamError) Unwrap() error {
|
|
return e.Err
|
|
}
|
|
|
|
type UnmarshalingParamError struct {
|
|
ParamName string
|
|
Err error
|
|
}
|
|
|
|
func (e *UnmarshalingParamError) Error() string {
|
|
return fmt.Sprintf("Error unmarshaling parameter %s as JSON: %s", e.ParamName, e.Err.Error())
|
|
}
|
|
|
|
func (e *UnmarshalingParamError) Unwrap() error {
|
|
return e.Err
|
|
}
|
|
|
|
type RequiredParamError struct {
|
|
ParamName string
|
|
}
|
|
|
|
func (e *RequiredParamError) Error() string {
|
|
return fmt.Sprintf("Query argument %s is required, but not found", e.ParamName)
|
|
}
|
|
|
|
type RequiredHeaderError struct {
|
|
ParamName string
|
|
Err error
|
|
}
|
|
|
|
func (e *RequiredHeaderError) Error() string {
|
|
return fmt.Sprintf("Header parameter %s is required, but not found", e.ParamName)
|
|
}
|
|
|
|
func (e *RequiredHeaderError) Unwrap() error {
|
|
return e.Err
|
|
}
|
|
|
|
type InvalidParamFormatError struct {
|
|
ParamName string
|
|
Err error
|
|
}
|
|
|
|
func (e *InvalidParamFormatError) Error() string {
|
|
return fmt.Sprintf("Invalid format for parameter %s: %s", e.ParamName, e.Err.Error())
|
|
}
|
|
|
|
func (e *InvalidParamFormatError) Unwrap() error {
|
|
return e.Err
|
|
}
|
|
|
|
type TooManyValuesForParamError struct {
|
|
ParamName string
|
|
Count int
|
|
}
|
|
|
|
func (e *TooManyValuesForParamError) Error() string {
|
|
return fmt.Sprintf("Expected one value for %s, got %d", e.ParamName, e.Count)
|
|
}
|
|
|
|
// Handler creates http.Handler with routing matching OpenAPI spec.
|
|
func Handler(si ServerInterface) http.Handler {
|
|
return HandlerWithOptions(si, StdHTTPServerOptions{})
|
|
}
|
|
|
|
// ServeMux is an abstraction of [http.ServeMux].
|
|
type ServeMux interface {
|
|
HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
|
|
http.Handler
|
|
}
|
|
|
|
type StdHTTPServerOptions struct {
|
|
BaseURL string
|
|
BaseRouter ServeMux
|
|
Middlewares []MiddlewareFunc
|
|
ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
|
|
}
|
|
|
|
// HandlerFromMux creates http.Handler with routing matching OpenAPI spec based on the provided mux.
|
|
func HandlerFromMux(si ServerInterface, m ServeMux) http.Handler {
|
|
return HandlerWithOptions(si, StdHTTPServerOptions{
|
|
BaseRouter: m,
|
|
})
|
|
}
|
|
|
|
func HandlerFromMuxWithBaseURL(si ServerInterface, m ServeMux, baseURL string) http.Handler {
|
|
return HandlerWithOptions(si, StdHTTPServerOptions{
|
|
BaseURL: baseURL,
|
|
BaseRouter: m,
|
|
})
|
|
}
|
|
|
|
// HandlerWithOptions creates http.Handler with additional options
|
|
func HandlerWithOptions(si ServerInterface, options StdHTTPServerOptions) http.Handler {
|
|
m := options.BaseRouter
|
|
|
|
if m == nil {
|
|
m = http.NewServeMux()
|
|
}
|
|
if options.ErrorHandlerFunc == nil {
|
|
options.ErrorHandlerFunc = func(w http.ResponseWriter, r *http.Request, err error) {
|
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
}
|
|
}
|
|
|
|
wrapper := ServerInterfaceWrapper{
|
|
Handler: si,
|
|
HandlerMiddlewares: options.Middlewares,
|
|
ErrorHandlerFunc: options.ErrorHandlerFunc,
|
|
}
|
|
|
|
m.HandleFunc(http.MethodGet+" "+options.BaseURL+"/api/v1/operations/{operation_id}", wrapper.GetOperation)
|
|
m.HandleFunc(http.MethodGet+" "+options.BaseURL+"/api/v1/sites/{site_id}/devices", wrapper.ListDevices)
|
|
m.HandleFunc(http.MethodPost+" "+options.BaseURL+"/api/v1/sites/{site_id}/devices", wrapper.CreateDevice)
|
|
m.HandleFunc(http.MethodGet+" "+options.BaseURL+"/api/v1/sites/{site_id}/devices/{device_id}", wrapper.GetDevice)
|
|
m.HandleFunc(http.MethodPatch+" "+options.BaseURL+"/api/v1/sites/{site_id}/devices/{device_id}", wrapper.UpdateDevice)
|
|
m.HandleFunc(http.MethodPut+" "+options.BaseURL+"/api/v1/sites/{site_id}/devices/{device_id}/desired-state", wrapper.SetDeviceDesiredState)
|
|
m.HandleFunc(http.MethodPost+" "+options.BaseURL+"/api/v1/sites/{site_id}/devices:batchDesiredState", wrapper.BatchSetDeviceDesiredState)
|
|
|
|
return m
|
|
}
|