goseismic

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2023 License: MIT Imports: 5 Imported by: 0

README

goseismic

Travis CI Build Status

goseismic is library for receiving (near) realtime notifications about earthquakes using websockets from SeismicPortal. Using goseismic, received JSON message is parsed to goseismic.Event and sent to channel when an event is inserted or updated. Depending on the event, you can use bots, push notification etc. to further process the information.

Installation

go get -u github.com/h00s/goseismic

Usage

Information about earthquake events are sent in JSON thru websockets. This is example of one received event:

{
  "action":"create",
  "data":{
    "geometry":{
      "type":"Point",
      "coordinates":[
        -121.2,
        36.6,
        -4.0
      ]
    },
    "type":"Feature",
    "id":"20201230_0000082",
    "properties":{
      "lastupdate":"2020-12-30T08:47:00.0Z",
      "magtype":"md",
      "evtype":"ke",
      "lon":-121.2,
      "auth":"NC",
      "lat":36.6,
      "depth":4.0,
      "unid":"20201230_0000082",
      "mag":2.4,
      "time":"2020-12-30T08:45:29.9Z",
      "source_id":"934165",
      "source_catalog":"EMSC-RTS",
      "flynn_region":"CENTRAL CALIFORNIA"
    }
  }
}

Possible values for action are created or updated depending if it's new event or update on one of the previous events.

Received events are parsed and sent to Seismic.Events channel which you can read and further process. This is simple example how to receive events and display them (check example/main.go for comments):

package main

import (
	"log"
	"os"
	"os/signal"

	"github.com/h00s/goseismic"
)

func main() {
	s := goseismic.NewSeismic()
	s.Connect()
	defer s.Disconnect()

	interrupt := make(chan os.Signal, 1)
	signal.Notify(interrupt, os.Interrupt)

	for {
		select {
		case e := <-s.Events:
			log.Println(e)
		case <-interrupt:
			return
		}
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Action string `json:"action"`
	Data   struct {
		Geometry struct {
			Type        string     `json:"type"`
			Coordinates [3]float64 `json:"coordinates"`
		} `json:"geometry"`
		Type       string `json:"type"`
		ID         string `json:"id"`
		Properties struct {
			LastUpdate    time.Time `json:"lastupdate"`
			MagType       string    `json:"magtype"`
			EvType        string    `json:"evtype"`
			Longitude     float64   `json:"lon"`
			Auth          string    `json:"auth"`
			Latitude      float64   `json:"lat"`
			Depth         float64   `json:"depth"`
			UnID          string    `json:"unid"`
			Magnitude     float64   `json:"mag"`
			Time          time.Time `json:"time"`
			SourceID      string    `json:"source_id"`
			SourceCatalog string    `json:"source_catalog"`
			FlynnRegion   string    `json:"flynn_region"`
		} `json:"properties"`
	} `json:"data"`
}

Event represent one information obtained from seismic portal

{
  "action":"update",
  "data":{
    "geometry":{
      "type":"Point",
      "coordinates":[
        -121.2,
        36.6,
        -4.0
      ]
    },
    "type":"Feature",
    "id":"20201230_0000082",
    "properties":{
      "lastupdate":"2020-12-30T08:47:00.0Z",
      "magtype":"md",
      "evtype":"ke",
      "lon":-121.2,
      "auth":"NC",
      "lat":36.6,
      "depth":4.0,
      "unid":"20201230_0000082",
      "mag":2.4,
      "time":"2020-12-30T08:45:29.9Z",
      "source_id":"934165",
      "source_catalog":"EMSC-RTS",
      "flynn_region":"CENTRAL CALIFORNIA"
    }
  }
}

func ParseEvent

func ParseEvent(data []byte) (Event, error)

ParseEvent converts received message from websocket to Event struct

type Seismic

type Seismic struct {
	KeepAlive bool
	Debug     bool
	Events    chan Event
	// contains filtered or unexported fields
}

Seismic struct is type used for receiving events from websocket

func NewSeismic

func NewSeismic() *Seismic

NewSeismic creates new Seismic value which contains Event channel for receiving seismic events

func (*Seismic) Connect

func (s *Seismic) Connect() error

Connect connects to Seismic portal websocket

func (*Seismic) Disconnect

func (s *Seismic) Disconnect() error

Disconnect disconnects from Seismic portal websocket

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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