Documentation ¶
Index ¶
- Constants
- Variables
- func CheckHttpResponse(statusCode, goodStatus int) error
- func IsValidStatus(status string) error
- func JsonOut(obj any) string
- func JsonWrite(writer io.Writer, obj any) error
- type CompnentUptime
- type Component
- type ComponentGroup
- type ComponentGroupRequest
- type ComponentGroupResponse
- type ComponentGroupUptime
- type ComponentResponse
- type Components
- type ComponentsResponse
- type HttpClient
- type Incident
- type IncidentResponse
- type IncidentUpdate
- type IncidentUpdateResponse
- type Incidents
- type StatusEmbedConfig
- type StatusEmbedConfigResponse
- type StatusPageClient
- func (sp *StatusPageClient) CreateComponent(pageId string, newComponent Component) (*ComponentResponse, error)
- func (sp *StatusPageClient) CreateComponentGroup(pageId string, newGroup ComponentGroupRequest) (*ComponentGroupResponse, error)
- func (sp *StatusPageClient) CreateIncident(pageId string, incident Incident) (*IncidentResponse, error)
- func (sp *StatusPageClient) DeleteComponent(pageId string, id string) (bool, error)
- func (sp *StatusPageClient) GetComponent(pageId string, id string) (*ComponentResponse, error)
- func (sp *StatusPageClient) GetComponentGroup(pageId string, id string) (*ComponentGroupResponse, error)
- func (sp *StatusPageClient) GetComponentGroupUptime(pageId string, id string) (*ComponentGroupUptime, error)
- func (sp *StatusPageClient) GetComponentGroups(pageId string) ([]ComponentGroupResponse, error)
- func (sp *StatusPageClient) GetComponentUptime(pageId string, id string) (*CompnentUptime, error)
- func (sp *StatusPageClient) GetComponents(pageId string) ([]ComponentResponse, error)
- func (sp *StatusPageClient) GetIncident(pageId string, id string) (*Incident, error)
- func (sp *StatusPageClient) GetIncidents(pageId string, limit string) ([]IncidentResponse, error)
- func (sp *StatusPageClient) GetStatusEmbedConfig(pageId string) (*StatusEmbedConfigResponse, error)
- func (sp *StatusPageClient) SetComponentStatus(pageId string, id string, status string) (*ComponentResponse, error)
- func (sp *StatusPageClient) UpdateComponent(pageId string, id string, updateComponent Component) (*ComponentResponse, error)
- func (sp *StatusPageClient) UpdateStatusEmbedConfig(pageId string, embedUpdate *StatusEmbedConfig) (*StatusEmbedConfigResponse, error)
Constants ¶
const TmplViewComponent = `` /* 565-byte string literal not displayed */
TmplViewComponent constant represents the template for displaying the details of a component.
const TmplViewComponentGroup = `` /* 350-byte string literal not displayed */
TmplViewComponentGroup is a constant template string used to generate a formatted view of a ComponentGroup object.
const TmplViewComponentGroupUptime = `` /* 474-byte string literal not displayed */
TmplViewComponentGroupUptime is a constant that represents a template for viewing uptime of a component group
const TmplViewComponentUptime = `` /* 477-byte string literal not displayed */
TmplViewComponentUptime is a constant that represents the template for displaying the component uptime details.
const TmplViewIncident = `Id: {{ .Id }}
Name: {{ .Name }}
`
TmplViewIncident is a constant string that represents a template for viewing an incident.
Variables ¶
var DefaultClient = &http.Client{}
DefaultClient is the default HTTP client used by the StatusPageClient to make API requests.
var DefaultStatusPageUrl = "https://api.statuspage.io/v1"
DefaultStatusPageUrl is the default URL for the StatusPage API.
var ValidComponentStatus = []string{
"degraded_performance",
"partial_outage",
"major_outage",
"operational",
"under_maintenance",
}
ValidComponentStatus is a slice of strings that represents the valid status values for a component.
var ViewTemplates *template.Template
Functions ¶
func CheckHttpResponse ¶ added in v0.2.5
CheckHttpResponse Handle error
func IsValidStatus ¶ added in v0.2.5
IsValidStatus checks if the provided status string is a valid component status. It returns true if the status is found in the ValidComponentStatus slice, otherwise false.
Types ¶
type CompnentUptime ¶ added in v0.2.0
type CompnentUptime struct { RangeStart string `json:"range_start"` RangeEnd string `json:"range_end"` UptimePercentage float64 `json:"uptime_percentage"` MajorOutage int `json:"major_outage"` PartialOutage int `json:"partial_outage"` Warnings []string `json:"warnings"` Id string `json:"id"` Name string `json:"name"` RelatedEvents []struct { Id string `json:"id"` } `json:"related_events"` }
type Component ¶
type Component struct { Id string `json:"id,omitempty"` Name string `json:"name"` Description string `json:"description"` Status string `json:"status,omitempty"` Showcase bool `json:"showcase"` GroupId string `json:"group_id,omitempty"` OnlyShowIfDegraded bool `json:"only_show_if_degraded"` StartDate string `json:"start_date,omitempty"` }
Component represents a component of a status page.
type ComponentGroup ¶ added in v0.2.5
type ComponentGroupRequest ¶ added in v0.2.5
type ComponentGroupRequest struct { Description string `json:"description"` ComponentGroup ComponentGroup `json:"component_group"` }
type ComponentGroupResponse ¶ added in v0.2.5
type ComponentGroupResponse struct { Id string `json:"id,omitempty"` PageId string `json:"page_id"` Name string `json:"name"` Description string `json:"description"` Components []string `json:"components"` Position int `json:"position"` CreatedAt time.Time `json:"created_at,omitempty"` UpdatedAt time.Time `json:"updated_at,omitempty"` }
type ComponentGroupUptime ¶ added in v0.2.5
type ComponentGroupUptime struct { RangeStart string `json:"range_start"` RangeEnd string `json:"range_end"` UptimePercentage float64 `json:"uptime_percentage"` MajorOutage int `json:"major_outage"` PartialOutage int `json:"partial_outage"` Warnings []string `json:"warnings"` Id string `json:"id"` Name string `json:"name"` RelatedEvents []struct { ComponentId string `json:"component_id"` Incidents struct { Id string `json:"id"` } `json:"incidents"` } `json:"related_events"` }
type ComponentResponse ¶ added in v0.1.12
type ComponentResponse struct { Component Id string `json:"id,omitempty"` PageId string `json:"page_id,omitempty"` Group bool `json:"group"` CreatedAt time.Time `json:"created_at,omitempty"` UpdatedAt time.Time `json:"updated_at,omitempty"` Position int `json:"position,omitempty"` OnlyShowIfDegraded bool `json:"only_show_if_degraded"` AutomationEmail string `json:"automation_email,omitempty"` }
ComponentResponse represents a response containing details of a component.
func (*ComponentResponse) ReturnComponent ¶ added in v0.2.5
func (com *ComponentResponse) ReturnComponent() Component
ReturnComponent Json returns the JSON representation of a ComponentResponse.
Usage: jsonString := component.Json()
Returns:
string: The JSON representation of the ComponentResponse.
func (com ComponentResponse) Json() string { out, err := json.MarshalIndent(com, "", " ") if err != nil { return "" } return string(out) }
type Components ¶
type Components struct {
Components []Component
}
type ComponentsResponse ¶ added in v0.1.12
type ComponentsResponse struct {
Components []ComponentResponse
}
ComponentsResponse is a type that represents a collection of ComponentResponse instances.
type HttpClient ¶
HttpClient represents an interface for making HTTP requests and getting the responses.
type Incident ¶
type Incident struct { Id string `json:"id,omitempty"` Components []ComponentResponse `json:"components"` CreatedAt time.Time `json:"-"` ImpactOverride string `json:"impact_override"` Metadata struct{} `json:"metadata,omitempty"` Name string `json:"name"` ScheduledAutoCompleted bool `json:"scheduled_auto_completed"` ScheduledAutoInProgress bool `json:"scheduled_auto_in_progress"` ScheduledFor time.Time `json:"scheduled_for,omitempty"` AutoTransitionDeliverNotificationsAtEnd bool `json:"auto_transition_deliver_notifications_at_end"` AutoTransitionDeliverNotificationsAtStart bool `json:"auto_transition_deliver_notifications_at_start"` AutoTransitionToMaintenanceState bool `json:"auto_transition_to_maintenance_state"` AutoTransitionToOperationalState bool `json:"auto_transition_to_operational_state"` ScheduledRemindPrior bool `json:"scheduled_remind_prior"` ScheduledUntil time.Time `json:"scheduled_until,omitempty"` Status string `json:"status"` ReminderIntervals string `json:"reminder_intervals,omitempty"` DeliverNotifications bool `json:"deliver_notifications"` AutoTweetAtBeginning bool `json:"auto_tweet_at_beginning"` AutoTweetOnCompletion bool `json:"auto_tweet_on_completion"` AutoTweetOnCreation bool `json:"auto_tweet_on_creation"` AutoTweetOneHourBefore bool `json:"auto_tweet_one_hour_before"` BackfillDate string `json:"backfill_date,omitempty"` Backfilled bool `json:"backfilled"` Body string `json:"body"` ComponentIds []string `json:"component_ids"` ScheduledAutoTransition bool `json:"scheduled_auto_transition"` }
type IncidentResponse ¶ added in v0.2.6
type IncidentResponse struct { Id string `json:"id"` Components []Component `json:"components"` CreatedAt time.Time `json:"created_at"` Impact string `json:"impact"` ImpactOverride string `json:"impact_override"` IncidentUpdates []IncidentUpdateResponse `json:"incident_updates"` //Metadata []struct{} `json:"metadata,omitempty"` MonitoringAt time.Time `json:"monitoring_at"` Name string `json:"name"` PageId string `json:"page_id"` PostmortemBody string `json:"postmortem_body"` PostmortemBodyLastUpdatedAt time.Time `json:"postmortem_body_last_updated_at"` PostmortemIgnored bool `json:"postmortem_ignored"` PostmortemNotifiedSubscribers bool `json:"postmortem_notified_subscribers"` PostmortemNotifiedTwitter bool `json:"postmortem_notified_twitter"` PostmortemPublishedAt bool `json:"postmortem_published_at"` ResolvedAt time.Time `json:"resolved_at"` ScheduledAutoCompleted bool `json:"scheduled_auto_completed"` ScheduledAutoInProgress bool `json:"scheduled_auto_in_progress"` ScheduledFor time.Time `json:"scheduled_for"` AutoTransitionDeliverNotificationsAtEnd bool `json:"auto_transition_deliver_notifications_at_end"` AutoTransitionDeliverNotificationsAtStart bool `json:"auto_transition_deliver_notifications_at_start"` AutoTransitionToMaintenanceState bool `json:"auto_transition_to_maintenance_state"` AutoTransitionToOperationalState bool `json:"auto_transition_to_operational_state"` ScheduledRemindPrior bool `json:"scheduled_remind_prior"` ScheduledRemindedAt time.Time `json:"scheduled_reminded_at"` ScheduledUntil time.Time `json:"scheduled_until"` Shortlink string `json:"shortlink"` Status string `json:"status"` UpdatedAt time.Time `json:"updated_at"` ReminderIntervals string `json:"reminder_intervals"` }
type IncidentUpdate ¶
type IncidentUpdateResponse ¶ added in v0.2.6
type IncidentUpdateResponse struct { IncidentUpdate Id string `json:"id"` IncidentId string `json:"incident_id"` AffectedComponents []struct { Code string `json:"code"` Name string `json:"name"` OldStatus string `json:"old_status"` NewStatus string `json:"new_status"` } `json:"affected_components"` CreatedAt time.Time `json:"created_at,omitempty"` CustomTweet string `json:"custom_tweet,omitempty"` Status string `json:"status"` TweetId string `json:"tweet_id"` TwitterUpdatedAt time.Time `json:"twitter_updated_at"` UpdatedAt time.Time `json:"updated_at"` }
type StatusEmbedConfig ¶ added in v0.2.5
type StatusEmbedConfig struct { Position string `json:"position"` IncidentBackgroundColor string `json:"incident_background_color"` IncidentTextColor string `json:"incident_text_color"` MaintenanceBackgroundColor string `json:"maintenance_background_color"` MaintenanceTextColor string `json:"maintenance_text_color"` }
type StatusEmbedConfigResponse ¶ added in v0.2.5
type StatusEmbedConfigResponse struct { PageId string `json:"page_id"` StatusEmbedConfig }
type StatusPageClient ¶
type StatusPageClient struct { BaseUrl string ApiKey string Client HttpClient }
StatusPageClient represents a client for interacting with the StatusPage API.
func NewClient ¶
func NewClient(apiKey string) *StatusPageClient
NewClient creates a new instance of StatusPageClient with the provided API key. It sets the BaseUrl to DefaultStatusPageUrl and the Client to DefaultClient.
func (*StatusPageClient) CreateComponent ¶ added in v0.1.10
func (sp *StatusPageClient) CreateComponent(pageId string, newComponent Component) (*ComponentResponse, error)
CreateComponent creates a new component on a status page using the provided page ID and component data. It returns the created component response and an error if any.
Usage: component, err := client.CreateComponent(pageId, newComponent)
Example:
component, err := client.CreateComponent("pageId", Component{ Name: "New Component", Description: "A new component", Status: "operational", })
Parameters:
- pageId: The ID of the status page.
- newComponent: The data for the new component being created.
Returns:
- component: The created component response.
- error: An error if the request fails, if the response status code is not 200 OK, or if there is an issue unmarshaling the response body.
func (*StatusPageClient) CreateComponentGroup ¶ added in v0.2.5
func (sp *StatusPageClient) CreateComponentGroup(pageId string, newGroup ComponentGroupRequest) (*ComponentGroupResponse, error)
CreateComponentGroup sends a POST request to the specified pageId to create a new component group.
func (*StatusPageClient) CreateIncident ¶ added in v0.2.6
func (sp *StatusPageClient) CreateIncident(pageId string, incident Incident) (*IncidentResponse, error)
func (*StatusPageClient) DeleteComponent ¶ added in v0.1.12
func (sp *StatusPageClient) DeleteComponent(pageId string, id string) (bool, error)
DeleteComponent removes a component from a status page using the provided page ID and component ID. It returns a boolean indicating whether the component was successfully deleted and an error if any.
func (*StatusPageClient) GetComponent ¶
func (sp *StatusPageClient) GetComponent(pageId string, id string) (*ComponentResponse, error)
GetComponent fetches a specific component of a status page using the provided page ID and component ID. It returns the fetched component and an error if any.
Usage: component, err := client.GetComponent(pageId, id)
Example:
component, err := client.GetComponent("pageId", "componentId")
Parameters:
- pageId: The ID of the status page.
- id: The ID of the component.
Returns:
- component: The fetched component.
- error: An error if the request fails or if the response status code is not 200 OK.
func (*StatusPageClient) GetComponentGroup ¶ added in v0.2.5
func (sp *StatusPageClient) GetComponentGroup(pageId string, id string) (*ComponentGroupResponse, error)
GetComponentGroup retrieves a component group from a StatusPage.
func (*StatusPageClient) GetComponentGroupUptime ¶ added in v0.2.5
func (sp *StatusPageClient) GetComponentGroupUptime(pageId string, id string) (*ComponentGroupUptime, error)
GetComponentGroupUptime retrieves the uptime information for a component group from the pageid
func (*StatusPageClient) GetComponentGroups ¶ added in v0.2.5
func (sp *StatusPageClient) GetComponentGroups(pageId string) ([]ComponentGroupResponse, error)
GetComponentGroups retrieves all component groups from a StatusPage. It sends a GET request to the specified pageId,
func (*StatusPageClient) GetComponentUptime ¶ added in v0.2.5
func (sp *StatusPageClient) GetComponentUptime(pageId string, id string) (*CompnentUptime, error)
GetComponentUptime fetches the uptime information of a specific component of a status page using the provided page ID and component ID. It returns the fetched ComponentUptime and an error if any.
Usage: uptime, err := client.GetComponentUptime(pageId, id)
Example:
uptime, err := client.GetComponentUptime("pageId", "componentId")
Parameters:
- pageId: The ID of the status page.
- id: The ID of the component.
Returns:
- uptime: The fetched ComponentUptime.
- error: An error if the request fails or if the response status code is not 200 OK.
func (*StatusPageClient) GetComponents ¶
func (sp *StatusPageClient) GetComponents(pageId string) ([]ComponentResponse, error)
GetComponents fetches all components of a status page using the provided page ID. It returns the fetched components and an error if any.
Usage: components, err := client.GetComponents(pageId)
Example:
components, err := client.GetComponents("pageId")
Parameters:
- pageId: The ID of the status page.
Returns:
- components: The fetched components.
- error: An error if the request fails or if the response status code is not 200 OK.
func (*StatusPageClient) GetIncident ¶
func (sp *StatusPageClient) GetIncident(pageId string, id string) (*Incident, error)
func (*StatusPageClient) GetIncidents ¶
func (sp *StatusPageClient) GetIncidents(pageId string, limit string) ([]IncidentResponse, error)
func (*StatusPageClient) GetStatusEmbedConfig ¶ added in v0.2.5
func (sp *StatusPageClient) GetStatusEmbedConfig(pageId string) (*StatusEmbedConfigResponse, error)
GetStatusEmbedConfig retrieves the status embed configuration for the specified page.
func (*StatusPageClient) SetComponentStatus ¶
func (sp *StatusPageClient) SetComponentStatus(pageId string, id string, status string) (*ComponentResponse, error)
SetComponentStatus updates the status of a specific component on a status page using the provided page ID, component ID, and status. It returns the updated component and an error if any.
Usage: component, err := client.SetComponentStatus(pageId, id, status)
Example:
component, err := client.SetComponentStatus("pageId", "componentId", "status")
Parameters:
- pageId: The ID of the status page.
- id: The ID of the component.
- status: The new status of the component.
Returns:
- component: The updated component.
- error: An error if the request fails or if the response status code is not 200 OK.
func (*StatusPageClient) UpdateComponent ¶ added in v0.1.12
func (sp *StatusPageClient) UpdateComponent(pageId string, id string, updateComponent Component) (*ComponentResponse, error)
UpdateComponent updates a specific component of a status page using the provided page ID, component ID, and updated component information. It returns the updated component and an error if any. Usage: component, err := client.UpdateComponent(pageId, id, updatedComponent)
Parameters:
- pageId: The ID of the status page.
- id: The ID of the component.
- updateComponent: The updated component information.
Returns:
- component: The updated component.
- error: An error if the request fails or if the response status code is not 200 OK.
Note: The JSON representation of the updateComponent should be passed as a string. Example: updateComponent, err := client.UpdateComponent("pageId", "componentId", `{"name":"Updated Component", "description":"Updated description", "status":"partial_outage"}`)
func (*StatusPageClient) UpdateStatusEmbedConfig ¶ added in v0.2.6
func (sp *StatusPageClient) UpdateStatusEmbedConfig(pageId string, embedUpdate *StatusEmbedConfig) (*StatusEmbedConfigResponse, error)
UpdateStatusEmbedConfig updates the status embed configuration for the specified page.