Skip to content

A Go library for interacting with Common Alerting Protocol v1.2 / v1.1 messages

License

Notifications You must be signed in to change notification settings

mark-adams/cap-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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>w-nws.webmaster@noaa.gov</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)
}

About

A Go library for interacting with Common Alerting Protocol v1.2 / v1.1 messages

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages