capxml

package
v0.0.0-...-66518bc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TimeFormat is the time format used for dates in the CAP protocol.
	TimeFormat = "2006-01-02T15:04:05-07:00"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Alert

type Alert struct {
	XMLName xml.Name `xml:"alert" json:"-"`

	Identifier  string      `xml:"identifier" json:"identifier"`
	Sender      string      `xml:"sender" json:"sender"`
	Sent        Time        `xml:"sent" json:"sent"`
	Status      Status      `xml:"status" json:"status"`
	MessageType MessageType `xml:"msgType" json:"message_type"`
	Source      string      `xml:"source" json:"source"`
	Scope       Scope       `xml:"scope" json:"scope"`
	Restriction string      `xml:"restriction" json:"restriction"`
	Addresses   List        `xml:"addresses" json:"addresses"`
	Codes       []string    `xml:"code" json:"codes"`
	Note        string      `xml:"note" json:"note"`
	References  References  `xml:"references" json:"references"`
	Incidents   List        `xml:"incidents" json:"incidents"`
	Infos       []*Info     `xml:"info" json:"infos"`
	Superseded  bool        `xml:"-" json:"superseded"`
}

An Alert represents an alert issued through a Common Alerting Protocol (CAP) compliant system.

func (*Alert) ID

func (alert *Alert) ID() string

ID returns the alert's identification string. The identification string is a sha1sum of sender,unix(sent),identifier.

func (*Alert) Supersede

func (alert *Alert) Supersede()

Supersede marks an alert as superseded.

type Area

type Area struct {
	XMLName xml.Name `xml:"area" json:"-"`

	Description string   `xml:"areaDesc" json:"description"`
	Polygons    Polygons `xml:"polygon" json:"polygons"`
	Circles     Circles  `xml:"circle" json:"circles"`
	GeoCodes    KeyValue `xml:"geocode" json:"geocodes"`
	Altitude    int      `xml:"altitude" json:"altitude"`
	Ceiling     int      `xml:"ceiling" json:"ceiling"`
}

An Area represents an area affected by an event.

type Category

type Category int

A Category represents an alert category.

const (
	// CategoryUnknown represents an unknown event category.
	CategoryUnknown Category = iota

	// CategoryGeophysical represents a geophysical event.
	CategoryGeophysical

	// CategoryMeteorological represents a meteorological event.
	CategoryMeteorological

	// CategorySafety represents a general emergency and public safety event.
	CategorySafety

	// CategorySecurity represents a law enforcement, military, homeland and local/private security event.
	CategorySecurity

	// CategoryRescue represents a rescue and recovert event.
	CategoryRescue

	// CategoryFire represents a fire suppression and rescue event.
	CategoryFire

	// CategoryHealth represents a medical and public health event.
	CategoryHealth

	// CategoryEnvironment represents a pollutiohn and other environmental event.
	CategoryEnvironment

	// CategoryTransport represents a public and private transportation event.
	CategoryTransport

	// CategoryInfrastructure represents a utility, telecommunication or other non-transport infrastructure event.
	CategoryInfrastructure

	// CategoryCBRNE represents a Chemical, Biological, Radiological, Nuclear or High-Yield explosive threat or attack event.
	CategoryCBRNE

	// CategoryOther represnts other events.
	CategoryOther
)

func (Category) MarshalXML

func (category Category) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements the xml.Marshaler interface.

func (Category) String

func (category Category) String() string

String returns a Category as a string.

func (*Category) UnmarshalJSON

func (category *Category) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Category) UnmarshalText

func (category *Category) UnmarshalText(data []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (*Category) UnmarshalXML

func (category *Category) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements the xml.Unmarshaler interface.

type Certainty

type Certainty int

A Certainty represents the certainty of an event.

const (
	// CertaintyUnknown represents an event with unknown certainty.
	CertaintyUnknown Certainty = iota

	// CertaintyObserved represents an event determined to have occurred or to be ongoing.
	CertaintyObserved

	// CertaintyLikely represents an event that is likely (p > ~50%).
	CertaintyLikely

	// CertaintyPossible represents an event that is possible but not likely (p <= ~50%)
	CertaintyPossible

	// CertaintyUnlikely represents an event that is unlikely to occure (p ~ 0)
	CertaintyUnlikely
)

func (Certainty) MarshalXML

func (certainty Certainty) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements the xml.Marshaler interface.

func (Certainty) String

func (certainty Certainty) String() string

String returns a Certainty as a string.

func (*Certainty) UnmarshalJSON

func (certainty *Certainty) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Certainty) UnmarshalText

func (certainty *Certainty) UnmarshalText(data []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (*Certainty) UnmarshalXML

func (certainty *Certainty) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements the xml.Unmarshaler interface.

type Circle

type Circle struct {
	Type        string    `json:"type"`
	Coordinates []float64 `json:"coordinates"`
	Radius      float64   `json:"radius"`
}

A Circle represents a circular area affected by an event.

type Circles

type Circles []*Circle

Circles represents multiple circles.

func (*Circles) MarshalXML

func (m *Circles) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements the xml.Marshaler interface.

func (*Circles) UnmarshalXML

func (m *Circles) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements the xml.Unmarshaler interface.

type Info

type Info struct {
	XMLName xml.Name `xml:"info" json:"-"`

	Language      string         `xml:"language" json:"language"`
	Categories    []Category     `xml:"category" json:"categories"`
	Event         string         `xml:"event" json:"event"`
	ResponseTypes []ResponseType `xml:"responseType" json:"response_types"`
	Urgency       Urgency        `xml:"urgency" json:"urgency"`
	Severity      Severity       `xml:"severity" json:"severity"`
	Certainty     Certainty      `xml:"certainty" json:"certainty"`
	Audience      string         `xml:"audience" json:"audience"`
	EventCodes    KeyValue       `xml:"eventCode" json:"event_codes"`
	Effective     *Time          `xml:"effective" json:"effective"`
	Onset         *Time          `xml:"onset" json:"onset"`
	Expires       *Time          `xml:"expires" json:"expires"`
	SenderName    string         `xml:"senderName" json:"sender_name"`
	Headline      string         `xml:"headline" json:"headline"`
	Description   string         `xml:"description" json:"description"`
	Instruction   string         `xml:"instruction" json:"instruction"`
	Web           string         `xml:"web" json:"web"`
	Contact       string         `xml:"contact" json:"contact"`
	Parameters    KeyValue       `xml:"parameter" json:"parameters"`
	Resources     []*Resource    `xml:"resource" json:"resources"`
	Areas         []*Area        `xml:"area" json:"areas"`
}

An Info represents the information section of an alert.

type KeyValue

type KeyValue map[string][]string

A KeyValue represents a set of key-value pairs.

func (*KeyValue) MarshalXML

func (m *KeyValue) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements the xml.Marshaler interface.

func (*KeyValue) UnmarshalXML

func (m *KeyValue) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML impelements the xml.Unmarshaler interface.

type List

type List []string

A List represents a list of string values.

func (*List) UnmarshalXML

func (m *List) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements the xml.Unmarshaler interface.

type MessageType

type MessageType int

A MessageType represents the nature of the alert message.

const (
	// MessageTypeUnknown represents an unknown message type.
	MessageTypeUnknown MessageType = iota

	// MessageTypeAlert represents initial information requiring attention by targeted recipients.
	MessageTypeAlert

	// MessageTypeUpdate represents updates and supercedes the earlier message(s) identified in Alert.References.
	MessageTypeUpdate

	// MessageTypeCancel represents a cancellation of the earlier message(s) identified in Alert.References.
	MessageTypeCancel

	// MessageTypeAck represents an acknowledgment receipt and acceptance of the message(s) identified in Alert.References.
	MessageTypeAck

	// MessageTypeError represents a rejection of the message(s) identified in Alert.References.
	MessageTypeError
)

func (MessageType) MarshalXML

func (messageType MessageType) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements the xml.Marshaler interface.

func (MessageType) String

func (messageType MessageType) String() string

String returns a MessageType as a string.

func (*MessageType) UnmarshalJSON

func (messageType *MessageType) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*MessageType) UnmarshalText

