Skip to content

Commit

Permalink
Cleanup (#15)
Browse files Browse the repository at this point in the history
* Remove unused bump go.mod

* prevent panics, fix pointers

* update travis

* echo go version for sanity
  • Loading branch information
Setheck committed Mar 13, 2020
1 parent f5e8dab commit 7e1cf15
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 27 deletions.
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@ language: go
env:
- GO111MODULE=on
install:
- go version
- go get golang.org/x/tools/cmd/cover
- go get github.com/mattn/goveralls
matrix:
include:
- go: "1.10.x"
- go: "1.x"
script:
- go get -u github.com/stretchr/testify
- go get -u github.com/spf13/viper
- go get -u github.com/spf13/cobra
- go mod tidy
- go test -v -covermode=count -coverprofile=coverage.out ./...
- $HOME/gopath/bin/goveralls -coverprofile=coverage.out -service=travis-ci -repotoken $COVERALLS_TOKEN
- go: "1.11.x"
script:
- go build ./...
- go test -v -covermode=count -coverprofile=coverage.out ./...
- go build ./...
- $HOME/gopath/bin/goveralls -coverprofile=coverage.out -service=travis-ci -repotoken $COVERALLS_TOKEN
3 changes: 1 addition & 2 deletions defaultclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -1502,8 +1502,7 @@ func (c DefaultClient) VehiclesForAgency(id string) ([]VehicleStatus, error) {
routes := data.Routes(agencies)
stops := data.Stops(routes)
trips := data.Trips()
situations := data.Situations()
vhs := data.List.toVehicleStatuses(situations, stops, trips)
vhs := data.List.toVehicleStatuses(stops, trips)
return vhs, nil
}

Expand Down
16 changes: 4 additions & 12 deletions entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func (e Entry) ToArrivalAndDeparture(sis []Situation, st []Stop, ts []Trip) *Arr
StopSequence: e.StopSequence,
TripID: e.TripID,
TripHeadSign: e.TripHeadSign,
TripStatus: e.ToTripStatus(sis, st, ts),
TripStatus: e.ToTripStatus(st),
VehicleID: e.VehicleID,
}
}
Expand Down Expand Up @@ -497,7 +497,7 @@ func (e Entry) ToTripDetails(ts []Trip, ss []Situation) *TripDetails {
}
}

func (e Entry) ToTripStatus(sis []Situation, ss []Stop, ts []Trip) *TripStatus {
func (e Entry) ToTripStatus(ss []Stop) *TripStatus {
var cstop Stop
var nstop Stop
for _, s := range ss {
Expand All @@ -508,14 +508,6 @@ func (e Entry) ToTripStatus(sis []Situation, ss []Stop, ts []Trip) *TripStatus {
cstop = s
}
}
situations := make([]Situation, 0, len(sis))
for _, si := range sis {
for _, sid := range e.SituationIDs {
if sid == si.ID {
situations = append(situations, si)
}
}
}

return &TripStatus{
ActiveTripID: e.ActiveTripID,
Expand Down Expand Up @@ -545,7 +537,7 @@ func (e Entry) ToTripStatus(sis []Situation, ss []Stop, ts []Trip) *TripStatus {
}
}

func (e Entry) ToVehicleStatus(sis []Situation, ss []Stop, ts []Trip) (ret *VehicleStatus) {
func (e Entry) ToVehicleStatus(ss []Stop, ts []Trip) (ret *VehicleStatus) {
var trip Trip
for _, t := range ts {
if t.ID == e.TripID {
Expand All @@ -556,7 +548,7 @@ func (e Entry) ToVehicleStatus(sis []Situation, ss []Stop, ts []Trip) (ret *Vehi

var tstatus TripStatus
if e.TripStatus != nil {
tstatus = *e.TripStatus.ToTripStatus(sis, ss, ts)
tstatus = *e.TripStatus.ToTripStatus(ss)
}
var loc Location
if e.Location != nil {
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module github.com/Setheck/oba

go 1.14

require (
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions list.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ func (l List) toTripDetails(ts []Trip, ss []Situation) []TripDetails {
return tds
}

func (l List) toVehicleStatuses(sits []Situation, st []Stop, ts []Trip) []VehicleStatus {
func (l List) toVehicleStatuses(st []Stop, ts []Trip) []VehicleStatus {
vss := make([]VehicleStatus, 0, len(l))
for _, entry := range l {
vhs := *entry.ToVehicleStatus(sits, st, ts)
vhs := *entry.ToVehicleStatus(st, ts)
vss = append(vss, vhs)
}
return vss
Expand Down
12 changes: 6 additions & 6 deletions requestutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ func makeGetRequest(url string) ([]byte, error) {
return body, nil
}

func handleResponse(r Response) error {
func handleResponse(r *Response) error {
if r.Code != http.StatusOK {
return fmt.Errorf("code: %d %v", r.Code, r.Text)
}
return nil
}

func handleAltResponse(r AltResponse) error {
func handleAltResponse(r *AltResponse) error {
if r.Code != http.StatusOK {
return fmt.Errorf("code: %d %v", r.Code, r.Text)
}
Expand All @@ -41,7 +41,7 @@ func unmarshalResponse(data []byte) *Response {
response := &Response{}
err := json.Unmarshal(data, response)
if err != nil {
panic(err)
fmt.Println("error un-marshaling response", err)
}
return response
}
Expand All @@ -50,7 +50,7 @@ func unmarshalAltResponse(data []byte) *AltResponse {
response := &AltResponse{}
err := json.Unmarshal(data, response)
if err != nil {
panic(err)
fmt.Println("error un-marshaling response", err)
}
return response
}
Expand All @@ -61,7 +61,7 @@ func requestAndHandle(u, errmsg string) (*Response, error) {
return nil, errors.New(errmsg + err.Error())
}
response := unmarshalResponse(body)
if err := handleResponse(*response); err != nil {
if err := handleResponse(response); err != nil {
return nil, errors.New(errmsg + err.Error())
}
return response, nil
Expand All @@ -73,7 +73,7 @@ func requestAndHandleAlt(u, errmsg string) (*AltResponse, error) {
return nil, errors.New(errmsg + err.Error())
}
response := unmarshalAltResponse(body)
if err := handleAltResponse(*response); err != nil {
if err := handleAltResponse(response); err != nil {
return nil, errors.New(errmsg + err.Error())
}
return response, nil
Expand Down

0 comments on commit 7e1cf15

Please sign in to comment.