ais

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsEOF added in v0.0.2

func IsEOF(err error) bool

IsEOF returns true iff the supplied error is an EOF error (i.e. signals the end of a stream).

Types

type AisMultiple

type AisMultiple struct {
	Type responsetype.Ais
	Position
	Aton
	Staticdata
}

AisMultiple holds a union of the multiple response types that an AIS data request can return. Use the Type property to inspect which type the message is.

func (AisMultiple) AsAton

func (a AisMultiple) AsAton() Aton

AsAton returns the underlying Aton response data if the response is of the correct type, and a zero (default-valued) Aton struct otherwise.

func (AisMultiple) AsPosition

func (a AisMultiple) AsPosition() Position

AsPosition returns the underlying Position response data if the response is of the correct type, and a zero (default-valued) Position struct otherwise.

func (AisMultiple) AsStaticdata

func (a AisMultiple) AsStaticdata() Staticdata

AsStaticdata returns the underlying Staticdata response data if the response is of the correct type, and a zero (default-valued) Staticdata struct otherwise.

func (AisMultiple) IsZero

func (a AisMultiple) IsZero() bool

IsZero is true iff the receiver is a default-valued AisMultiple struct.

func (*AisMultiple) UnmarshalJSON

func (a *AisMultiple) UnmarshalJSON(data []byte) error

type ApiError

type ApiError struct {
	Type    string `json:"type"`
	Title   string `json:"title"`
	Status  int    `json:"status"`
	TraceId string `json:"traceId"`
}

ApiError is an error supplied by the API.

Note that the error type is undocumented in the Swagger documentation (as of 2023-02-28).

type Aton

type Aton struct {
	MessageType                  int       `json:"messageType"`
	Mmsi                         int       `json:"mmsi"`
	Msgtime                      time.Time `json:"msgtime"`
	Longitude                    *float64  `json:"longitude"`
	Latitude                     *float64  `json:"latitude"`
	Name                         string    `json:"name"`
	DimensionA                   *int      `json:"dimensionA"`
	DimensionB                   *int      `json:"dimensionB"`
	DimensionC                   *int      `json:"dimensionC"`
	DimensionD                   *int      `json:"dimensionD"`
	TypeOfAidsToNavigation       int       `json:"typeOfAidsToNavigation"`
	TypeOfElectronicFixingDevice int       `json:"typeOfElectronicFixingDevice"`
}

Aton

Verified in private communication Jan 24 2023.

func (Aton) IsZero

func (a Aton) IsZero() bool

IsZero is true iff the receiver is a default-valued Aton struct.

type CancelFunc

type CancelFunc func()

type Client

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

Client is the main workhorse of the http package. It contains configurations for authenticating with Barentswatch' API, and the documented API methods.

A client must be constructed with the NewClient factory function.

func NewClient

func NewClient(clientId string, clientSecret string, urls ...URLs) *Client

NewClient creates a new Client.

It must be called with the user's OAuth client ID and client secret, which can be obtained from Barentswatch. Optionally you can supply a single set of URLs to override the default URLs for the API endpoints. Do not supply more than zero or one set of URLs.

func (*Client) GetAis

func (c *Client) GetAis() (StreamResponse[AisMultiple], error)

GetAis carries out GET against /v1/ais

func (*Client) GetAisContext

func (c *Client) GetAisContext(ctx context.Context) (StreamResponse[AisMultiple], error)

GetAisContext carries out GET against /v1/ais with a context for cancellation.

func (*Client) GetCombined

func (c *Client) GetCombined() (StreamResponse[CombinedSimpleJson], error)

GetCombined carries out GET against /v1/combined

func (*Client) GetCombinedContext

func (c *Client) GetCombinedContext(ctx context.Context) (StreamResponse[CombinedSimpleJson], error)

GetCombinedContext carries out GET against /v1/combined with a context for cancellation.

func (*Client) GetLatestAis

func (c *Client) GetLatestAis(opts ...option.Option) (Response[[]AisMultiple], error)

GetLatestAis carries out GET against /v1/latest/ais

func (*Client) GetLatestAisContext

func (c *Client) GetLatestAisContext(ctx context.Context, opts ...option.Option) (Response[[]AisMultiple], error)

GetLatestAisContext carries out GET against /v1/latest/ais with a context for cancellation.

func (*Client) GetLatestCombined

func (c *Client) GetLatestCombined(opts ...option.Option) (Response[[]CombinedSimpleJson], error)

GetLatestCombined carries out GET against /v1/latest/combined

func (*Client) GetLatestCombinedContext

func (c *Client) GetLatestCombinedContext(ctx context.Context, opts ...option.Option) (Response[[]CombinedSimpleJson], error)

GetLatestCombinedContext carries out GET against /v1/latest/combined with a context for cancellation.

func (*Client) GetOpenAisArea

func (c *Client) GetOpenAisArea(ctx context.Context) (Response[geojson.Geometry], error)

GetOpenAisArea carries out GET against /v1/openaisarea with a context for cancellation.

func (*Client) GetSSEAis

func (c *Client) GetSSEAis() (StreamResponse[AisMultiple], error)

GetSSEAis carries out GET against /v1/sse/ais

func (*Client) GetSSEAisContext

func (c *Client) GetSSEAisContext(ctx context.Context) (StreamResponse[AisMultiple], error)

GetSSEAisContext carries out GET against /v1/sse/ais with a context for cancellation.

func (*Client) GetSSECombined

func (c *Client) GetSSECombined() (StreamResponse[CombinedSimpleJson], error)

GetSSECombined carries out GET against /v1/combined

func (*Client) GetSSECombinedContext

func (c *Client) GetSSECombinedContext(ctx context.Context) (StreamResponse[CombinedSimpleJson], error)

GetSSECombinedContext carries out GET against /v1/combined with a context for cancellation.

func (*Client) PostAis

func (c *Client) PostAis(filterInput FilterInput) (StreamResponse[AisMultiple], error)

PostAis carries out POST against /v1/ais

func (*Client) PostAisContext

func (c *Client) PostAisContext(ctx context.Context, filterInput FilterInput) (StreamResponse[AisMultiple], error)

PostAisContext carries out POST against /v1/ais with a context for cancellation.

func (*Client) PostCombined

func (c *Client) PostCombined(filterInput CombinedFilterInput) (StreamResponse[CombinedMultiple], error)

PostCombined carries out POST against /v1/combined

func (*Client) PostCombinedContext

func (c *Client) PostCombinedContext(ctx context.Context, filterInput CombinedFilterInput) (StreamResponse[CombinedMultiple], error)

PostCombinedContext carries out POST against /v1/combined with a context for cancellation.

func (*Client) PostLatestAis

func (c *Client) PostLatestAis(filter LatestAisFilterInput) (Response[[]AisMultiple], error)

PostLatestAis carries out POST against /v1/latest/ais.

func (*Client) PostLatestAisContext

func (c *Client) PostLatestAisContext(ctx context.Context, filter LatestAisFilterInput) (Response[[]AisMultiple], error)

PostLatestAisContext carries out POST against /v1/latest/ais with a context for cancellation.

func (*Client) PostSSEAis

func (c *Client) PostSSEAis(filterInput FilterInput) (StreamResponse[AisMultiple], error)

func (*Client) PostSSEAisContext

func (c *Client) PostSSEAisContext(ctx context.Context, filterInput FilterInput) (StreamResponse[AisMultiple], error)

PostSSEAisContext carries out POST against /v1/sse/ais with a context for cancellation.

func (*Client) PostSSECombined

func (c *Client) PostSSECombined(filterInput CombinedFilterInput) (StreamResponse[CombinedMultiple], error)

PostSSECombined carries out POST against /v1/combined

func (*Client) PostSSECombinedContext

func (c *Client) PostSSECombinedContext(ctx context.Context, filterInput CombinedFilterInput) (StreamResponse[CombinedMultiple], error)

PostSSECombinedContext carries out POST against /v1/combined with a context for cancellation.

type CombinedFilterInput

type CombinedFilterInput struct {
	Geometry     *geojson.Geometry         `json:"geometry"`
	Since        *time.Time                `json:"since"`
	MMSI         *int                      `json:"mmsi"`
	ShipTypes    []shiptype.ShipType       `json:"shipTypes"`
	CountryCodes []countrycode.CountryCode `json:"countryCodes"`
	ModelType    modeltype.ModelType       `json:"modelType"`
	ModelFormat  modelformat.ModelFormat   `json:"modelFormat"`
	Downsample   bool                      `json:"downsample"`
}

CombinedFilterInput is Ais.LiveApi.Api.AisMessage.Models.CombinedFilterInput

type CombinedFullGeojson

type CombinedFullGeojson struct {
	Type     string `json:"type"`
	Geometry struct {
		Type        string    `json:"type"`
		Coordinates []float64 `json:"coordinates"`
	} `json:"geometry"`
	Properties struct {
		Mmsi                     int       `json:"mmsi"`
		Name                     string    `json:"name"`
		Msgtime                  time.Time `json:"msgtime"`
		SpeedOverGround          *float64  `json:"speedOverGround"`
		CourseOverGround         *float64  `json:"courseOverGround"`
		NavigationalStatus       int       `json:"navigationalStatus"`
		RateOfTurn               *float64  `json:"rateOfTurn"`
		ShipType                 *int      `json:"shipType"`
		TrueHeading              *int      `json:"trueHeading"`
		CallSign                 string    `json:"callSign"`
		Destination              string    `json:"destination"`
		Eta                      string    `json:"eta"`
		ImoNumber                *int      `json:"imoNumber"`
		DimensionA               *int      `json:"dimensionA"`
		DimensionB               *int      `json:"dimensionB"`
		DimensionC               *int      `json:"dimensionC"`
		DimensionD               *int      `json:"dimensionD"`
		Draught                  *int      `json:"draught"`
		ShipLength               *int      `json:"shipLength"`
		ShipWidth                *int      `json:"shipWidth"`
		PositionFixingDeviceType int       `json:"positionFixingDeviceType"`
		ReportClass              string    `json:"reportClass"`
	} `json:"properties"`
}

CombinedFullGeojson is a response to Combined when requesting ModelType "Full" and ModelFormat "Geojson"

func (CombinedFullGeojson) IsZero

func (a CombinedFullGeojson) IsZero() bool

IsZero is true iff the receiver is a default-valued CombinedFullJson struct.

type CombinedFullJson

type CombinedFullJson struct {
	CourseOverGround         *float64  `json:"courseOverGround"`
	Latitude                 *float64  `json:"latitude"`
	Longitude                *float64  `json:"longitude"`
	Name                     string    `json:"name"`
	RateOfTurn               *float64  `json:"rateOfTurn"`
	ShipType                 *int      `json:"shipType"`
	SpeedOverGround          *float64  `json:"speedOverGround"`
	TrueHeading              *int      `json:"trueHeading"`
	Mmsi                     int       `json:"mmsi"`
	Msgtime                  time.Time `json:"msgtime"`
	Altitude                 *int      `json:"altitude"`
	NavigationalStatus       int       `json:"navigationalStatus"`
	ImoNumber                *int      `json:"imoNumber"`
	CallSign                 string    `json:"callSign"`
	Destination              string    `json:"destination"`
	Eta                      string    `json:"eta"`
	Draught                  *int      `json:"draught"`
	ShipLength               *int      `json:"shipLength"`
	ShipWidth                *int      `json:"shipWidth"`
	DimensionA               *int      `json:"dimensionA"`
	DimensionB               *int      `json:"dimensionB"`
	DimensionC               *int      `json:"dimensionC"`
	DimensionD               *int      `json:"dimensionD"`
	PositionFixingDeviceType int       `json:"positionFixingDeviceType"`
	ReportClass              string    `json:"reportClass"`
}

CombinedFullJson is a response to Combined when requesting ModelType "Full" and ModelFormat "Json"

func (CombinedFullJson) IsZero

func (a CombinedFullJson) IsZero() bool

IsZero is true iff the receiver is a default-valued CombinedFullJson struct.

type CombinedMultiple

CombinedMultiple is a response which can be either CombinedSimpleJson, CombinedFullJson, CombinedSimpleGeojson or CombinedFullGeojson. Which one it is depends on what was requested by the user, and must be checked on use.

func (CombinedMultiple) AsFullGeojson

func (c CombinedMultiple) AsFullGeojson() CombinedFullGeojson

AsFullGeojson returns the underlying CombinedFullGeojson response data if the response is of the correct type, and a zero (default-valued) CombinedFullGeojson struct otherwise.

func (CombinedMultiple) AsFullJson

func (c CombinedMultiple) AsFullJson() CombinedFullJson

AsFullJson returns the underlying CombinedFullJson response data if the response is of the correct type, and a zero (default-valued) CombinedFullJson struct otherwise.

func (CombinedMultiple) AsSimpleGeojson

func (c CombinedMultiple) AsSimpleGeojson() CombinedSimpleGeojson

AsSimpleGeojson returns the underlying CombinedSimpleGeojson response data if the response is of the correct type, and a zero (default-valued) CombinedSimpleGeojson struct otherwise.

func (CombinedMultiple) AsSimpleJson

func (c CombinedMultiple) AsSimpleJson() CombinedSimpleJson

AsSimpleJson returns the underlying CombinedSimpleJson response data if the response is of the correct type, and a zero (default-valued) CombinedSimpleJson struct otherwise.

func (CombinedMultiple) IsZero

func (c CombinedMultiple) IsZero() bool

IsZero is true iff the receiver is a default-valued CombinedMultiple struct.

func (*CombinedMultiple) UnmarshalJSON

func (c *CombinedMultiple) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the supplied JSON data into a CombinedMultiple.

type CombinedSimpleGeojson

type CombinedSimpleGeojson struct {
	Type     string `json:"type"`
	Geometry struct {
		Type        string    `json:"type"`
		Coordinates []float64 `json:"coordinates"`
	} `json:"geometry"`
	Properties struct {
		Mmsi             int       `json:"mmsi"`
		Name             string    `json:"name"`
		Msgtime          time.Time `json:"msgtime"`
		SpeedOverGround  *float64  `json:"speedOverGround"`
		CourseOverGround *float64  `json:"courseOverGround"`
		RateOfTurn       *float64  `json:"rateOfTurn"`
		ShipType         *int      `json:"shipType"`
		TrueHeading      *int      `json:"trueHeading"`
	} `json:"properties"`
}

CombinedSimpleGeojson is a response to Combined when requesting ModelType "Simple" and ModelFormat "Geojson"

func (CombinedSimpleGeojson) IsZero

func (a CombinedSimpleGeojson) IsZero() bool

IsZero is true iff the receiver is a default-valued CombinedSimpleGeojson struct.

type CombinedSimpleJson

type CombinedSimpleJson struct {
	CourseOverGround *float64  `json:"courseOverGround"`
	Latitude         *float64  `json:"latitude"`
	Longitude        *float64  `json:"longitude"`
	Name             string    `json:"name"`
	RateOfTurn       *float64  `json:"rateOfTurn"`
	ShipType         *int      `json:"shipType"`
	SpeedOverGround  *float64  `json:"speedOverGround"`
	TrueHeading      *int      `json:"trueHeading"`
	Mmsi             int       `json:"mmsi"`
	Msgtime          time.Time `json:"msgtime"`
}

CombinedSimpleJson is a response to Combined when requesting ModelType "Simple" and ModelFormat "Json"

func (CombinedSimpleJson) IsZero

func (a CombinedSimpleJson) IsZero() bool

IsZero is true iff the receiver is a default-valued CombinedSimpleJson struct.

type FilterInput

type FilterInput struct {
	Geometry                     *geojson.Geometry         `json:"geometry"`
	Since                        *time.Time                `json:"since"`
	MMSI                         []int                     `json:"mmsi"`
	ShipTypes                    []shiptype.ShipType       `json:"shipTypes"`
	CountryCodes                 []countrycode.CountryCode `json:"countryCodes"`
	IncludePosition              bool                      `json:"includePosition"`
	IncludeStatic                bool                      `json:"includeStatic"`
	IncludeAton                  bool                      `json:"includeAton"`
	IncludeSafetyRelated         bool                      `json:"includeSafetyRelated"`
	IncludeBinaryBroadcastMetHyd bool                      `json:"includeBinaryBroadcastMetHyd"`
	Downsample                   bool                      `json:"downsample"`
}

FilterInput Ais.LiveApi.Api.AisMessage.Models.FilterInput

type LatestAisFilterInput

type LatestAisFilterInput struct {
	Geometry                     *geojson.Geometry         `json:"geometry"`
	Since                        *time.Time                `json:"since"`
	MMSI                         []int                     `json:"mmsi"`
	ShipTypes                    []shiptype.ShipType       `json:"shipTypes"`
	CountryCodes                 []countrycode.CountryCode `json:"countryCodes"`
	IncludePosition              bool                      `json:"includePosition"`
	IncludeStatic                bool                      `json:"includeStatic"`
	IncludeAton                  bool                      `json:"includeAton"`
	IncludeSafetyRelated         bool                      `json:"includeSafetyRelated"`
	IncludeBinaryBroadcastMetHyd bool                      `json:"includeBinaryBroadcastMetHyd"`
}

type Position

type Position struct {
	MessageType        int       `json:"messageType"`
	Mmsi               int       `json:"mmsi"`
	Msgtime            time.Time `json:"msgtime"`
	Altitude           *int      `json:"altitude"`
	Longitude          *float64  `json:"longitude"`
	Latitude           *float64  `json:"latitude"`
	CourseOverGround   *float64  `json:"courseOverGround"`
	AisClass           string    `json:"aisClass"`
	NavigationalStatus int       `json:"navigationalStatus"`
	RateOfTurn         *float64  `json:"rateOfTurn"`
	SpeedOverGround    *float64  `json:"speedOverGround"`
	TrueHeading        *int      `json:"trueHeading"`
}

Position

Verified in private communication Jan 24 2023.

func (Position) IsZero

func (a Position) IsZero() bool

IsZero is true iff the receiver is a default-valued Position struct.

type Response

type Response[T any] struct {
	*http.Response
}

Response is an API response which contains the given T data type.

func (Response[T]) Unmarshal

func (r Response[T]) Unmarshal() (T, error)

Unmarshal unmarshals the reponse body into a new object of type T.

type Staticdata

type Staticdata struct {
	MessageType              int       `json:"messageType"`
	Mmsi                     int       `json:"mmsi"`
	Msgtime                  time.Time `json:"msgtime"`
	Name                     string    `json:"name"`
	DimensionA               *int      `json:"dimensionA"`
	DimensionB               *int      `json:"dimensionB"`
	DimensionC               *int      `json:"dimensionC"`
	DimensionD               *int      `json:"dimensionD"`
	ImoNumber                *int      `json:"imoNumber"`
	CallSign                 string    `json:"callSign"`
	Destination              string    `json:"destination"`
	Eta                      string    `json:"eta"`
	Draught                  *int      `json:"draught"`
	ShipLength               *int      `json:"shipLength"`
	ShipWidth                *int      `json:"shipWidth"`
	ShipType                 *int      `json:"shipType"`
	PositionFixingDeviceType int       `json:"positionFixingDeviceType"`
	ReportClass              string    `json:"reportClass"`
}

Staticdata

Verified in private communication Jan 24 2023.

func (Staticdata) IsZero

func (a Staticdata) IsZero() bool

IsZero is true iff the receiver is a default-valued Staticdata struct.

type StreamResponse

type StreamResponse[T any] struct {
	*http.Response
	// contains filtered or unexported fields
}

StreamResponse is an API response whose body is a continuous stream of data.

A StreamResponse can be consumed using the `UnmarshalStream` method.

func (*StreamResponse[T]) Error added in v0.0.2

func (r *StreamResponse[T]) Error() error

Error returns the underlying error or reason when a stream ends.

func (*StreamResponse[T]) UnmarshalStream

func (r *StreamResponse[T]) UnmarshalStream() (<-chan T, error)

UnmarshalStream unmarshals a stream of serialized data into the underlying data structure.

The returned channel returns the next object unmarshalled. The channel only closes when it encounters an error, or when the stream closes. Use StreamResponse.Error to check the reason for the closed stream. If UnmarshalStream encounters an error, the underlying connection is closed. To continue consuming data, another api call must be made to get a new StreamResponse.

type StreamType added in v0.0.2

type StreamType int
const (
	None StreamType = iota
	Simple
	SSE
)

type URLs

type URLs struct {
	// OAuthBase is the base URL for all OAuth requests.
	//
	// Example: https://id.barentswatch.no
	OAuthBase string

	// TokenEndpoint is the relative location of the OAuth Authorization Server token endpoint.
	//
	// Example: /connect/token
	TokenEndpoint string

	// APIBase is the base URL for all API requests.
	//
	// Example: https://live.ais.barentswatch.no
	APIBase string

	// AISEndpoint is the relative location of the AIS API endpoint.
	//
	// Example: /v1/ais
	AISEndpoint string

	// SSEAISEndpoint is the relative location of the Server Side Event AIS API endpoint.
	//
	// Example: /v1/sse/ais
	SSEAISEndpoint string

	// CombinedEndpoint is the relative location of the combined position and static data AIS API endpoint.
	//
	// Example: /v1/combined
	CombinedEndpoint string

	// SSECombinedEndpoint is the relative location of the Server Side Event combined position and static data AIS
	// API endpoint.
	//
	// Example: /v1/sse/combined
	SSECombinedEndpoint string

	// LatestAISEndpoint is the relative location of latest AIS endpoint.
	//
	// Example: /v1/latest/ais
	LatestAISEndpoint string

	// LatestCombinedEndpoint is the relative location of the latest combined position and static data AIS API endpoint.
	//
	// Example: /v1/latest/combined
	LatestCombinedEndpoint string

	// OpenAISAreaEndpoint is the relative location of the Open AIS Area API endpoint.
	//
	// Example: /v1/openaisarea
	OpenAISAreaEndpoint string
}

func DefaultURLs

func DefaultURLs() URLs

DefaultURLs returns the documented URLs to the API endpoints.

func (URLs) AIS

func (r URLs) AIS() string

AIS returns the full URL to the AIS endpoint

func (URLs) Combined

func (r URLs) Combined() string

Combined returns the full URL to the Combined endpoint

func (URLs) LatestAIS

func (r URLs) LatestAIS() string

LatestAIS returns the full URL to the Latest endpoint

func (URLs) LatestCombined

func (r URLs) LatestCombined() string

LatestCombined returns the full URL to the Latest Combined endpoint

func (URLs) OAuthToken

func (r URLs) OAuthToken() string

OAuthToken returns the full URL to the OAuth 2.0 token endpoint

func (URLs) OpenAISArea

func (r URLs) OpenAISArea() string

OpenAISArea returns the full URL to the Open AIS Area endpoint

func (URLs) SSEAIS

func (r URLs) SSEAIS() string

SSEAIS returns the full URL to the AIS endpoint that returns data through Server Sent Events (SSE)

func (URLs) SSECombined

func (r URLs) SSECombined() string

SSECombined returns the full URL to the Combined endpoint that returns data through Server Sent Events (SSE)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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