-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstation.go
More file actions
63 lines (46 loc) · 991 Bytes
/
station.go
File metadata and controls
63 lines (46 loc) · 991 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package traincat
import (
"fmt"
"github.com/train-cat/client-train-go/filters"
)
type (
// Station output of the API
Station struct {
Entity
Name string `json:"name"`
UIC string `json:"uic"`
IsRealTime bool `json:"is_realtime"`
Hateoas
}
)
// GetStation return one station
func GetStation(stationID int) (*Station, error) {
s := &Station{}
_, err := r(false).SetResult(s).
Get(fmt.Sprintf(EndpointStation, stationID))
return s, err
}
// CGetAllStations get all pages and return all stations
func CGetAllStations(f *filters.Station) ([]Station, error) {
c := &Collection{}
req := r(false).
SetResult(c)
_, err := filters.Apply(req, f).Get(EndpointStations)
if err != nil {
return nil, err
}
var ss []Station
for err == nil {
var tmp []Station
err = c.Embedded.Get(EmbeddedItems, &tmp)
if err != nil {
return nil, err
}
ss = append(ss, tmp...)
if c.IsLastPage() {
break
}
err = c.Next()
}
return ss, err
}