Skip to content

Latest commit

 

History

History
74 lines (56 loc) · 1.98 KB

README.md

File metadata and controls

74 lines (56 loc) · 1.98 KB

cap-go

Build Status Coverage Status

A Go library for interacting with Common Alerting Protocol messages

The Common Alerting Protocol (CAP) is a simple but general format for exchanging all-hazard emergency alerts and public warnings over all kinds of networks.

The CAP specification can be found on the OASIS website.

Examples

Retrieving the CAP feed from NWS

package main

import (
    "fmt"
    "github.com/mark-adams/cap-go/cap"
)

func main(){
    feed, err := GetNWSAtomFeed()

    if err != nil {
        fmt.Errorf(err.Error())
        os.Exit(1)
    }

    fmt.Println(feed.ID)
}

Parsing a CAP alert

package main

import (
    "fmt"
    "github.com/mark-adams/cap-go/cap"
)

func main(){
    xmlData := []byte(`<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
        <alert xmlns='urn:oasis:names:tc:emergency:cap:1.2'>
            <identifier>NOAA-NWS-ALERTS-AR1253BA3B00A4.FloodWarning.1253BA3D4A94AR.LZKFLSLZK.342064b5a5aafb8265dfc3707d6a3b09</identifier>
            <sender>[email protected]</sender>
            <sent>2015-08-15T20:45:00-05:00</sent>
            <status>Actual</status>
            <msgType>Alert</msgType>
            <scope>Public</scope>
            <info>
                <category>Met</category>
                <event>Flood Warning</event>
                <urgency>Expected</urgency>
                <severity>Moderate</severity>
                <certainty>Likely</certainty>
            </info>
        </alert>`)

    alert, err := ParseAlert(xmlData)

    if err != nil {
        fmt.Errorf(err.Error())
        os.Exit(1)
    }

    fmt.Println(alert.MessageID)
    fmt.Println(alert.Infos[0].EventType)
}