func (messageType *MessageType) UnmarshalText(data []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (*MessageType) UnmarshalXML

func (messageType *MessageType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements the xml.Unmarshaler interface.

type Polygon

type Polygon struct {
	Type        string        `json:"type"`
	Coordinates [][][]float64 `json:"coordinates"`
}

A Polygon represents an area affected by an event as a polygon.

func (*Polygon) UnmarshalXML

func (p *Polygon) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements the xml.Unmarshaler interface.

type Polygons

type Polygons []*Polygon

Polygons is a collection of polygons.

func (*Polygons) MarshalXML

func (m *Polygons) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements the xml.Marshaler interface.

type Reference

type Reference struct {
	Sender     string `json:"sender"`
	Identifier string `json:"identifier"`
	Sent       Time   `json:"sent"`
}

A Reference represents a the identifying information of another alert.

func (*Reference) ID

func (reference *Reference) ID() string

ID returns the ID of the referenced alert.

func (Reference) MarshalJSON

func (reference Reference) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

type References

type References []*Reference

References is an array of Reference.

func (*References) MarshalXML

func (m *References) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements the xml.Marshaler interface.

func (*References) UnmarshalXML

func (m *References) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements the xml.Unmarshaler interface.

type Resource

type Resource struct {
	XMLName xml.Name `xml:"resource" json:"-"`

	Description string `xml:"resourceDesc" json:"description"`
	MimeType    string `xml:"mimeType" json:"mime_type"`
	Size        int    `xml:"size" json:"size"`
	URI         string `xml:"uri" json:"uri"`
	Digest      string `xml:"digest" json:"digest"`
	DerefURI    string `xml:"derefUri" json:"deref_uri"`
}

A Resource represents a reference to additional information related to the Info segment. These are references to digital assets such as images or audio.

func (*Resource) Checksum

func (res *Resource) Checksum() string

Checksum returns the checksum value for the resource, if available. The Resource.Digest value is returned if provided. If no digest is available, it is calculated from the DerefURI value (if available). Otherwise, an empty string is returned.

type ResponseType

type ResponseType int

A ResponseType represents the type of action recommended.

const (
	// ResponseTypeUnknown represents an unknown response type.
	ResponseTypeUnknown ResponseType = iota

	// ResponseTypeShelter represents taking shelter in place or per the instruction.
	ResponseTypeShelter

	// ResponseTypeEvacuate represents replocating as instructed in the instruction.
	ResponseTypeEvacuate

	// ResponseTypePrepare represents making preparations per the intruction.
	ResponseTypePrepare

	// ResponseTypeExecute represents executing a pre-planned activity identified in the instruction.
	ResponseTypeExecute

	// ResponseTypeAvoid represents avoding the subject event as per the instruction.
	ResponseTypeAvoid

	// ResponseTypeMonitor represents attending to information sources as described in the instruction.
	ResponseTypeMonitor

	// ResponseTypeAssess represents evaluating the information in the mssage.
	ResponseTypeAssess

	// ResponseTypeAllClear represents that the subject event no longer poses a threat or concern and any follow on action is described in the instruction.
	ResponseTypeAllClear

	// ResponseTypeNone represents that no action recommended.
	ResponseTypeNone
)

func (ResponseType) MarshalXML

func (responseType ResponseType) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements the xml.Marshaler interface.

func (ResponseType) String

func (responseType ResponseType) String() string

String returns a ResponseType as a string.

func (*ResponseType) UnmarshalJSON

func (responseType *ResponseType) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*ResponseType) UnmarshalText

func (responseType *ResponseType) UnmarshalText(data []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (*ResponseType) UnmarshalXML

func (responseType *ResponseType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements the xml.Unmarshaler interface.

type Scope

type Scope int

A Scope represents the intended distribution of the alert message.

const (
	// ScopeUnknown represents an unknown scope.
	ScopeUnknown Scope = iota

	// ScopePublic represents an alert for general dissemination to unrestricted audiences.
	ScopePublic

	// ScopeRestricted represents an alert for dissemination only to users with a known operational requirement.
	ScopeRestricted

	// ScopePrivate represents an alert for dissemination only to specified addresses.
	ScopePrivate
)

func (Scope) MarshalXML

func (scope Scope) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements the xml.Marshaler interface.

func (Scope) String

func (scope Scope) String() string

String returns a Scope as a string.

func (*Scope) UnmarshalJSON

func (scope *Scope) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Scope) UnmarshalText

func (scope *Scope) UnmarshalText(data []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (*Scope) UnmarshalXML

func (scope *Scope) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements the xml.Unmarshaler interface.

type Severity

type Severity int

A Severity represents the severity of an event.

const (
	// SeverityUnknown represents an event with unknown certainty.
	SeverityUnknown Severity = iota

	// SeverityExtreme represents an event with extraordinary threat to life or property.
	SeverityExtreme

	// SeveritySevere represents an event with significant threat to life or property.
	SeveritySevere

	// SeverityModerate represents an event with possible threat to life or property.
	SeverityModerate

	// SeverityMinor represents an event with minimal to no known threat to life or property.
	SeverityMinor
)

func (Severity) MarshalXML

func (severity Severity) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements the xml.Marshaler interface.

func (Severity) String

func (severity Severity) String() string

String returns a Severity as a string.

func (*Severity) UnmarshalJSON

func (severity *Severity) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Severity) UnmarshalText

func (severity *Severity) UnmarshalText(data []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (*Severity) UnmarshalXML

func (severity *Severity) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements the xml.Unmarshaler interface.

type Status

type Status int

A Status represents the appropriate handling of the alert message.

const (
	// StatusUnknown represents an unknown status.
	StatusUnknown Status = iota

	// StatusActual represents an alert actionable by all targeted recipients.
	StatusActual

	// StatusExcercise represents an alert actionable only by desginated exercise participants.
	StatusExcercise

	// StatusSystem represents a message that supports alert network internal functions.
	StatusSystem

	// StatusTest represents technical testing only. All recipients should disregard.
	StatusTest

	// StatusDraft represents a perliminary template or draft. The alert is not actionable in its current form.
	StatusDraft
)

func (Status) MarshalXML

func (status Status) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements the xml.Marshaler interface.

func (Status) String

func (status Status) String() string

String returns a Status as a string.

func (*Status) UnmarshalJSON

func (status *Status) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Status) UnmarshalText

func (status *Status) UnmarshalText(data []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (*Status) UnmarshalXML

func (status *Status) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements the xml.Marshaler interface.

type Time

type Time struct {
	time.Time
}

A Time represents an instant in time.

func (Time) FormatCAP

func (time Time) FormatCAP() string

FormatCAP returns the time, formatted to Common Alert Protocol standards.

func (Time) MarshalXML

func (time Time) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements the xml.Marshaler interface.

type Urgency

type Urgency int

A Urgency represents the urgency of an event.

const (
	// UrgencyUnknown represents unknown urgency.
	UrgencyUnknown Urgency = iota

	// UrgencyImmediate represents that responsive action should be taken immediately.
	UrgencyImmediate

	// UrgencyExpected represents that responsive action should be taken soon (within the next hour).
	UrgencyExpected

	// UrgencyFuture represents that responsive action should be taken in the near future.
	UrgencyFuture

	// UrgencyPast represents that responsive action is no longer required.
	UrgencyPast
)

func (Urgency) MarshalXML

func (urgency Urgency) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements the xml.Marshaler interface.

func (Urgency) String

func (urgency Urgency) String() string

String returns a Urgency as a string.

func (*Urgency) UnmarshalJSON

func (urgency *Urgency) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Urgency) UnmarshalText

func (urgency *Urgency) UnmarshalText(data []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (*Urgency) UnmarshalXML

func (urgency *Urgency) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements the xml.Unmarshaler interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL