diff --git a/connections.go b/connections.go index 0b7af67..9d96a76 100644 --- a/connections.go +++ b/connections.go @@ -11,7 +11,7 @@ import ( "github.com/govitia/navitia/utils" ) -// A Connection is either a Departure or an Arrival +// A Connection is either a Departure or an Arrival. type Connection struct { Display types.Display StopPoint types.StopPoint diff --git a/departures.go b/departures.go index abc3b6e..c808d4a 100644 --- a/departures.go +++ b/departures.go @@ -14,12 +14,12 @@ type DeparturesResults struct { session *Session } -// Count returns the number of results available in a Departures +// Count returns the number of results available in a Departures. func (dr *DeparturesResults) Count() int { return len(dr.Departures) } -// DeparturesRequest contain the parameters needed to make a departures +// DeparturesRequest contain the parameters needed to make a departures. type DeparturesRequest struct { StopArea string } diff --git a/errors.go b/errors.go index ef0006c..9f25f00 100644 --- a/errors.go +++ b/errors.go @@ -8,12 +8,12 @@ import ( "github.com/pkg/errors" ) -// RemoteErrorID is an ID for a remote error +// RemoteErrorID is an ID for a remote error. type RemoteErrorID string -// RemoteErrXXX are the known error ids that can be returned by the navitia server +// RemoteErrXXX are the known error ids that can be returned by the navitia server. const ( - // 404 Errors + // 404 Errors. RemoteErrDateOutOfBounds RemoteErrorID = "date_out_of_bounds" // When the given date is out of bounds of the production dates of the region RemoteErrNoOrigin RemoteErrorID = "no_origin" // Couldn’t find an origin for the journeys @@ -21,7 +21,7 @@ const ( RemoteErrNoOriginNoDestination RemoteErrorID = "nor_origin_nor_destination" // Couldn’t find an origin nor a destination for the journeys RemoteErrUnknownObject RemoteErrorID = "unknown_object" // Unknown Object - // 400 Errors + // 400 Errors. RemoteErrBadFilter RemoteErrorID = "bad_filter" // Bad filter (with custom filter) RemoteErrUnableToParse RemoteErrorID = "unable_to_parse" // Unable to parse mal-formed custom filter" @@ -29,7 +29,7 @@ const ( // remoteErrorsDescriptions contains human-readable descriptions for a given remote error ID // -// Can also be used as a list of known error IDs +// Can also be used as a list of known error IDs. var remoteErrorsDescriptions = map[RemoteErrorID]string{ RemoteErrDateOutOfBounds: "When the given date is out of bounds of the production dates of the region", RemoteErrNoOrigin: "Couldn’t find an origin for the journeys", @@ -40,7 +40,7 @@ var remoteErrorsDescriptions = map[RemoteErrorID]string{ RemoteErrUnableToParse: "Unable to parse mal-formed custom filter", } -// A RemoteError represents an error sent by the server +// A RemoteError represents an error sent by the server. type RemoteError struct { StatusCode int ID RemoteErrorID `json:"id"` @@ -48,7 +48,7 @@ type RemoteError struct { } // Error formats the error in a human-readable format -// Also allows it to satisfy the error interface +// Also allows it to satisfy the error interface. func (err RemoteError) Error() string { var s string @@ -66,7 +66,7 @@ func (err RemoteError) Error() string { return s } -// parseRemoteError parses a non 200 OK status-coded response and returns the error +// parseRemoteError parses a non 200 OK status-coded response and returns the error. func parseRemoteError(resp *http.Response) error { remoteErr := &RemoteError{StatusCode: resp.StatusCode} diff --git a/go.mod b/go.mod index 02af804..2c8f71d 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/paulmach/go.geojson v1.4.0 github.com/pkg/errors v0.9.1 github.com/twpayne/go-geom v1.3.6 + golang.org/x/net v0.0.0-20191003171128-d98b1b443823 golang.org/x/sys v0.0.0-20201109165425-215b40eba54c // indirect golang.org/x/text v0.3.4 gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b // indirect diff --git a/go.sum b/go.sum index 3b8b46e..e570f92 100644 --- a/go.sum +++ b/go.sum @@ -75,6 +75,7 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20191003171128-d98b1b443823 h1:Ypyv6BNJh07T1pUSrehkLemqPKXhus2MkfktJ91kRh4= golang.org/x/net v0.0.0-20191003171128-d98b1b443823/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/init_test.go b/init_test.go index aa4904e..f1c7371 100644 --- a/init_test.go +++ b/init_test.go @@ -12,7 +12,7 @@ var ( testSession *Session ) -// Initialise testing function +// Initialise testing function. func init() { // Populate flags flag.Parse() diff --git a/journeys.go b/journeys.go index 1b46a5b..ae7920a 100644 --- a/journeys.go +++ b/journeys.go @@ -20,12 +20,12 @@ type JourneyResults struct { session *Session } -// Count returns the number of results available in a JourneyResults +// Count returns the number of results available in a JourneyResults. func (jr *JourneyResults) Count() int { return len(jr.Journeys) } -// JourneyRequest contain the parameters needed to make a Journey request +// JourneyRequest contain the parameters needed to make a Journey request. type JourneyRequest struct { // There must be at least one From or To parameter defined // When used with just one of them, the resulting Journey won't have a populated Sections field. @@ -33,8 +33,7 @@ type JourneyRequest struct { To types.ID // When do you want to depart ? Or is DateIsArrival when do you want to arrive at your destination. - Date time.Time - DateIsArrival bool + Date time.Time // The traveller's type Traveler types.TravelerType @@ -81,16 +80,18 @@ type JourneyRequest struct { // Maximum duration of a trip MaxDuration time.Duration // To seconds - // Wheelchair restricts the answer to accessible public transports - Wheelchair bool - // Headsign If given, add a filter on the vehicle journeys that has the // given value as headsign (on vehicle journey itself or at a stop time). Headsign string + + // Wheelchair restricts the answer to accessible public transports + Wheelchair bool + + DateIsArrival bool } // toURL formats a journey request to url -// Should be refactored using a switch statement +// Should be refactored using a switch statement. func (req JourneyRequest) toURL() (url.Values, error) { rb := utils.NewRequestBuilder() diff --git a/logging.go b/logging.go index 80342d7..84fa04f 100644 --- a/logging.go +++ b/logging.go @@ -2,24 +2,24 @@ package navitia import "time" -// Logging stores logging info +// Logging stores logging info. type Logging struct { Created time.Time Sent time.Time Received time.Time } -// creating stores creation time +// creating stores creation time. func (l *Logging) creating() { l.Created = time.Now() } -// sending stores sending time +// sending stores sending time. func (l *Logging) sending() { l.Sent = time.Now() } -// parsing stores parsing time +// parsing stores parsing time. func (l *Logging) parsing() { l.Received = time.Now() } diff --git a/navitia_test.go b/navitia_test.go index 77d5c90..affb496 100644 --- a/navitia_test.go +++ b/navitia_test.go @@ -39,7 +39,7 @@ type testPair struct { correct interface{} } -// Convert testing mechanism to known compare + corpus runs +// Convert testing mechanism to known compare + corpus runs. type typeTestData struct { known map[string]testPair // Hardcoded map of pairs of JSON data / the Go representation they should have correct map[string][]byte // Map of known correct files to be parsed (they should _not_ return an error) @@ -47,11 +47,11 @@ type typeTestData struct { bench map[string][]byte // Descriptions -> File } -// testData stores a map which maps each category to their data +// testData stores a map which maps each category to their data. var testData = make(map[string]typeTestData, len(typesList)) // this is the list of potential types -// must be lower case +// must be lower case. var typesList = []string{ "journeys", "coverage", @@ -59,7 +59,7 @@ var typesList = []string{ "connections", } -// listCategoryDirs retrieves the subdirectories under the main testdata directory +// listCategoryDirs retrieves the subdirectories under the main testdata directory. func listCategoryDirs(path string) ([]os.FileInfo, error) { mainSubdirs, err := ioutil.ReadDir(path) if err != nil { @@ -79,7 +79,7 @@ func listCategoryDirs(path string) ([]os.FileInfo, error) { return subDirsInfo, nil } -// extractCorpus extracts a corpus +// extractCorpus extracts a corpus. func extractCorpus(path string) (map[string][]byte, error) { // List the files files, err := ioutil.ReadDir(path) @@ -117,7 +117,7 @@ func extractCorpus(path string) (map[string][]byte, error) { return corpus, nil } -// getPertinentSubdirs, given a dir in a category subdirectory, returns the awaited values +// getPertinentSubdirs, given a dir in a category subdirectory, returns the awaited values. func getCategory(path string) (typeTestData, error) { // Create the data data := typeTestData{} @@ -157,7 +157,7 @@ func getCategory(path string) (typeTestData, error) { return data, nil } -// load loads the file structing into the testData +// load loads the file structing into the testData. func load() error { subDirsInfo, err := listCategoryDirs(testDataPath) if err != nil { diff --git a/paging.go b/paging.go index 7d5e58e..66609d5 100644 --- a/paging.go +++ b/paging.go @@ -7,7 +7,7 @@ import ( "github.com/pkg/errors" ) -// Paging holds potential Previous / Next functions +// Paging holds potential Previous / Next functions. type Paging struct { // Next results Next func(ctx context.Context, s *Session, res results) error @@ -23,7 +23,7 @@ type link struct { Type string } -// createPagingFunc creates a paging func (either Previous or Next) +// createPagingFunc creates a paging func (either Previous or Next). func createPagingFunc(url string) func(ctx context.Context, s *Session, res results) error { f := func(ctx context.Context, s *Session, res results) error { return s.requestURL(ctx, url, res) @@ -31,7 +31,7 @@ func createPagingFunc(url string) func(ctx context.Context, s *Session, res resu return f } -// UnmarshalJSON unmarshals a Paging type from a Links data structure +// UnmarshalJSON unmarshals a Paging type from a Links data structure. func (p *Paging) UnmarshalJSON(b []byte) error { var links []link err := json.Unmarshal(b, &links) diff --git a/places.go b/places.go index cd36f70..8e7f45f 100644 --- a/places.go +++ b/places.go @@ -30,12 +30,12 @@ func (pr *PlacesResults) Less(i, j int) bool { return pr.Places[i].Quality < pr.Places[j].Quality } -// Swap swaps the Place of index i and the Place of index j +// Swap swaps the Place of index i and the Place of index j. func (pr *PlacesResults) Swap(i, j int) { pr.Places[i], pr.Places[j] = pr.Places[j], pr.Places[i] } -// PlacesRequest is the query you need to build before passing it to Places +// PlacesRequest is the query you need to build before passing it to Places. type PlacesRequest struct { Query string // The search item @@ -56,7 +56,7 @@ type PlacesRequest struct { Count uint } -// toURL formats a Places request to url +// toURL formats a Places request to url. func (req PlacesRequest) toURL() (url.Values, error) { rb := utils.NewRequestBuilder() diff --git a/pretty/containers.go b/pretty/containers.go index f3bd67e..2ac1214 100644 --- a/pretty/containers.go +++ b/pretty/containers.go @@ -9,14 +9,14 @@ import ( "github.com/govitia/navitia/types" ) -// ContainerConf stores configuration for use in ContainerWrite +// ContainerConf stores configuration for use in ContainerWrite. type ContainerConf struct { Quality *color.Color Type *color.Color Name *color.Color } -// DefaultContainerConf holds a default, quite good configuration +// DefaultContainerConf holds a default, quite good configuration. var DefaultContainerConf = ContainerConf{ Quality: color.New(color.FgMagenta), Type: color.New(color.FgGreen), diff --git a/pretty/journey.go b/pretty/journey.go index 05f7920..b92df46 100644 --- a/pretty/journey.go +++ b/pretty/journey.go @@ -14,7 +14,7 @@ import ( const timeLayout = "15:04" -// JourneyConf stores configuration for pretty-printing a types.Journey +// JourneyConf stores configuration for pretty-printing a types.Journey. type JourneyConf struct { Departure *color.Color Arrival *color.Color @@ -24,7 +24,7 @@ type JourneyConf struct { Section SectionConf } -// DefaultJourneyConf holds a default, quite good configuration +// DefaultJourneyConf holds a default, quite good configuration. var DefaultJourneyConf = JourneyConf{ Departure: color.New(color.FgRed), Arrival: color.New(color.FgRed), @@ -33,7 +33,7 @@ var DefaultJourneyConf = JourneyConf{ Section: DefaultSectionConf, } -// PrettyWrite writes a pretty-printed types.Journey to out +// PrettyWrite writes a pretty-printed types.Journey to out. func (conf JourneyConf) PrettyWrite(j *types.Journey, out io.Writer) error { // Build the envellope const msgFmt = "%s ➡️ %s | %s\n" diff --git a/pretty/journeyresults.go b/pretty/journeyresults.go index 395816f..a0be3ea 100644 --- a/pretty/journeyresults.go +++ b/pretty/journeyresults.go @@ -11,19 +11,19 @@ import ( "github.com/govitia/navitia/types" ) -// JourneyResultsConf stores configuration for pretty-printing a navitia.JourneyResults +// JourneyResultsConf stores configuration for pretty-printing a navitia.JourneyResults. type JourneyResultsConf struct { Count *color.Color Journey JourneyConf } -// DefaultJourneyResultsConf holds a default, quite good configuration +// DefaultJourneyResultsConf holds a default, quite good configuration. var DefaultJourneyResultsConf = JourneyResultsConf{ Count: color.New(color.FgBlack), Journey: DefaultJourneyConf, } -// PrettyWrite writes a pretty-printed navitia.JourneyResults to out +// PrettyWrite writes a pretty-printed navitia.JourneyResults to out. func (conf JourneyResultsConf) PrettyWrite(jr *navitia.JourneyResults, out io.Writer) error { // Buffers to line-up the reads, sequentially buffers := make([]io.Reader, jr.Count()) diff --git a/pretty/placesresults.go b/pretty/placesresults.go index c36585e..28af756 100644 --- a/pretty/placesresults.go +++ b/pretty/placesresults.go @@ -12,13 +12,13 @@ import ( "github.com/govitia/navitia/types" ) -// PlacesResultsConf stores configuration for pretty-printing +// PlacesResultsConf stores configuration for pretty-printing. type PlacesResultsConf struct { Count *color.Color Place ContainerConf } -// DefaultPlacesResultsConf holds a default, quite good configuration +// DefaultPlacesResultsConf holds a default, quite good configuration. var DefaultPlacesResultsConf = PlacesResultsConf{ Count: color.New(color.Italic), Place: DefaultContainerConf, diff --git a/pretty/section.go b/pretty/section.go index 8acc2b8..15f5d06 100644 --- a/pretty/section.go +++ b/pretty/section.go @@ -36,7 +36,7 @@ var modeEmoji = map[string]string{ types.ModeBikeShare: "🚴", } -// SectionConf stores configuration for pretty-printing a types.Section +// SectionConf stores configuration for pretty-printing a types.Section. type SectionConf struct { Mode *color.Color Duration *color.Color @@ -45,7 +45,7 @@ type SectionConf struct { Emoji bool } -// DefaultSectionConf holds a default, quite good configuration +// DefaultSectionConf holds a default, quite good configuration. var DefaultSectionConf = SectionConf{ Mode: color.New(color.FgGreen), Duration: color.New(color.FgMagenta), @@ -53,7 +53,7 @@ var DefaultSectionConf = SectionConf{ To: color.New(color.FgBlue), } -// PrettyWrite writes a pretty-printed types.Section to out +// PrettyWrite writes a pretty-printed types.Section to out. func (conf SectionConf) PrettyWrite(s *types.Section, out io.Writer) error { // if there's no from or no to, finish now if s.From.Name == "" || s.To.Name == "" { diff --git a/region.go b/region.go index 7c40785..96add56 100644 --- a/region.go +++ b/region.go @@ -10,7 +10,7 @@ import ( const regionEndpoint string = "coverage" // A RegionResults holds results for a coverage query -// This Results doesn't support paging :( +// This Results doesn't support paging :(. type RegionResults struct { // The list of regions retrieved Regions []types.Region `json:"Regions"` @@ -22,7 +22,7 @@ type RegionResults struct { session *Session } -// RegionRequest contains the parameters needed to make a Coverage request +// RegionRequest contains the parameters needed to make a Coverage request. type RegionRequest struct { // Count is the number of items to return, if count=0, then it will return the default number // BUG: Count doesn't work, server-side. diff --git a/request.go b/request.go index ceff7d4..52cedd8 100644 --- a/request.go +++ b/request.go @@ -8,7 +8,7 @@ type query interface { toURL() (url.Values, error) } -// results is implemented by every Result type +// results is implemented by every Result type. type results interface { creating() sending() diff --git a/scope.go b/scope.go index 79ba38c..f64ff6b 100644 --- a/scope.go +++ b/scope.go @@ -39,7 +39,7 @@ func (s *Session) ArrivalsC(ctx context.Context, req ConnectionsRequest, coords return s.connections(ctx, scopeURL, req) } -// Departures computes a list of Departures according to the parameters given in a specific scope +// Departures computes a list of Departures according to the parameters given in a specific scope. func (scope *Scope) Departures(ctx context.Context, req DeparturesRequest) (*DeparturesResults, error) { // there is a special case for departures stop areas, it needs to be added before any parameters filterByVJ := "" @@ -53,7 +53,7 @@ func (scope *Scope) Departures(ctx context.Context, req DeparturesRequest) (*Dep return scope.session.departures(ctx, reqURL, req) } -// DeparturesSA requests the departures for a given StopArea +// DeparturesSA requests the departures for a given StopArea. func (scope *Scope) DeparturesSA(ctx context.Context, req ConnectionsRequest, resource types.ID) (*ConnectionsResults, error) { // Create the URL scopeURL := scope.session.APIURL + "/coverage/" + string(scope.region) + "/stop_areas/" + string(resource) + "/" + departuresEndpoint @@ -61,7 +61,7 @@ func (scope *Scope) DeparturesSA(ctx context.Context, req ConnectionsRequest, re return scope.session.connections(ctx, scopeURL, req) } -// DeparturesSP requests the departures for a given StopPoint +// DeparturesSP requests the departures for a given StopPoint. func (scope *Scope) DeparturesSP(ctx context.Context, req ConnectionsRequest, resource types.ID) (*ConnectionsResults, error) { // Create the URL scopeURL := scope.session.APIURL + "/coverage/" + string(scope.region) + "/stop_points/" + string(resource) + "/" + departuresEndpoint @@ -69,7 +69,7 @@ func (scope *Scope) DeparturesSP(ctx context.Context, req ConnectionsRequest, re return scope.session.connections(ctx, scopeURL, req) } -// Journeys computes a list of journeys according to the parameters given in a specific scope +// Journeys computes a list of journeys according to the parameters given in a specific scope. func (scope *Scope) Journeys(ctx context.Context, req JourneyRequest) (*JourneyResults, error) { // Create the URL reqURL := scope.session.APIURL + "/coverage/" + string(scope.region) + "/" + journeysEndpoint @@ -88,7 +88,7 @@ func (scope *Scope) Places(ctx context.Context, params PlacesRequest) (*PlacesRe return scope.session.places(ctx, reqURL, params) } -// VehicleJourneys computes a list of VehicleJourneys according to the parameters given in a specific scope +// VehicleJourneys computes a list of VehicleJourneys according to the parameters given in a specific scope. func (scope *Scope) VehicleJourneys(ctx context.Context, req VehicleJourneyRequest) (*VehicleJourneyResults, error) { // there is a special case for vehicle journey ID, it needs to be added before any parameters filterByVJ := "" diff --git a/session.go b/session.go index e8b8db1..caa09bf 100644 --- a/session.go +++ b/session.go @@ -16,17 +16,17 @@ import ( ) const ( - // default Navitia REST service + // default Navitia REST service. defaultAPIURL = "https://api.navitia.io/v1" // Maximum size of response in bytes - // 10 megabytes + // 10 megabytes. maxSize int64 = 10e6 ) var defaultClient = &http.Client{} -// Session holds a current session, it is thread-safe +// Session holds a current session, it is thread-safe. type Session struct { APIKey string APIURL string @@ -43,7 +43,7 @@ func New(key string) (*Session, error) { return NewCustom(key, path.Clean(defaultAPIURL), defaultClient) } -// NewCustom creates a custom new session given an API key, URL to api base & http client +// NewCustom creates a custom new session given an API key, URL to api base & http client. func NewCustom(key, url string, client *http.Client) (*Session, error) { return &Session{ APIKey: key, @@ -53,21 +53,21 @@ func NewCustom(key, url string, client *http.Client) (*Session, error) { }, nil } -// departures is the internal function used by Departures & Arrivals functions +// departures is the internal function used by Departures & Arrivals functions. func (s *Session) connections(ctx context.Context, url string, req ConnectionsRequest) (*ConnectionsResults, error) { results := &ConnectionsResults{} err := s.request(ctx, url, req, results) return results, err } -// departures is the internal function used by Journeys functions +// departures is the internal function used by Journeys functions. func (s *Session) departures(ctx context.Context, url string, req DeparturesRequest) (*DeparturesResults, error) { results := &DeparturesResults{session: s} err := s.request(ctx, url, req, results) return results, err } -// Departures computes a list of Departures according to the parameters given +// Departures computes a list of Departures according to the parameters given. func (s *Session) Departures(ctx context.Context, req DeparturesRequest) (*DeparturesResults, error) { // Create the URL reqURL := s.APIURL + "/" + departuresEndpoint @@ -84,14 +84,14 @@ func (s *Session) DeparturesC(ctx context.Context, req ConnectionsRequest, coord return s.connections(ctx, scopeURL, req) } -// journeys is the internal function used by Journeys functions +// journeys is the internal function used by Journeys functions. func (s *Session) journeys(ctx context.Context, url string, req JourneyRequest) (*JourneyResults, error) { results := &JourneyResults{session: s} err := s.request(ctx, url, req, results) return results, err } -// Journeys computes a list of journeys according to the parameters given +// Journeys computes a list of journeys according to the parameters given. func (s *Session) Journeys(ctx context.Context, req JourneyRequest) (*JourneyResults, error) { // Create the URL reqURL := s.APIURL + "/" + journeysEndpoint @@ -100,7 +100,7 @@ func (s *Session) Journeys(ctx context.Context, req JourneyRequest) (*JourneyRes return s.journeys(ctx, reqURL, req) } -// places is the internal function used by Places functions +// places is the internal function used by Places functions. func (s *Session) places(ctx context.Context, url string, params PlacesRequest) (*PlacesResults, error) { results := &PlacesResults{session: s} err := s.request(ctx, url, params, results) @@ -216,7 +216,7 @@ func (s *Session) requestURL(ctx context.Context, url string, res results) error return err } -// request does a request given a url, query and results to populate +// request does a request given a url, query and results to populate. func (s *Session) request(ctx context.Context, baseURL string, query query, res results) error { // Encode the parameters values, err := query.toURL() @@ -234,7 +234,7 @@ func (s *Session) Scope(region types.ID) *Scope { return &Scope{region: region, session: s} } -// vehicleJourneys is the internal function used by VehicleJourneys functions +// vehicleJourneys is the internal function used by VehicleJourneys functions. func (s *Session) vehicleJourneys(ctx context.Context, url string, req VehicleJourneyRequest) (*VehicleJourneyResults, error) { results := &VehicleJourneyResults{session: s} err := s.request(ctx, url, req, results) @@ -243,7 +243,7 @@ func (s *Session) vehicleJourneys(ctx context.Context, url string, req VehicleJo const vehicleJourneysEndpoint string = "vehicle_journeys" -// VehicleJourneys computes a list of VehicleJourneys according to the parameters given +// VehicleJourneys computes a list of VehicleJourneys according to the parameters given. func (s *Session) VehicleJourneys(ctx context.Context, req VehicleJourneyRequest) (*VehicleJourneyResults, error) { // Create the URL reqURL := s.APIURL + "/" + vehicleJourneysEndpoint diff --git a/types/container.go b/types/container.go index eaf96f5..16f1aa3 100644 --- a/types/container.go +++ b/types/container.go @@ -22,7 +22,7 @@ const ( EmbeddedTrip = "trip" // This is a PT Object ) -// EmbeddedTypes lists all the possible embedded types you can find in a Container +// EmbeddedTypes lists all the possible embedded types you can find in a Container. var EmbeddedTypes = [...]string{ EmbeddedStopArea, EmbeddedPOI, @@ -55,10 +55,10 @@ var embeddedTypesPTObject = [...]string{ EmbeddedTrip, } -// An Object is what is contained by a Container +// An Object is what is contained by a Container. type Object interface{} -// A Container holds an Object, which can be a Place or a PT Object +// A Container holds an Object, which can be a Place or a PT Object. type Container struct { ID ID `json:"id"` Name string `json:"name"` @@ -75,7 +75,7 @@ type Container struct { mu *sync.RWMutex } -// IsPlace returns true if the container's content is a Place +// IsPlace returns true if the container's content is a Place. func (c *Container) IsPlace() bool { t := c.EmbeddedType return t == EmbeddedStopArea || @@ -85,7 +85,7 @@ func (c *Container) IsPlace() bool { t == EmbeddedAdmin } -// IsPTObject returns true if the container's content is a PTObject +// IsPTObject returns true if the container's content is a PTObject. func (c *Container) IsPTObject() bool { t := c.EmbeddedType return t == EmbeddedStopArea || @@ -96,7 +96,7 @@ func (c *Container) IsPTObject() bool { t == EmbeddedTrip } -// ErrInvalidContainer is returned after a check on a Container +// ErrInvalidContainer is returned after a check on a Container. type ErrInvalidContainer struct { // If the Container has a zero ID. NoID bool @@ -108,7 +108,7 @@ type ErrInvalidContainer struct { UnknownEmbeddedType bool } -// Error satisfies the error interface +// Error satisfies the error interface. func (err ErrInvalidContainer) Error() string { // Count the number of anomalies var anomalies uint @@ -131,7 +131,7 @@ func (err ErrInvalidContainer) Error() string { return fmt.Sprintf(msg, anomalies) } -// Empty returns true if the container is empty (zero value) +// Empty returns true if the container is empty (zero value). func (c *Container) Empty() bool { return c.ID == "" && c.Name == "" && c.EmbeddedType == "" && c.Quality == 0 && len(c.embeddedJSON) == 0 && c.embeddedObject == nil } @@ -243,7 +243,7 @@ func (c *Container) Object() (Object, error) { // Place returns the Place contained in the container if that is what's inside // -// If the Object isn't a Place or the Container is empty or invalid, Place returns an error +// If the Object isn't a Place or the Container is empty or invalid, Place returns an error. func (c *Container) Place() (Place, error) { // Check if its a Place if !c.IsPlace() { @@ -262,7 +262,7 @@ func (c *Container) Place() (Place, error) { // PTObject returns the PTObject contained in the container if that is what's inside // -// If the Object isn't a PTObject or the Container is empty or invalid, Place returns an error +// If the Object isn't a PTObject or the Container is empty or invalid, Place returns an error. func (c *Container) PTObject() (PTObject, error) { // Check if its a Place if !c.IsPTObject() { diff --git a/types/container_json.go b/types/container_json.go index da2662f..fb72f08 100644 --- a/types/container_json.go +++ b/types/container_json.go @@ -7,7 +7,7 @@ import ( "github.com/pkg/errors" ) -// UnmarshalJSON satisfies the json.Unmarshaller interface +// UnmarshalJSON satisfies the json.Unmarshaller interface. func (c *Container) UnmarshalJSON(b []byte) error { // Set up a mutex c.mu = &sync.RWMutex{} diff --git a/types/container_test.go b/types/container_test.go index 5174fc9..e396df3 100644 --- a/types/container_test.go +++ b/types/container_test.go @@ -8,7 +8,7 @@ import ( var containers map[string]*Container -// loadContainers loads the containers in their final form for testing +// loadContainers loads the containers in their final form for testing. func loadContainers() error { // Get the input corpus := testData["container"].correct @@ -34,7 +34,7 @@ func loadContainers() error { return nil } -// TestContainer_Object_NoCompare tests the Container.Object method +// TestContainer_Object_NoCompare tests the Container.Object method. func TestContainer_Object_NoCompare(t *testing.T) { // Get the input data := containers @@ -66,7 +66,7 @@ func TestContainer_Object_NoCompare(t *testing.T) { } } -// TestContainer_Check_NoCompare tests the Container.Check method +// TestContainer_Check_NoCompare tests the Container.Check method. func TestContainer_Check_NoCompare(t *testing.T) { // Get the input data := containers @@ -94,7 +94,7 @@ func TestContainer_Check_NoCompare(t *testing.T) { } } -// BenchmarkContainer_UnmarshalJSON benchmarks Container.UnmarshalJSON through benchmarks +// BenchmarkContainer_UnmarshalJSON benchmarks Container.UnmarshalJSON through benchmarks. func BenchmarkContainer_UnmarshalJSON(b *testing.B) { // Get the bench data data := testData["container"].bench @@ -149,7 +149,7 @@ func BenchmarkContainer_UnmarshalJSON(b *testing.B) { } } -// BenchmarkContainer_Check benchmarks Container.Check through subbenchmarks +// BenchmarkContainer_Check benchmarks Container.Check through subbenchmarks. func BenchmarkContainer_Check(b *testing.B) { // Get the bench data data := testData["container"].bench @@ -184,7 +184,7 @@ func BenchmarkContainer_Check(b *testing.B) { } } -// TestContainer_IsXXX tests (*Container).IsPlace and (*Container).IsPTObject +// TestContainer_IsXXX tests (*Container).IsPlace and (*Container).IsPTObject. func TestContainer_IsXXX(t *testing.T) { t.Run("IsPlace", func(t *testing.T) { for _, et := range embeddedTypesPlace { @@ -221,7 +221,7 @@ func TestContainer_IsXXX(t *testing.T) { }) } -// TestContainer_Empty tests that (*Container).Empty reports correctly whether or not the container is truly empty +// TestContainer_Empty tests that (*Container).Empty reports correctly whether or not the container is truly empty. func TestContainer_Empty(t *testing.T) { emptyContainer := Container{} nonEmptyContainers := []Container{ diff --git a/types/coordinates.go b/types/coordinates.go index a522ebe..86491f6 100644 --- a/types/coordinates.go +++ b/types/coordinates.go @@ -14,7 +14,7 @@ type Coordinates struct { Latitude float64 `json:"lat"` } -// ID formats coordinates for use in queries as an ID +// ID formats coordinates for use in queries as an ID. func (c Coordinates) ID() ID { return ID(fmt.Sprintf("%3.3f;%3.3f", c.Longitude, c.Latitude)) } diff --git a/types/coordinates_json.go b/types/coordinates_json.go index d2b4524..ee72f90 100644 --- a/types/coordinates_json.go +++ b/types/coordinates_json.go @@ -7,7 +7,7 @@ import ( "github.com/pkg/errors" ) -// UnmarshalJSON implements json.Unmarshaller for a Coordinates +// UnmarshalJSON implements json.Unmarshaller for a Coordinates. func (c *Coordinates) UnmarshalJSON(b []byte) error { // First let's create the analogous structure data := &struct { diff --git a/types/display_json.go b/types/display_json.go index 970840e..7b44c69 100644 --- a/types/display_json.go +++ b/types/display_json.go @@ -6,7 +6,7 @@ import ( "github.com/pkg/errors" ) -// UnmarshalJSON implements json.Unmarshaller for a Display +// UnmarshalJSON implements json.Unmarshaller for a Display. func (d *Display) UnmarshalJSON(b []byte) error { // First let's create the analogous structure // We define some of the value as pointers to the real values, allowing us to bypass copying in cases where we don't need to process the data diff --git a/types/disruption.go b/types/disruption.go index e46866c..d6999fc 100644 --- a/types/disruption.go +++ b/types/disruption.go @@ -8,10 +8,10 @@ import ( // Effect codes for known journey status information // For example, reduced service, detours or moved stops. // -// See https://developers.google.com/transit/gtfs-realtime/reference/Effect for more information +// See https://developers.google.com/transit/gtfs-realtime/reference/Effect for more information. type Effect string -// JourneyStatusXXX are known JourneyStatuse +// JourneyStatusXXX are known JourneyStatuse. const ( // Service suspended. EffectNoService Effect = "NO_SERVICE" @@ -41,7 +41,7 @@ const ( JourneyStatusStopMoved = "STOP_MOVED" ) -// A Disruption reports the specifics of a Disruption +// A Disruption reports the specifics of a Disruption. type Disruption struct { // ID of the Disruption ID ID `json:"id"` @@ -119,7 +119,7 @@ type ImpactedObject struct { ImpactedStops []ImpactedStop `json:"impacted_stops"` } -// An ImpactedSection records the impact to a section +// An ImpactedSection records the impact to a section. type ImpactedSection struct { // The start of the disruption, spatially From Container `json:"from"` @@ -127,7 +127,7 @@ type ImpactedSection struct { To Container `json:"to"` } -// An ImpactedStop records the impact to a stop +// An ImpactedStop records the impact to a stop. type ImpactedStop struct { // The impacted stop point of the trip Point StopPoint `json:"stop_point"` @@ -176,7 +176,7 @@ type PTObjectDisruptions struct { Trip Trip `json:"trip"` } -// Period of effect +// Period of effect. type Period struct { Begin time.Time `json:"begin"` End time.Time `json:"end"` diff --git a/types/disruption_json.go b/types/disruption_json.go index ce34450..86da370 100644 --- a/types/disruption_json.go +++ b/types/disruption_json.go @@ -6,7 +6,7 @@ import ( "github.com/pkg/errors" ) -// UnmarshalJSON implements json.Unmarshaller for a Disruption +// UnmarshalJSON implements json.Unmarshaller for a Disruption. func (d *Disruption) UnmarshalJSON(b []byte) error { // First let's create the analogous structure // We define some of the value as pointers to the real values, allowing us to bypass copying in cases where we don't need to process the data @@ -57,7 +57,7 @@ func (d *Disruption) UnmarshalJSON(b []byte) error { return nil } -// UnmarshalJSON implements json.Unmarshaller for a Period +// UnmarshalJSON implements json.Unmarshaller for a Period. func (p *Period) UnmarshalJSON(b []byte) error { // First let's create the analogous structure // We define some of the value as pointers to the real values, allowing us to bypass copying in cases where we don't need to process the data @@ -90,7 +90,7 @@ func (p *Period) UnmarshalJSON(b []byte) error { return nil } -// UnmarshalJSON implements json.Unmarshaller for a Severity +// UnmarshalJSON implements json.Unmarshaller for a Severity. func (s *Severity) UnmarshalJSON(b []byte) error { // First let's create the analogous structure // We define some of the value as pointers to the real values, allowing us to bypass copying in cases where we don't need to process the data diff --git a/types/equipment.go b/types/equipment.go index 6793d6a..7169a59 100644 --- a/types/equipment.go +++ b/types/equipment.go @@ -1,9 +1,9 @@ package types -// An Equipment codes for specific equipment the public transport object has +// An Equipment codes for specific equipment the public transport object has. type Equipment string -// EquipmentWheelchairAccessibility are known equipments +// EquipmentWheelchairAccessibility are known equipments. const ( EquipmentWheelchairAccessibility Equipment = "has_wheelchair_accessibility" EquipmentBikeAccepted Equipment = "has_bike_accepted" @@ -20,7 +20,7 @@ const ( EquipmentBikeDepot Equipment = "has_bike_depot" ) -// knownEquipments lists all the known equipments +// knownEquipments lists all the known equipments. var knownEquipments = [...]Equipment{ EquipmentWheelchairAccessibility, EquipmentBikeAccepted, @@ -37,7 +37,7 @@ var knownEquipments = [...]Equipment{ EquipmentBikeDepot, } -// Known reports whether an equipment is known +// Known reports whether an equipment is known. func (eq Equipment) Known() bool { for _, k := range knownEquipments { if eq == k { diff --git a/types/id.go b/types/id.go index c4f7c14..13829cf 100644 --- a/types/id.go +++ b/types/id.go @@ -9,7 +9,7 @@ import ( // An ID is used throughout the library, it is something used by the navitia API and useful to communicate with it. type ID string -// Check for ID validity +// Check for ID validity. func (id ID) Check() error { if len(id) == 0 { return errors.Errorf("ID invalid: an empty string \"\" is not a valid ID") @@ -17,7 +17,7 @@ func (id ID) Check() error { return nil } -// typeNames stores navitia-side name of types that may appear in IDs +// typeNames stores navitia-side name of types that may appear in IDs. var typeNames = map[string]bool{ "network": true, "line": true, diff --git a/types/id_test.go b/types/id_test.go index 12ada18..36659f1 100644 --- a/types/id_test.go +++ b/types/id_test.go @@ -2,7 +2,7 @@ package types import "testing" -// TestIDCheck checks if ID.Check returns an error when given an empty ID +// TestIDCheck checks if ID.Check returns an error when given an empty ID. func TestIDCheck(t *testing.T) { id := ID("") if id.Check() == nil { diff --git a/types/journeys.go b/types/journeys.go index 7305f51..b122881 100644 --- a/types/journeys.go +++ b/types/journeys.go @@ -9,7 +9,7 @@ import ( // A JourneyQualification qualifies a Journey, see const declaration. type JourneyQualification string -// JourneyXXX qualify journeys +// JourneyXXX qualify journeys. const ( JourneyBest JourneyQualification = "best" JourneyRapid JourneyQualification = "rapid" @@ -26,7 +26,7 @@ const ( // JourneyQualifications is a user-friendly slice of all journey qualification // -// As it might be used in requests, this is exported +// As it might be used in requests, this is exported. var JourneyQualifications = []JourneyQualification{ JourneyBest, JourneyRapid, @@ -41,7 +41,7 @@ var JourneyQualifications = []JourneyQualification{ JourneyNoPTBikeShare, } -// A Journey holds information about a possible journey +// A Journey holds information about a possible journey. type Journey struct { Duration time.Duration Transfers uint @@ -71,30 +71,30 @@ type CO2Emissions struct { Value float64 } -// Fare is the fare of some thing +// Fare is the fare of some thing. type Fare struct { Total currency.Amount Found bool } // TravelerType is a Traveler's type -// Defines speeds & accessibility values for different types of people +// Defines speeds & accessibility values for different types of people. type TravelerType string -// The defined types of the api +// The defined types of the api. const ( - // A standard Traveler + // A standard Traveler. TravelerStandard TravelerType = "standard" - // A slow walker + // A slow walker. TravelerSlowWalker TravelerType = "slow_walker" - // A fast walker + // A fast walker. TravelerFastWalker TravelerType = "fast_walker" - // A Traveler with luggage + // A Traveler with luggage. TravelerWithLuggage TravelerType = "luggage" - // A Traveler in a wheelchair + // A Traveler in a wheelchair. TravelerInWheelchair TravelerType = "wheelchair" ) diff --git a/types/journeys_json.go b/types/journeys_json.go index 5f804e7..446621a 100644 --- a/types/journeys_json.go +++ b/types/journeys_json.go @@ -76,7 +76,7 @@ func (j *Journey) UnmarshalJSON(b []byte) error { return nil } -// UnmarshalJSON implements json.Unmarshaller for a Fare +// UnmarshalJSON implements json.Unmarshaller for a Fare. func (f *Fare) UnmarshalJSON(b []byte) error { // First let's create the analogous structure // We define some of the value as pointers to the real values, allowing us to bypass copying in cases where we don't need to process the data @@ -116,7 +116,7 @@ func (f *Fare) UnmarshalJSON(b []byte) error { return nil } -// UnmarshalJSON implements json.Unmarshaller for CO2Emissions +// UnmarshalJSON implements json.Unmarshaller for CO2Emissions. func (c *CO2Emissions) UnmarshalJSON(b []byte) error { // First let's create the analogous structure // We define some of the value as pointers to the real values, allowing us to bypass copying in cases where we don't need to process the data diff --git a/types/journeys_test.go b/types/journeys_test.go index 6e3df4e..154d9d9 100644 --- a/types/journeys_test.go +++ b/types/journeys_test.go @@ -15,7 +15,7 @@ func Test_Journey_Unmarshal(t *testing.T) { testUnmarshal(t, testData["journey"], reflect.TypeOf(Journey{})) } -// BenchmarkJourney_UnmarshalJSON benchmarks Journey unmarshalling via subbenchmarks +// BenchmarkJourney_UnmarshalJSON benchmarks Journey unmarshalling via subbenchmarks. func BenchmarkJourney_UnmarshalJSON(b *testing.B) { // Get the bench data data := testData["journey"].bench diff --git a/types/json.go b/types/json.go index 3bf7d7f..a2e6ded 100644 --- a/types/json.go +++ b/types/json.go @@ -13,13 +13,13 @@ import ( const ( // DateTimeFormat is the format used by the Navitia Api for use with time pkg. DateTimeFormat string = "20060102T150405" // YYYYMMDDThhmmss - // DateFormat is when there is no time info + // DateFormat is when there is no time info. DateFormat string = "20060102" ) // parseDateTime parses a time formatted under iso-date-time as indicated in the Navitia api. // This is simply parsing a date formatted under the standard ISO 8601. -// If the given string is empty (i.e ""), then the zero value of time.Time will be returned +// If the given string is empty (i.e ""), then the zero value of time.Time will be returned. func parseDateTime(datetime string) (time.Time, error) { // If there's no datetime given, just return the zero value if datetime == "" || datetime == "not-a-date-time" { @@ -43,7 +43,7 @@ func parseDateTime(datetime string) (time.Time, error) { } // UnmarshalError is returned when unmarshalling fails -// It implements both error and github.com/pkg/errors's causer +// It implements both error and github.com/pkg/errors's causer. type UnmarshalError struct { // Type on which the unmarshaller where the error occurred works Type string @@ -67,12 +67,12 @@ type UnmarshalError struct { JSON []byte } -// Cause implements github.com/pkg/error's causer +// Cause implements github.com/pkg/error's causer. func (err UnmarshalError) Cause() error { return err.Underlying } -// Error implements error +// Error implements error. func (err UnmarshalError) Error() string { msg := fmt.Sprintf( "(*%s).UnmarshalJSON: Unmarshalling %s (json: \"%s\") with value \"%v\" failed", @@ -90,13 +90,13 @@ func (err UnmarshalError) Error() string { return msg } -// unmarshalErrorer allows us to make better error messages +// unmarshalErrorer allows us to make better error messages. type unmarshalErrorMaker struct { Type string JSON []byte } -// err creates a new UnmarshalError +// err creates a new UnmarshalError. func (gen unmarshalErrorMaker) err(underlyingErr error, name string, key string, value interface{}, message string) error { return UnmarshalError{ Type: gen.Type, diff --git a/types/line_json.go b/types/line_json.go index 49015df..a466969 100644 --- a/types/line_json.go +++ b/types/line_json.go @@ -7,7 +7,7 @@ import ( "github.com/pkg/errors" ) -// UnmarshalJSON implements json.Unmarshaller for a Line +// UnmarshalJSON implements json.Unmarshaller for a Line. func (l *Line) UnmarshalJSON(b []byte) error { // First let's create the analogous structure // We define some of the value as pointers to the real values, allowing us to bypass copying in cases where we don't need to process the data diff --git a/types/line_test.go b/types/line_test.go index 77d5388..c048d79 100644 --- a/types/line_test.go +++ b/types/line_test.go @@ -15,7 +15,7 @@ func Test_Line_Unmarshal(t *testing.T) { testUnmarshal(t, testData["line"], reflect.TypeOf(Line{})) } -// BenchmarkLineUnmarshal benchmarks Line unmarshalling via subbenchmarks +// BenchmarkLineUnmarshal benchmarks Line unmarshalling via subbenchmarks. func BenchmarkLineUnmarshal(b *testing.B) { // Get the bench data data := testData["line"].bench diff --git a/types/misc.go b/types/misc.go index 933716a..6329bd7 100644 --- a/types/misc.go +++ b/types/misc.go @@ -8,10 +8,10 @@ import ( "github.com/pkg/errors" ) -// DataFreshness codes for a specific data freshness requirement: realtime or base_schedule +// DataFreshness codes for a specific data freshness requirement: realtime or base_schedule. type DataFreshness string -// parseColor, given a hex code #RRGGBB returns a color.NRGBA +// parseColor, given a hex code #RRGGBB returns a color.NRGBA. func parseColor(str string) (color.NRGBA, error) { var clr color.NRGBA @@ -40,7 +40,7 @@ func parseColor(str string) (color.NRGBA, error) { } const ( - // DataFreshnessRealTime means you'll get undisrupted journeys + // DataFreshnessRealTime means you'll get undisrupted journeys. DataFreshnessRealTime DataFreshness = "realtime" // DataFreshnessBaseSchedule means you can get disrupted journeys in the response. DataFreshnessBaseSchedule = "base_schedule" diff --git a/types/mode.go b/types/mode.go index 28389c0..72e8c81 100644 --- a/types/mode.go +++ b/types/mode.go @@ -1,12 +1,12 @@ package types -// ModeXXX are known non-public transportation mode +// ModeXXX are known non-public transportation mode. const ( ModeWalking = "walking" ModeBike = "bike" ModeCar = "car" - // Not used in Section + // Not used in Section. ModeBikeShare = "bss" ) @@ -46,7 +46,7 @@ type PhysicalMode struct { CommercialModes []CommercialMode `json:"commercial_mode"` } -// PhysicalModeXXX are the possible physical modes in ID form +// PhysicalModeXXX are the possible physical modes in ID form. const ( PhysicalModeAir ID = "physical_mode:Air" PhysicalModeBoat ID = "physical_mode:Boat" diff --git a/types/path.go b/types/path.go index b00b810..7e8540b 100644 --- a/types/path.go +++ b/types/path.go @@ -2,7 +2,7 @@ package types import "time" -// A PathSegment (called Path item in the Navitia API) is a part of a path +// A PathSegment (called Path item in the Navitia API) is a part of a path. type PathSegment struct { // The Length of the segment Length uint `json:"length"` diff --git a/types/path_json.go b/types/path_json.go index 0559bfc..0ccf4b4 100644 --- a/types/path_json.go +++ b/types/path_json.go @@ -7,7 +7,7 @@ import ( "github.com/pkg/errors" ) -// UnmarshalJSON implements json.Unmarshaller for a PathSegment +// UnmarshalJSON implements json.Unmarshaller for a PathSegment. func (ps *PathSegment) UnmarshalJSON(b []byte) error { // First let's create the analogous structure // We define some of the value as pointers to the real values, allowing us to bypass copying in cases where we don't need to process the data diff --git a/types/place.go b/types/place.go index 3f8898d..f148ee5 100644 --- a/types/place.go +++ b/types/place.go @@ -35,7 +35,7 @@ type StopArea struct { Timezone string `json:"timezone"` } -// A POIType codes for the type of the point of interest +// A POIType codes for the type of the point of interest. type POIType struct { ID ID `json:"id"` Name string `json:"name"` diff --git a/types/region_json.go b/types/region_json.go index 2ad658b..b73251b 100644 --- a/types/region_json.go +++ b/types/region_json.go @@ -8,7 +8,7 @@ import ( "github.com/twpayne/go-geom" ) -// UnmarshalJSON implements json.Unmarshaller for a Region +// UnmarshalJSON implements json.Unmarshaller for a Region. func (r *Region) UnmarshalJSON(b []byte) error { // First let's create the analogous structure data := &struct { @@ -90,7 +90,7 @@ func (r *Region) UnmarshalJSON(b []byte) error { return nil } -// convertWktMPtoGeomMP converts a wkt MultiPolygon to a geom MultiPolygon +// convertWktMPtoGeomMP converts a wkt MultiPolygon to a geom MultiPolygon. func convertWktMPtoGeomMP(in *wkt.MultiPolygon) (*geom.MultiPolygon, error) { // Now let's convert it to a geom format // First let's create the geom.MultiPolygon diff --git a/types/region_test.go b/types/region_test.go index 895520f..d001db0 100644 --- a/types/region_test.go +++ b/types/region_test.go @@ -17,7 +17,7 @@ func Test_Region_Unmarshal(t *testing.T) { testUnmarshal(t, testData["region"], reflect.TypeOf(Region{})) } -// TestRegionUnmarshal_ShapeInvalidMKT tests known invalid MKT (well-known text) -encoded Region.Shape inputs for (*Region).UnmarshalJSON +// TestRegionUnmarshal_ShapeInvalidMKT tests known invalid MKT (well-known text) -encoded Region.Shape inputs for (*Region).UnmarshalJSON. func TestRegionUnmarshal_ShapeInvalidMKT(t *testing.T) { // Shapes shapes := [...]string{ @@ -42,7 +42,7 @@ func TestRegionUnmarshal_ShapeInvalidMKT(t *testing.T) { } } -// BenchmarkRegionUnmarshal benchmarks Region unmarshalling via subbenchmarks +// BenchmarkRegionUnmarshal benchmarks Region unmarshalling via subbenchmarks. func BenchmarkRegionUnmarshal(b *testing.B) { // Get the bench data data := testData["region"].bench diff --git a/types/route_json.go b/types/route_json.go index 6f86390..192af5a 100644 --- a/types/route_json.go +++ b/types/route_json.go @@ -6,7 +6,7 @@ import ( "github.com/pkg/errors" ) -// UnmarshalJSON implements json.Unmarshaller for Route +// UnmarshalJSON implements json.Unmarshaller for Route. func (r *Route) UnmarshalJSON(b []byte) error { // First let's create the analogous structure // We define some of the value as pointers to the real values, allowing us to bypass copying in cases where we don't need to process the data diff --git a/types/section.go b/types/section.go index 2fb8078..43e2e55 100644 --- a/types/section.go +++ b/types/section.go @@ -6,7 +6,7 @@ import ( "github.com/twpayne/go-geom" ) -// A Section holds information about a specific section +// A Section holds information about a specific section. type Section struct { Type SectionType ID ID @@ -39,48 +39,48 @@ type Section struct { Additional []PTMethod } -// A SectionType codifies the type of section that can be encountered +// A SectionType codifies the type of section that can be encountered. type SectionType string -// These are the types of sections that can be returned from the API +// These are the types of sections that can be returned from the API. const ( - // Public transport section + // Public transport section. SectionPublicTransport SectionType = "public_transport" - // Street section + // Street section. SectionStreetNetwork SectionType = "street_network" - // Waiting section between transport + // Waiting section between transport. SectionWaiting SectionType = "waiting" // This “stay in the vehicle” section occurs when the traveller has to stay in the vehicle when the bus change its routing. SectionStayIn SectionType = "stay_in" - // Transfer section + // Transfer section. SectionTransfer SectionType = "transfer" // Teleportation section. Used when starting or arriving to a city or a stoparea (“potato shaped” objects) Useful to make navitia idempotent. - // Warning: Be careful: no Path nor Geo items in this case + // Warning: Be careful: no Path nor Geo items in this case. SectionCrowFly SectionType = "crow_fly" // Vehicle may not drive along: traveler will have to call agency to confirm journey - // Also sometimes called ODT + // Also sometimes called ODT. SectionOnDemandTransport SectionType = "on_demand_transport" - // Taking a bike from a bike sharing system (bss) + // Taking a bike from a bike sharing system (bss). SectionBikeShareRent SectionType = "bss_rent" - // Putting back a bike from a bike sharing system (bss) + // Putting back a bike from a bike sharing system (bss). SectionBikeSharePutBack SectionType = "bss_put_back" - // Boarding on plane + // Boarding on plane. SectionBoarding SectionType = "boarding" - // Landing off the plane + // Landing off the plane. SectionLanding SectionType = "landing" ) -// SectionTypes is the type of a section +// SectionTypes is the type of a section. var SectionTypes = map[SectionType]string{ SectionPublicTransport: "Public transport section", SectionStreetNetwork: "Street section", @@ -103,23 +103,23 @@ type StopTime struct { // The stop point in question StopPoint StopPoint `json:"stop_point"` - DropOffAllowed bool `json:"drop_off_allowed"` - UTCDepartureTime string `json:"utc_departure_time"` Headsign string `json:"headsign"` UTCArrivalTime string `json:"utc_arrival_time"` + DepartureTime string `json:"departure_time"` + PickupAllowed bool `json:"pickup_allowed"` - DepartureTime string `json:"departure_time"` + DropOffAllowed bool `json:"drop_off_allowed"` } -// A PTMethod is a Public Transportation method: it can be regular, estimated times or ODT (on-demand transport) +// A PTMethod is a Public Transportation method: it can be regular, estimated times or ODT (on-demand transport). type PTMethod string -// PTMethodXXX codes for known PTMethod +// PTMethodXXX codes for known PTMethod. const ( // PTMethodRegular: No on-demand transport. Line does not contain any estimated stop times, nor zonal stop point location. No need to call too. PTMethodRegular PTMethod = "regular" @@ -133,6 +133,6 @@ const ( // PTMethodODTStopPoint: Line can contain some estimated stop times, but no zonal stop point location. And you will have to call to take it. PTMethodODTStopPoint PTMethod = "odt_with_stop_point" - // PTMethodODTZone: Line can contain some estimated stop times, and zonal stop point location. And you will have to call to take it. Well, not really a public transport line, more a cab… + // PTMethodODTZone: Line can contain some estimated stop times, and zonal stop point location. And you will have to call to take it. Well, not really a public transport line, more a cab…. PTMethodODTZone PTMethod = "odt_with_zone" ) diff --git a/types/section_json.go b/types/section_json.go index bc66276..9e2a01a 100644 --- a/types/section_json.go +++ b/types/section_json.go @@ -94,7 +94,7 @@ func (s *Section) UnmarshalJSON(b []byte) error { return nil } -// UnmarshalJSON implements json.Unmarshaller for a PTDateTime +// UnmarshalJSON implements json.Unmarshaller for a PTDateTime. func (ptdt *PTDateTime) UnmarshalJSON(b []byte) error { // First let's create the analogous structure data := &struct { diff --git a/types/trafficreport.go b/types/trafficreport.go index a5be645..66767bd 100644 --- a/types/trafficreport.go +++ b/types/trafficreport.go @@ -4,7 +4,7 @@ package types // Named "traffic_report" in the Navitia doc // // See http://doc.navitia.io/#traffic-reports -// TODO: Add the internal links +// TODO: Add the internal links. type TrafficReport struct { // Main object (network) and links within its own disruptions Network Network `json:"network"` diff --git a/types/types_test.go b/types/types_test.go index 2141d1e..ccb51d6 100644 --- a/types/types_test.go +++ b/types/types_test.go @@ -39,7 +39,7 @@ type testPair struct { correct interface{} } -// Convert testing mechanism to known compare + corpus runs +// Convert testing mechanism to known compare + corpus runs. type typeTestData struct { known map[string]testPair // Hardcoded map of pairs of JSON data / the Go representation they should have correct map[string][]byte // Map of known correct files to be parsed (they should _not_ return an error) @@ -47,11 +47,11 @@ type typeTestData struct { bench map[string][]byte // Descriptions -> File } -// testData stores a map which maps each category to their data +// testData stores a map which maps each category to their data. var testData = make(map[string]typeTestData, len(typesList)) // this is the list of potential types -// must be lower case +// must be lower case. var typesList = [...]string{ "journey", "coverage", @@ -62,7 +62,7 @@ var typesList = [...]string{ "company", } -// listCategoryDirs retrieves the subdirectories under the main testdata directory +// listCategoryDirs retrieves the subdirectories under the main testdata directory. func listCategoryDirs(path string) ([]os.FileInfo, error) { mainSubdirs, err := ioutil.ReadDir(path) if err != nil { @@ -82,7 +82,7 @@ func listCategoryDirs(path string) ([]os.FileInfo, error) { return subDirsInfo, nil } -// extractCorpus extracts a corpus +// extractCorpus extracts a corpus. func extractCorpus(path string) (map[string][]byte, error) { // List the files files, err := ioutil.ReadDir(path) @@ -120,7 +120,7 @@ func extractCorpus(path string) (map[string][]byte, error) { return corpus, nil } -// getPertinentSubdirs, given a dir in a category subdirectory, returns the awaited values +// getPertinentSubdirs, given a dir in a category subdirectory, returns the awaited values. func getCategory(path string) (typeTestData, error) { // Create the data data := typeTestData{} @@ -160,7 +160,7 @@ func getCategory(path string) (typeTestData, error) { return data, nil } -// load loads the file structing into the testData +// load loads the file structing into the testData. func load() error { subDirsInfo, err := listCategoryDirs(testDataPath) if err != nil { diff --git a/utils/requestBuilder.go b/utils/requestBuilder.go index 1206168..a0fd89a 100644 --- a/utils/requestBuilder.go +++ b/utils/requestBuilder.go @@ -13,7 +13,7 @@ type RequestBuilder struct { params *url.Values } -// NewRequestBuilder create and return a new instance of RequestBuilder +// NewRequestBuilder create and return a new instance of RequestBuilder. func NewRequestBuilder() RequestBuilder { return RequestBuilder{params: &url.Values{}} } @@ -58,7 +58,7 @@ func (rb RequestBuilder) AddIDSlice(key string, ids []types.ID) { } } -// AddMode add a mode list to the request +// AddMode add a mode list to the request. func (rb RequestBuilder) AddMode(key string, modes []string) { if len(modes) != 0 { for _, mode := range modes { @@ -67,14 +67,14 @@ func (rb RequestBuilder) AddMode(key string, modes []string) { } } -// AddDate add a date time to the request (YYYYMMDDThhmmss) +// AddDate add a date time to the request (YYYYMMDDThhmmss). func (rb RequestBuilder) AddDateTime(key string, date time.Time) { if !date.IsZero() { rb.params.Add(key, date.Format(types.DateTimeFormat)) } } -// Values return value of url.Values +// Values return value of url.Values. func (rb RequestBuilder) Values() url.Values { return *rb.params } \ No newline at end of file diff --git a/vehicleJourney.go b/vehicleJourney.go index e2ace22..41893c9 100644 --- a/vehicleJourney.go +++ b/vehicleJourney.go @@ -24,12 +24,12 @@ type VehicleJourneyResults struct { session *Session } -// Count returns the number of results available in a JourneyResults +// Count returns the number of results available in a JourneyResults. func (jr *VehicleJourneyResults) Count() int { return len(jr.VehicleJourneys) } -// VehicleJourneyRequest contain the parameters needed to make a Journey request +// VehicleJourneyRequest contain the parameters needed to make a Journey request. type VehicleJourneyRequest struct { ID types.ID // There must be at least one From or To parameter defined @@ -38,8 +38,7 @@ type VehicleJourneyRequest struct { To types.ID // When do you want to depart ? Or is DateIsArrival when do you want to arrive at your destination. - Date time.Time - DateIsArrival bool + Date time.Time // The traveller's type Traveler types.TravelerType @@ -87,9 +86,6 @@ type VehicleJourneyRequest struct { // Maximum duration of a trip MaxDuration time.Duration // To seconds - // Wheelchair restricts the answer to accessible public transports - Wheelchair bool - // Headsign If given, add a filter on the vehicle journeys that has the // given value as headsign (on vehicle journey itself or at a stop time). Headsign string @@ -98,10 +94,15 @@ type VehicleJourneyRequest struct { Since time.Time // Until, like Since, filter on a period, optional too. Until time.Time + + // Wheelchair restricts the answer to accessible public transports + Wheelchair bool + + DateIsArrival bool } // toURL formats a journey request to url -// Should be refactored using a switch statement +// Should be refactored using a switch statement. func (req VehicleJourneyRequest) toURL() (url.Values, error) { rb := utils.NewRequestBuilder()