Documentation
¶
Index ¶
- Variables
- type AccessLevel
- type Action
- type ActionParams
- type ActionType
- type ApicallActionParams
- type CreateEventRequest
- type CreateTokenRequest
- type CreateTokenResponse
- type Event
- type EventCreateRequest
- type EventFilter
- type EventResponse
- type EventStatus
- type EventUpdateRequest
- type Occurrence
- type OccurrenceFilter
- type OccurrenceStatus
- type PaginatedResponse
- type Schedule
- type ScheduleConfig
- type Token
- type TokenClaims
- type TokenType
- type UpdateEventRequest
- type WebhookActionParams
- type WebsocketActionParams
Constants ¶
This section is empty.
Variables ¶
var ( ErrEventNotFound = errors.New("event not found") ErrOccurrenceNotFound = errors.New("occurrence not found") )
Functions ¶
This section is empty.
Types ¶
type AccessLevel ¶
type AccessLevel string
AccessLevel represents the access level of a token
const ( AccessLevelRead AccessLevel = "read" AccessLevelWrite AccessLevel = "write" AccessLevelReadWrite AccessLevel = "read_write" AccessLevelAdmin AccessLevel = "admin" )
type Action ¶
type Action struct {
Type ActionType `json:"type"`
Params json.RawMessage `json:"params"` // Holds WebhookActionParams or WebsocketActionParams as JSON
}
Action represents a generic action to be performed for an event.
func (*Action) GetWebhookParams ¶
func (a *Action) GetWebhookParams() (*WebhookActionParams, error)
GetWebhookParams attempts to unmarshal the action's params into WebhookActionParams.
func (*Action) GetWebsocketParams ¶
func (a *Action) GetWebsocketParams() (*WebsocketActionParams, error)
GetWebsocketParams attempts to unmarshal the action's params into WebsocketActionParams.
type ActionParams ¶
type ActionParams interface{}
ActionParams is an interface for action-specific parameters. We use json.RawMessage for Params in the Action struct to allow flexible marshalling/unmarshalling of type-specific parameter structs.
type ActionType ¶
type ActionType string
ActionType defines the type of action to be performed.
const ( ActionTypeWebhook ActionType = "webhook" ActionTypeWebsocket ActionType = "websocket" ActionTypeAPICall ActionType = "apicall" // ActionTypeUnknown represents an unsupported or undefined action type. ActionTypeUnknown ActionType = "unknown" )
type ApicallActionParams ¶
type ApicallActionParams struct {
Method string `json:"method"`
Headers map[string]string `json:"headers,omitempty"`
Body json.RawMessage `json:"body,omitempty"`
URL string `json:"url"`
}
ApicallActionParams defines parameters for the apicall action type
type CreateEventRequest ¶
type CreateEventRequest struct {
Name string `json:"name" validate:"required"`
Description *string `json:"description,omitempty"`
StartTime time.Time `json:"start_time" validate:"required"`
Webhook string `json:"webhook" validate:"required"`
Metadata datatypes.JSON `json:"metadata" validate:"required"`
Schedule *ScheduleConfig `json:"schedule,omitempty"`
Tags []string `json:"tags"`
HMACSecret *string `json:"hmac_secret,omitempty"`
}
type CreateTokenRequest ¶
type CreateTokenRequest struct {
Type TokenType `json:"type" binding:"required"`
Sub string `json:"sub" binding:"required"`
Access AccessLevel `json:"access" binding:"required"`
Scope []string `json:"scope" binding:"required"`
ExpiresAt time.Time `json:"expires_at" binding:"required"`
}
CreateTokenRequest represents the request to create a new token
type CreateTokenResponse ¶
type CreateTokenResponse struct {
Token string `json:"token"`
Type TokenType `json:"type"`
Sub string `json:"sub"`
Access AccessLevel `json:"access"`
Scope []string `json:"scope"`
ExpiresAt time.Time `json:"expires_at"`
}
CreateTokenResponse represents the response when creating a new token
type Event ¶
type Event struct {
ID uuid.UUID `json:"id" db:"id"`
Name string `json:"name" db:"name"`
Description string `json:"description" db:"description,omitempty"`
StartTime time.Time `json:"start_time" db:"start_time"`
Webhook string `json:"webhook" db:"webhook"`
Action *Action `json:"action" db:"action,omitempty"`
Metadata datatypes.JSON `json:"metadata" db:"metadata,omitempty"`
Schedule *ScheduleConfig `json:"schedule" db:"schedule,omitempty"`
Tags pq.StringArray `json:"tags" db:"tags,omitempty"`
Status EventStatus `json:"status" db:"status"`
HMACSecret *string `json:"hmac_secret" db:"hmac_secret,omitempty"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
UpdatedAt *time.Time `json:"updated_at" db:"updated_at,omitempty"`
}
Event represents a scheduled event
func (*Event) ToEventResponse ¶
func (e *Event) ToEventResponse() EventResponse
ToEventResponse converts an Event model to an EventResponse for API output. This can be expanded to include more fields or transform data as needed.
type EventCreateRequest ¶
type EventCreateRequest struct {
Name string `json:"name" binding:"required"`
Description *string `json:"description,omitempty"`
StartTime time.Time `json:"start_time" binding:"required"`
Webhook *string `json:"webhook,omitempty"` // Kept for backward compatibility
Action *Action `json:"action,omitempty"` // New action field
Metadata json.RawMessage `json:"metadata,omitempty"` // Use json.RawMessage for flexible metadata
Schedule *ScheduleConfig `json:"schedule,omitempty"`
Tags []string `json:"tags,omitempty"`
HMACSecret *string `json:"hmac_secret,omitempty"`
}
EventCreateRequest defines the structure for creating a new event
type EventFilter ¶
type EventResponse ¶
type EventResponse struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
StartTime time.Time `json:"start_time"`
Webhook string `json:"webhook"`
Action *Action `json:"action,omitempty"`
Metadata datatypes.JSON `json:"metadata,omitempty"`
Schedule *ScheduleConfig `json:"schedule,omitempty"`
Tags pq.StringArray `json:"tags,omitempty"`
Status string `json:"status"`
HMACSecret *string `json:"hmac_secret,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
}
EventResponse defines the structure for API responses for an event
type EventStatus ¶
type EventStatus string
const ( EventStatusActive EventStatus = "active" EventStatusInactive EventStatus = "inactive" EventStatusPaused EventStatus = "paused" EventStatusDeleted EventStatus = "deleted" )
type EventUpdateRequest ¶
type EventUpdateRequest struct {
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
StartTime *time.Time `json:"start_time,omitempty"`
Webhook *string `json:"webhook,omitempty"` // Kept for backward compatibility
Action *Action `json:"action,omitempty"` // New action field
Metadata json.RawMessage `json:"metadata,omitempty"` // Use json.RawMessage for flexible metadata
Schedule *ScheduleConfig `json:"schedule,omitempty"`
Tags []string `json:"tags,omitempty"`
Status *EventStatus `json:"status,omitempty"`
HMACSecret *string `json:"hmac_secret,omitempty"`
}
EventUpdateRequest defines the structure for updating an existing event All fields are optional, so use pointers
type Occurrence ¶
type Occurrence struct {
ID int `json:"id" db:"id"`
OccurrenceID uuid.UUID `json:"occurrence_id" db:"occurrence_id"`
EventID uuid.UUID `json:"event_id" db:"event_id"`
ScheduledAt time.Time `json:"scheduled_at" db:"scheduled_at"`
Status OccurrenceStatus `json:"status" db:"status"`
AttemptCount int `json:"attempt_count" db:"attempt_count"`
Timestamp time.Time `json:"timestamp" db:"timestamp"`
StatusCode int `json:"status_code" db:"status_code"`
ResponseBody string `json:"response_body" db:"response_body"`
ErrorMessage string `json:"error_message" db:"error_message"`
StartedAt time.Time `json:"started_at" db:"started_at"`
CompletedAt time.Time `json:"completed_at" db:"completed_at"`
}
type OccurrenceFilter ¶
type OccurrenceStatus ¶
type OccurrenceStatus string
const ( OccurrenceStatusPending OccurrenceStatus = "pending" OccurrenceStatusScheduled OccurrenceStatus = "scheduled" OccurrenceStatusDispatched OccurrenceStatus = "dispatched" OccurrenceStatusCompleted OccurrenceStatus = "completed" OccurrenceStatusFailed OccurrenceStatus = "failed" )
type PaginatedResponse ¶
type Schedule ¶
type Schedule struct {
Occurrence
Name string `json:"name"`
Description string `json:"description"`
Webhook string `json:"webhook"`
Metadata datatypes.JSON `json:"metadata"`
Tags pq.StringArray `json:"tags"`
}
Schedule is used for storing scheduled events in Redis with all event fields (no prefix)
type ScheduleConfig ¶
type ScheduleConfig struct {
Frequency string `json:"frequency"` // daily, weekly, monthly, yearly
Interval int `json:"interval"` // interval between occurrences
ByDay []string `json:"by_day,omitempty"` // for weekly frequency
ByMonth []int `json:"by_month,omitempty"` // for yearly frequency
ByMonthDay []int `json:"by_month_day,omitempty"` // for monthly frequency
Count *int `json:"count,omitempty"` // number of occurrences
Until *string `json:"until,omitempty"` // end date in RFC3339 format
}
ScheduleConfig represents the JSON schedule configuration
func (*ScheduleConfig) Scan ¶
func (s *ScheduleConfig) Scan(value interface{}) error
Implement sql.Scanner for ScheduleConfig
type Token ¶
type Token struct {
Sub string `json:"sub"`
Access AccessLevel `json:"access"`
Scope []string `json:"scope"`
ExpiresAt time.Time `json:"exp"`
}
Token represents a JWT token with its claims
type TokenClaims ¶
type TokenClaims struct {
Sub string `json:"sub"`
Access AccessLevel `json:"access"`
Scope []string `json:"scope"`
ExpiresAt time.Time `json:"exp"`
}
TokenClaims represents the claims in a JWT token
type TokenType ¶
type TokenType string
TokenType represents the type of token
const (
TokenTypeJWT TokenType = "jwt"
)
type UpdateEventRequest ¶
type UpdateEventRequest struct {
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
StartTime *time.Time `json:"start_time,omitempty"`
Webhook *string `json:"webhook,omitempty"`
Metadata datatypes.JSON `json:"metadata,omitempty"`
Schedule *ScheduleConfig `json:"schedule,omitempty"`
Tags []string `json:"tags,omitempty"`
Status *string `json:"status,omitempty"`
HMACSecret *string `json:"hmac_secret,omitempty"`
}
type WebhookActionParams ¶
type WebhookActionParams struct {
URL string `json:"url"`
}
WebhookActionParams contains parameters specific to webhook actions.
type WebsocketActionParams ¶
type WebsocketActionParams struct {
ClientName string `json:"client_name"`
}
WebsocketActionParams contains parameters specific to websocket actions. This refers to dispatching to a client connected to Qhronos's own WebSocket server.