EDDNClient

package module
v0.0.0-...-f499cba Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2017 License: BSD-2-Clause-Views Imports: 14 Imported by: 0

README

A Go interface to EDDN.

Go Report Card GoDoc

Install

go get github.com/mbsmith/EDDNClient

Docs

Special Thanks

Just some gratitude to those that have helped me navigate this ever growing eco-system along the way!

Documentation

Overview

Package EDDNClient provides an interface to EDDN. Currently it only provides subscriber support, but other features will be added in the future.

Index

Examples

Constants

View Source
const (
	FilterNone        = 1 << iota // Filter nothing
	FilterJournal     = 1 << iota // Filter journal messages
	FilterShipyard    = 1 << iota // Filter shipyard messages
	FilterCommodity   = 1 << iota // Filter commodity messages
	FilterBlackmarket = 1 << iota // Filter blackmarket messages
	FilterOutfitting  = 1 << iota // Filter outfitting messages.
)

An enumeration of filters used to tell the ChannelInterface what data the receiver is interested in. These can be OR'd together to build any filter the receiver wishes.

View Source
const EDDNSubAddress = "tcp://eddn-relay.elite-markets.net:9500"

EDDNSubAddress is a simple constant for the ZeroMQ relay used by EDDN.

View Source
const EDDNUploadAddress = "http://eddn-gateway.elite-markets.net:8080/upload/"

EDDNUploadAddress is a simple constant for the EDDN POST URI.

Variables

This section is empty.

Functions

func GenerateUTCDateTime

func GenerateUTCDateTime() (timeString string)

GenerateUTCDateTime is a helper function for generating RFC3339Nano time strings.

func Version

func Version() (major int, minor int, revision int)

Version is a simple function that returns the major, minor, and revision versions.

Types

type Blackmarket

type Blackmarket struct {
	SchemaRef string             `json:"$schemaRef"`
	Header    Header             `json:"header"`
	Message   BlackmarketMessage `json:"message"`
}

Blackmarket is the high level type that contains the entire JSON message.

type BlackmarketMessage

type BlackmarketMessage struct {
	Name        string `json:"name"`        // Required
	Prohibited  bool   `json:"prohibited"`  // Required
	SellPrice   int    `json:"sellPrice"`   // Required
	StationName string `json:"stationName"` // Required
	SystemName  string `json:"systemName"`  // Required
	Timestamp   string `json:"timestamp"`   // Required
}

BlackmarketMessage contains the blackmarket data sent to EDDN.

type ChannelInterface

type ChannelInterface struct {
	Socket          *zmq.Socket        // Underlying ZeroMQ socket
	JournalChan     <-chan Journal     // Channel for journal messages. (Provides many message types.)
	ShipyardChan    <-chan Shipyard    // Channel for reading shipyard messages
	CommodityChan   <-chan Commodity   // Channel for reading commodity messages
	BlackmarketChan <-chan Blackmarket // Channel for reading blackmarket messages
	OutfittingChan  <-chan Outfitting  // Channel for reading outfitting messages
	ControlChan     chan<- int         // Channel providing goroutine control
	Done            chan bool          // Sent when the ChannelInterface is done.
}

A ChannelInterface provides an interface to a group of channels that each provide various types of EDDN data separated into their respective channels. JournalChan, ShipyardChan, CommodityChan, BlackmarketChan, and OutfittingChan each only send messages pertaining to their respective types. When a Done message is received all processing on the receiver should halt as this means that the ChannelInterface is closed.

It should be noted that the Journal channel can send several types that must be asserted by the caller. While this may be a bit tedious it does provide type correctness, and allows the caller to know precisely what data was provided by EDDN.

Example
package main

import (
	"fmt"
	eddn "github.com/mbsmith/EDDNClient"
	"log"
)

func main() {
	// Create a new channel interface that filters everything but journal
	// messages.
	channelInterface, err := eddn.NewChannelInterface(eddn.FilterShipyard |
		eddn.FilterCommodity | eddn.FilterOutfitting | eddn.FilterBlackmarket)

	if err != nil {
		log.Fatalf("Error: %v\n", err)
	}

loop:
	for {

		// Get a single journal message and then close/exit.
		select {
		case journalMsg := <-channelInterface.JournalChan:
			fmt.Printf("Schema: %v", journalMsg.SchemaRef)
			break loop
		}

	}

	channelInterface.Close()

}
Output:

Schema: http://schemas.elite-markets.net/eddn/journal/1

func NewChannelInterface

func NewChannelInterface(filter int) (channels *ChannelInterface, err error)

NewChannelInterface creates an active ChannelInterface using the provided filter. If one wishes no filters then 0, or FilterNone can be passed here. If an error is found then err will not be nil and shall be returned. The ChannelInterface will be active immediately and must be stopped with Close() if the receiver wishes to stop receiving messages.

Should the receiver wish to begin receiving messages again then a new ChannelInterface must be created.

func (*ChannelInterface) Close

func (ci *ChannelInterface) Close()

Close closes the given ChannelInterface ci.

type Commodities

type Commodities struct {
	BuyPrice      int      `json:"buyPrice"`
	Demand        int      `json:"demand"`
	DemandBracket int      `json:"demandBracket"`
	MeanPrice     int      `json:"meanPrice"`
	Name          string   `json:"name"`
	SellPrice     int      `json:"sellPrice"`
	StatusFlags   []string `json:"statusFlags,omitempty"`
	Stock         int      `json:"stock"`
	StockBracket  int      `json:"stockBracket"`
}

Commodities describes various commodities sent in a Message.

type Commodity

type Commodity struct {
	SchemaRef string           `json:"$schemaRef"`
	Header    Header           `json:"header"`
	Message   CommodityMessage `json:"message"`
}

Commodity is the high level type that contains the entire JSON message.

type CommodityMessage

type CommodityMessage struct {
	Commodities []Commodities `json:"commodities"` // Required
	StationName string        `json:"stationName"` // Required
	SystemName  string        `json:"systemName"`  // Required
	Timestamp   string        `json:"timestamp"`   // Required
}

CommodityMessage contains the commodity data sent to EDDN.

type Composition

type Composition struct {
	Name    string  `mapstructure:"Name" json:"Name"`
	Percent float64 `mapstructure:"Percent" json:"Percent"`
}

Composition describes atmospheric composition that may or may not be included in a journal Message.

type Faction

type Faction struct {
	Allegiance   string  `mapstructure:"Allegiance" json:"Allegiance"`
	FactionState string  `mapstructure:"FactionState" json:"FactionState"`
	Government   string  `mapstructure:"Government" json:"Government"`
	Influence    float32 `mapstructure:"Influence" json:"Influence"`
	Name         string  `mapstructure:"Name" json:"Name"`
}

Faction describes an individual faction that may or may not be included in the journal Message.

type Header struct {
	GatewayTimestamp string `json:"gatewayTimestamp,omitempty"` // Timestamp
	SoftwareName     string `json:"softwareName"`               // Software that sent the data
	SoftwareVersion  string `json:"softwareVersion"`            // Software version
	UploaderID       string `json:"uploaderID"`                 // ID of the uploader
}

Header type that is common to all messages. This bit is only used by the parser however. The types sent by the ChannelInterface will have their own Root/Header types that the receiver should use.

type Journal

type Journal struct {
	SchemaRef string      `json:"$schemaRef"`
	Header    Header      `json:"header"`
	Message   interface{} `json:"message"`
}

Journal is the high level type that contains the entire JSON message.

type JournalDocked

type JournalDocked struct {
	StarSystem        string    `mapstructure:"StarSystem" json:"StarSystem"`
	StationFaction    string    `mapstructure:"StationFaction" json:"StationFaction"`
	StationGovernment string    `mapstructure:"StationGovernment" json:"StationGovernment"`
	Timestamp         string    `mapstructure:"timestamp" json:"timestamp"`
	StationAllegiance string    `mapstructure:"StationAllegiance" json:"StationAllegiance"`
	StationEconomy    string    `mapstructure:"StationEconomy" json:"StationEconomy"`
	StarPos           []float64 `mapstructure:"StarPos" json:"StarPos"`
	StationName       string    `mapstructure:"StationName" json:"StationName"`
	StationType       string    `mapstructure:"StationType" json:"StationType"`
	DistFromStarLS    float64   `mapstructure:"DistFromStarLS" json:"DistFromStarLS"`
	FactionState      string    `mapstructure:"FactionState" json:"FactionState"`
	Event             string    `mapstructure:"event" json:"event"`
}

JournalDocked contains information pertaining to a 'docked' event. This is missing the 'Security' field, but it seems to mostly go unused with this event so it's omitted for now.

type JournalFSDJump

type JournalFSDJump struct {
	StarSystem       string    `mapstructure:"StarSystem" json:"StarSystem"`
	Timestamp        string    `mapstructure:"timestamp" json:"timestamp"`
	Event            string    `mapstructure:"event" json:"event"`
	SystemSecurity   string    `mapstructure:"SystemSecurity" json:"SystemSecurity"`
	SystemAllegiance string    `mapstructure:"SystemAllegiance" json:"SystemAllegiance"`
	SystemEconomy    string    `mapstructure:"SystemEconomy" json:"SystemEconomy"`
	StarPos          []float64 `mapstructure:"StarPos" json:"StarPos"`
	SystemGovernment string    `mapstructure:"SystemGovernment" json:"SystemGovernment"`
}

JournalFSDJump contains information about a system after a frameshift jump is performed.

type JournalScanPlanet

type JournalScanPlanet struct {
	Eccentricity          float64    `mapstructure:"Eccentricity" json:"Eccentricity"`
	OrbitalInclination    float64    `mapstructure:"OrbitalInclination" json:"OrbitalInclination"`
	OrbitalPeriod         float64    `mapstructure:"OrbitalPeriod" json:"OrbitalPeriod"`
	Periapsis             float64    `mapstructure:"Periapsis" json:"Periapsis"`
	SemiMajorAxis         float64    `mapstructure:"SemiMajorAxis" json:"SemiMajorAxis"`
	BodyName              string     `mapstructure:"BodyName" json:"BodyName"`
	DistanceFromArrivalLS float64    `mapstructure:"DistanceFromArrivalLS" json:"DistanceFromArrivalLS"`
	TidalLock             bool       `mapstructure:"TidalLock" json:"TidalLock"`
	TerraformState        string     `mapstructure:"TerraformState" json:"TerraformState"`
	PlanetClass           string     `mapstructure:"PlanetClass" json:"PlanetClass"`
	SurfacePressure       float64    `mapstructure:"SurfacePressure" json:"SurfacePressure"`
	MassEM                float64    `mapstructure:"MassEM" json:"MassEM"`
	RotationPeriod        float64    `mapstructure:"RotationPeriod" json:"RotationPeriod"`
	Event                 string     `mapstructure:"event" json:"event"`
	StarPos               []float64  `mapstructure:"StarPos" json:"StarPos"`
	AtmosphereType        string     `mapstructure:"AtmosphereType" json:"AtmosphereType"`
	SurfaceTemperature    float64    `mapstructure:"SurfaceTemperature" json:"SurfaceTemperature"`
	Timestamp             string     `mapstructure:"timestamp" json:"timestamp"`
	Materials             []Material `mapstructure:"Materials" json:"Materials"`
	Volcanism             string     `mapstructure:"Volcanism" json:"Volcanism"`
	StarSystem            string     `mapstructure:"StarSystem" json:"StarSystem"`
	Atmosphere            string     `mapstructure:"Atmosphere" json:"Atmosphere"`
	Landable              bool       `mapstructure:"Landable" json:"Landable"`
	Radius                float64    `mapstructure:"Radius" json:"Radius"`
	SurfaceGravity        float64    `mapstructure:"SurfaceGravity" json:"SurfaceGravity"`
}

JournalScanPlanet contains information about a scanned moon, or planet. This is used when a journal entry does NOT have a StarType field. If it does then a JournalScanStar type will be used.

type JournalScanStar

type JournalScanStar struct {
	StellarMass           float64   `mapstructure:"StellarMass" json:"StellarMass"`
	BodyName              string    `mapstructure:"BodyName" json:"BodyName"`
	StarSystem            string    `mapstructure:"StarSystem" json:"StarSystem"`
	Timestamp             string    `mapstructure:"timestamp" json:"timestamp"`
	RotationPeriod        float64   `mapstructure:"RotationPeriod" json:"RotationPeriod"`
	Rings                 []Ring    `mapstructure:"Rings" json:"Rings"`
	StarType              string    `mapstructure:"StarType" json:"StarType"`
	Radius                float64   `mapstructure:"Radius" json:"Radius"`
	AbsoluteMagnitude     float64   `mapstructure:"AbsoluteMagnitude" json:"AbsoluteMagnitude"`
	StarPos               []float64 `mapstructure:"StarPos" json:"StarPos"`
	AgeMy                 int       `mapstructure:"Age_MY" json:"Age_MY"`
	Event                 string    `mapstructure:"event" json:"event"`
	DistanceFromArrivalLS float64   `mapstructure:"DistanceFromArrivalLS" json:"DistanceFromArrivalLS"`
	SurfaceTemperature    float64   `mapstructure:"SurfaceTemperature" json:"SurfaceTemperature"`
	Eccentricity          float64   `mapstructure:"Eccentricity" json:"Eccentricity"`
	OrbitalInclination    float64   `mapstructure:"OrbitalInclination" json:"OrbitalInclination"`
	OrbitalPeriod         float64   `mapstructure:"OrbitalPeriod" json:"OrbitalPeriod"`
	Periapsis             float64   `mapstructure:"Periapsis" json:"Periapsis"`
	SemiMajorAxis         float64   `mapstructure:"SemiMajorAxis" json:"SemiMajorAxis"`
}

JournalScanStar contains information about a scanned star. This is used when a journal entry has a StarType field. Barring that a JournalScanPlanet type will be used.

type Material

type Material struct {
	Name    string  `mapstructure:"Name" json:"Name"`
	Percent float64 `mapstructure:"Percent" json:"Percent"`
}

Material describes the name, and percentage contained on a planet, or moon.

type Outfitting

type Outfitting struct {
	SchemaRef string            `json:"$schemaRef"`
	Header    Header            `json:"header"`
	Message   OutfittingMessage `json:"message"`
}

Outfitting is the high level type that contains the entire JSON message.

type OutfittingMessage

type OutfittingMessage struct {
	Modules     []string `json:"modules"`     // Required
	StationName string   `json:"stationName"` // Required
	SystemName  string   `json:"systemName"`  // Required
	Timestamp   string   `json:"timestamp"`   // Required
}

OutfittingMessage contains the outfitting data sent to EDDN.

type Ring

type Ring struct {
	InnerRad  float64 `mapstructure:"InnerRad" json:"InnerRad"`
	MassMT    float64 `mapstructure:"MassMT" json:"MassMT"`
	Name      string  `mapstructure:"Name" json:"Name"`
	OuterRad  float64 `mapstructure:"OuterRad" json:"OuterRad"`
	RingClass string  `mapstructure:"RingClass" json:"RingClass"`
}

Ring describes planetary rings of a body that may or may not be included in a journal message.

type Root

type Root struct {
	SchemaRef string          `json:"$schemaRef"` // The schema of the message
	Header    Header          `json:"header"`     // The message header
	Message   json.RawMessage `json:"message"`    // The message unparsed until later
}

Root is the root of every JSON message received from EDDN. This should not be used directly as this is lazily parsed to find the schema first.

type Shipyard

type Shipyard struct {
	SchemaRef string          `json:"$schemaRef"`
	Header    Header          `json:"header"`
	Message   ShipyardMessage `json:"message"`
}

Shipyard is the high level type that contains the entire JSON message.

type ShipyardMessage

type ShipyardMessage struct {
	Ships       []string `json:"ships"`       // Required
	StationName string   `json:"stationName"` // Required
	SystemName  string   `json:"systemName"`  // Required
	Timestamp   string   `json:"timestamp"`   // Required
}

ShipyardMessage contains the shipyard data sent to EDDN.

type Uploader

type Uploader struct {
	// contains filtered or unexported fields
}

Uploader is a helper type (required) that keeps track of the header, and other potential portions of data that don't need to be regenerated after each message. It also updates its timestamp internally on each message so it shouldn't ever be off time.

func NewUploader

func NewUploader(uploaderID string, softwareName string,
	softwareVersion string) (uploader *Uploader, err error)

NewUploader creates a new Uploader that will be used to send various types of messages. uploaderID, softwareName, and softwareVersion should be set to values that you want represented in the header of every message you send.

func (*Uploader) SendBlackmarket

func (uploader *Uploader) SendBlackmarket(msg *BlackmarketMessage) (err error)

SendBlackmarket sends a blackmarket message to the EDDN servers. The message should be filled (especially the required fields). The required fields are marked in the blackmarket.go source file.

func (*Uploader) SendCommodity

func (uploader *Uploader) SendCommodity(msg *CommodityMessage) (err error)

SendCommodity sends a commodity message to the EDDN servers. The message should be filled (especially the required fields). The required fields are marked in the commodity.go source file.

func (*Uploader) SendJournalDocked

func (uploader *Uploader) SendJournalDocked(msg *JournalDocked) (err error)

SendJournalDocked sends a Docked message to the EDDN servers. The message should be filled (especially the required fields). The required fields are marked in the journal.go source file.

func (*Uploader) SendJournalFSDJump

func (uploader *Uploader) SendJournalFSDJump(msg *JournalFSDJump) (err error)

SendJournalFSDJump sends a FSDJump message to the EDDN servers. The message should be filled (especially the required fields). The required fields are marked in the journal.go source file.

func (*Uploader) SendJournalScanPlanet

func (uploader *Uploader) SendJournalScanPlanet(msg *JournalScanPlanet) (err error)

SendJournalScanPlanet sends a planet Scan message to the EDDN servers. The message should be filled (especially the required fields). The required fields are marked in the journal.go source file.

func (*Uploader) SendJournalScanStar

func (uploader *Uploader) SendJournalScanStar(msg *JournalScanStar) (err error)

SendJournalScanStar sends a star Scan message to the EDDN servers. The message should be filled (especially the required fields). The required fields are marked in the journal.go source file.

func (*Uploader) SendOutfitting

func (uploader *Uploader) SendOutfitting(msg *OutfittingMessage) (err error)

SendOutfitting sends a outfitting message to the EDDN servers. The message should be filled (especially the required fields). The required fields are marked in the outfitting.go source file.

func (*Uploader) SendShipyard

func (uploader *Uploader) SendShipyard(msg *ShipyardMessage) (err error)

SendShipyard sends a shipyard message to the EDDN servers. The message should be filled (especially the required fields). The required fields are marked in the shipyard.go source file.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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