igcserver

package
v1.0.2-0...-70f893f Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2018 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTrackNotFound is returned if a request did not result in a TrackMeta
	ErrTrackNotFound = errors.New("track not found")

	// ErrTrackAlreadyExists is returned to request to add a track which
	// already exists
	ErrTrackAlreadyExists = errors.New("track already exists")
)
View Source
var (
	// ErrWebhookNotFound is returned if a request did not result in a webhook
	ErrWebhookNotFound = errors.New("webhook not found")

	// ErrWebhookAlreadyExists is returned to request to add a webhook which
	// already exists
	ErrWebhookAlreadyExists = errors.New("webhook already exists")
)
View Source
var (
	// ErrNoTracksFound symbolizes that there are no tracks to report the
	// timestamp on
	ErrNoTracksFound = errors.New("no tracks meeting criteria found")
)

Functions

This section is empty.

Types

type DiscordMsg

type DiscordMsg struct {
	Content string `json:"content"`
}

DiscordMsg is a webhook message that can be sent to discord

func NewDiscordMsg

func NewDiscordMsg(latest time.Time, ids []TrackID, processing time.Duration) DiscordMsg

NewDiscordMsg creates a new discord message using a template

type Server

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

Server distributes request to a pool of worker gorutines

func NewServer

func NewServer(httpClient *http.Client, trackMetas TrackMetas, ticker Ticker, webhooks Webhooks) (srv Server)

NewServer creates a new server which handles requests to the igc api

func (*Server) ServeHTTP

func (server *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Ticker

type Ticker interface {
	Latest() *time.Time
	Reporter(latest time.Time)
	GetReport(limit int) (TickerReport, error)
	GetReportAfter(timestamp time.Time, limit int) (TickerReport, error)
}

Ticker is a generic interface for any type which can act as a ticker

type TickerDB

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

TickerDB is a database-aware ticker instance

func NewTickerDB

func NewTickerDB(session *mgo.Session, buf int) TickerDB

NewTickerDB creates a new database-aware ticker instance

func (*TickerDB) GetReport

func (t *TickerDB) GetReport(limit int) (rep TickerReport, err error)

GetReport returns a report of the oldest registered timestamps with the given limit

func (*TickerDB) GetReportAfter

func (t *TickerDB) GetReportAfter(timestamp time.Time, limit int) (rep TickerReport, err error)

GetReportAfter returns a report after a specified time with the given limit

func (*TickerDB) Latest

func (t *TickerDB) Latest() *time.Time

Latest returns a channel which expects send the current latest timestamp on a request

func (*TickerDB) Reporter

func (t *TickerDB) Reporter(latest time.Time)

Reporter returns a channel which expects to have timestamps sent to it and it will listen to it and keep the current timestamp updated accordingly

type TickerReport

type TickerReport struct {
	Latest     time.Time     `json:"t_latest"`
	Start      time.Time     `json:"t_start"`
	End        time.Time     `json:"t_stop"`
	Tracks     []TrackID     `json:"tracks"`
	Processing time.Duration `json:"processing"`
}

TickerReport encompasses the report the ticker provides to the user

{ "t_latest": <latest added timestamp>, "t_start": <the first timestamp of the added track>, "t_stop": <the last timestamp of the added track>, "tracks": [<id1>, <id2>, ...], "processing": <time in ms of how long it took to process the request> }

type TrackID

type TrackID uint32

TrackID is a unique id for a track

func NewTrackID

func NewTrackID(v []byte) TrackID

NewTrackID creates a new unique track ID

type TrackMeta

type TrackMeta struct {
	ID          TrackID   `json:"-" bson:"id"`
	Timestamp   time.Time `json:"-" bson:"timestamp"`
	Date        time.Time `json:"H_date" bson:"H_date"`
	Pilot       string    `json:"pilot" bson:"pilot"`
	Glider      string    `json:"glider" bson:"glider"`
	GliderID    string    `json:"glider_id" bson:"glider_id"`
	TrackLength float64   `json:"track_length" bson:"track_length"`
	TrackSrcURL string    `json:"track_src_url" bson:"track_src_url"`
}

TrackMeta contains a subset of metainformation about a igc-track

func TrackMetaFrom

func TrackMetaFrom(url url.URL, track igc.Track) TrackMeta

TrackMetaFrom converts a igc.Track into a TrackMeta struct

type TrackMetas

type TrackMetas interface {
	Get(id TrackID) (TrackMeta, error)
	Append(meta TrackMeta) error
	GetAllIDs() ([]TrackID, error)
}

TrackMetas is a interface for all storages containing TrackMeta

type TrackMetasDB

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

TrackMetasDB contains a map to many TrackMeta objects which are protected by a RWMutex and indexed by a unique id

func NewTrackMetasDB

func NewTrackMetasDB(session *mgo.Session) TrackMetasDB

NewTrackMetasDB creates a new mutex and mapping from ID to TrackMeta

func (*TrackMetasDB) Append

func (metas *TrackMetasDB) Append(meta TrackMeta) (err error)

Append appends a track meta and returns the given id

func (*TrackMetasDB) Get

func (metas *TrackMetasDB) Get(id TrackID) (meta TrackMeta, err error)

Get fetches the track meta of a specific id if it exists

func (*TrackMetasDB) GetAllIDs

func (metas *TrackMetasDB) GetAllIDs() (ids []TrackID, err error)

GetAllIDs fetches all the stored ids

type TrackRegRequest

type TrackRegRequest struct {
	URLstr string `json:"url"`
}

TrackRegRequest is the format of a track registration request

type WebhookID

type WebhookID uint32

WebhookID is a unique id for a track

func NewWebhookID

func NewWebhookID(v []byte) WebhookID

NewWebhookID creates a new unique track ID

type WebhookInfo

type WebhookInfo struct {
	ID            WebhookID `json:"-" bson:"id"`
	URLstr        string    `json:"webhookURL" bson:"webhookURL"`
	TriggerRate   uint      `json:"minTriggerValue" bson:"minTriggerValue"`
	LastTriggered time.Time `json:"-" bson:"lastTriggered"`
}

WebhookInfo contains information about a webhook

type Webhooks

type Webhooks interface {
	Trigger()
	Get(id WebhookID) (WebhookInfo, error)
	Append(webhook WebhookInfo) error
	Delete(id WebhookID) (WebhookInfo, error)
}

Webhooks is a interface for all storages containing WebhookInfo

type WebhooksDB

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

WebhooksDB contains a map to many WebhookInfo objects which are protected by a RWMutex and indexed by a unique id

func NewWebhooksDB

func NewWebhooksDB(session *mgo.Session, httpClient *http.Client) WebhooksDB

NewWebhooksDB creates a new mutex and mapping from ID to WebhookInfo

func (*WebhooksDB) Append

func (db *WebhooksDB) Append(webhook WebhookInfo) (err error)

Append appends a track webhook and returns the given id

func (*WebhooksDB) Delete

func (db *WebhooksDB) Delete(id WebhookID) (webhook WebhookInfo, err error)

Delete removes a webhook

func (*WebhooksDB) Get

func (db *WebhooksDB) Get(id WebhookID) (webhook WebhookInfo, err error)

Get fetches the track webhook of a specific id if it exists

func (*WebhooksDB) Trigger

func (db *WebhooksDB) Trigger()

Trigger returns a channel to trigger webhooks based on the number of tracks

Jump to

Keyboard shortcuts

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