Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions departures.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
16 changes: 8 additions & 8 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@ 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
RemoteErrNoDestination RemoteErrorID = "no_destination" // Couldn’t find an destination for the journeys
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"
)

// 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",
Expand All @@ -40,15 +40,15 @@ 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"`
Message string `json:"message"`
}

// 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

Expand All @@ -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}

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var (
testSession *Session
)

// Initialise testing function
// Initialise testing function.
func init() {
// Populate flags
flag.Parse()
Expand Down
17 changes: 9 additions & 8 deletions journeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,20 @@ 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.
From types.ID
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
Expand Down Expand Up @@ -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()

Expand Down
8 changes: 4 additions & 4 deletions logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
14 changes: 7 additions & 7 deletions navitia_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,27 @@ 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)
incorrect map[string][]byte // Map of known incorrect files to be parsed (they _should_ return an error)
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",
"places",
"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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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{}
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions paging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,15 +23,15 @@ 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)
}
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)
Expand Down
6 changes: 3 additions & 3 deletions places.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions pretty/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
6 changes: 3 additions & 3 deletions pretty/journey.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand All @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions pretty/journeyresults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions pretty/placesresults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading