avurnav

package module
v0.0.0-...-7b10c98 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2019 License: MIT Imports: 13 Imported by: 0

README

GoDoc Software License

AVURNAVs

This library can be used to get navigational warnings for Metropolitan France. Navigational warnings contain information about persons in distress, or objects and events that pose an immediate hazard to navigation. Navigational warnings are called AVURNAV (avis urgent aux navigateurs) in French.

It provides an HTTP client to get information directly from the Préfet Maritime websites, who publish navigational warnings for the sea region under their authority. It also offers a storage to persist to Redis navigational warnings.

Notice

This software is available under the MIT license and was developed as part of the Entrepreneur d'Intérêt Général program by the French government.

Documentation

Index

Constants

View Source
const (
	BASE_PREMAR = "https://premar.antoine-augusti.fr"
)

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range. API error responses are expected to have either no response body, or a JSON response body that maps to ErrorResponse. Any other response body will be silently ignored.

Types

type AVURNAV

type AVURNAV struct {
	// Number is the number of the AVURNAV. This is the main public identifier
	Number string `json:"number"`
	// Title is the title of the AVURNAV
	Title string `json:"title"`
	// Content is the content of the AVURNAV
	Content string `json:"content"`
	// Latitude gives an indication about the localisation of the AVURNAV.
	// It's not super reliable for now because AVURNAVs can spawn multiple
	// geographical regions but for now Préfet Maritimes only give a single point.
	Latitude float32 `json:"latitude"`
	// Longitude gives an indication about the localisation of the AVURNAV.
	// It's not super reliable for now because AVURNAVs can spawn multiple
	// geographical regions but for now Préfet Maritimes only give a single point.
	Longitude float32 `json:"longitude"`
	// URL gives a full URL to a Préfet Maritime website concerning this specific AVURNAV
	URL string `json:"url"`
	// ValidFrom tells when the AVURNAV will be in force. Format: YYYY-MM-DD
	ValidFrom *string `json:"valid_from"`
	// ValidUntil tells when the AVURNAV will not be valid anymore. Format: YYYY-MM-DD
	ValidUntil *string `json:"valid_until"`
	// PreMarRegion gives the region under the authority of this Préfet Maritime
	PreMarRegion string `json:"premar_region"`
}

AVURNAV represents an AVURNAV

func (AVURNAV) JSON

func (a AVURNAV) JSON() string

JSON gets the JSON representation of an AVURNAV

func (AVURNAV) MarshalBinary

func (a AVURNAV) MarshalBinary() ([]byte, error)

MarshalBinary marshals the object

func (AVURNAV) ParseContent

func (a AVURNAV) ParseContent(reader io.Reader) AVURNAV

ParseContent fills the content section of an AVURNAV and returns a new one

func (*AVURNAV) UnmarshalBinary

func (a *AVURNAV) UnmarshalBinary(data []byte) error

UnmarshalBinary unmarshals the object

type AVURNAVFetcher

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

AVURNAVFetcher fetches AVURNAVs on the Préfet Maritime websites

func (*AVURNAVFetcher) Get

Get fetches the content of an AVURNAV from the web and returns it

func (*AVURNAVFetcher) List

func (f *AVURNAVFetcher) List() (AVURNAVs, *http.Response, error)

List lists AVURNAVs that are currently available

type AVURNAVPayload

type AVURNAVPayload struct {
	Title      string  `json:"title"`
	ValidFrom  string  `json:"valid_from"`
	ValidUntil string  `json:"valid_until"`
	Latitude   float32 `json:"latitude"`
	Longitude  float32 `json:"longitude"`
	URL        string  `json:"url"`
	Number     string  `json:"number"`
}

AVURNAVPayload is used to decode AVURNAVs from the Préfet Maritime websites

func (AVURNAVPayload) AVURNAV

func (p AVURNAVPayload) AVURNAV(premar PremarInterface) AVURNAV

AVURNAV transforms a payload to a proper AVURNAV

type AVURNAVPayloads

type AVURNAVPayloads []AVURNAVPayload

AVURNAVPayloads represents multiple AVRUNAV payloads

func (AVURNAVPayloads) AVURNAVs

func (p AVURNAVPayloads) AVURNAVs(premar PremarInterface) AVURNAVs

AVURNAVs transforms payloads to AVURNAVs

type AVURNAVs

type AVURNAVs []AVURNAV

AVURNAVs represents multiple AVURNAV

type Client

type Client struct {

	// User agent for client
	UserAgent string
	// Services used for communications with the API
	Manche       AVURNAVFetcher
	Atlantique   AVURNAVFetcher
	Mediterranee AVURNAVFetcher

	Fetchers []*AVURNAVFetcher
	// contains filtered or unexported fields
}

Client manages communication with the API

func NewClient

func NewClient(httpClient *http.Client) *Client

NewClient returns a new API client

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*http.Response, error)

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response will be written to v, without attempting to decode it.

func (*Client) NewRequest

func (c *Client) NewRequest(method string, theURL *url.URL, body interface{}) (*http.Request, error)

NewRequest creates an API request to a given URL. If specified, the value pointed to by body is JSON encoded and included in as the request body.

type ErrorResponse

type ErrorResponse struct {
	// Response is the HTTP response that caused this error
	Response *http.Response

	// Message is the error message
	Message string
}

ErrorResponse reports the error caused by an API request

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

Error gives information about the error

type PremarInterface

type PremarInterface interface {
	// Client gets the HTTP client
	Client() *Client
	// BaseURL returns the base URL of the website
	BaseURL() *url.URL
	// Region returns the region under the authority of
	// the Préfet Maritime
	Region() string
}

PremarInterface describes which data a Préfet Maritime service should be able to give

type PremarService

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

PremarService gives information about a specific Préfet Maritime

func (PremarService) BaseURL

func (s PremarService) BaseURL() *url.URL

BaseURL returns the base URL of the website

func (PremarService) Client

func (s PremarService) Client() *Client

Client gets the HTTP client

func (PremarService) Region

func (s PremarService) Region() string

Region returns the region under the authority of the Préfet Maritime

type Storage

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

Storage stores AVURNAVs in Redis

func NewStorage

func NewStorage(client *redis.Client) Storage

NewStorage constructs a new Storage from a Redis client

func (*Storage) AVURNAVsForRegion

func (s *Storage) AVURNAVsForRegion(region string) AVURNAVs

AVURNAVsForRegion lists AVURNAVs for a specific Préfet Maritime region

func (*Storage) Get

func (s *Storage) Get(a AVURNAV) (AVURNAV, error)

Get gets a single AVURNAV from storage

func (*Storage) RegisterAVURNAVs

func (s *Storage) RegisterAVURNAVs(avurnavs AVURNAVs) error

RegisterAVURNAVs stores AVURNAVs in storage

Jump to

Keyboard shortcuts

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