-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
36 lines (32 loc) · 807 Bytes
/
server.go
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
package krkstops
import (
"github.com/PiotrKozimor/krkstops/pb"
"github.com/PiotrKozimor/krkstops/pkg/search"
"github.com/PiotrKozimor/krkstops/pkg/ttss"
)
type KrkStopsServer struct {
pb.UnimplementedKrkStopsServer
depsCache cache[[]typedDeparture]
ttssBusCli ttssClient
ttssTramCli ttssClient
searchCli *search.Search
}
type ttssClient interface {
GetDepartures(uint) ([]ttss.Departure, error)
// GetAllStops() ([]Stop, error)
}
func NewServer() (*KrkStopsServer, error) {
s, err := search.New()
if err != nil {
return nil, err
}
return &KrkStopsServer{
depsCache: cache[[]typedDeparture]{
d: make(map[uint]entry[[]typedDeparture], 50),
ttl: depsExpire,
},
ttssBusCli: ttss.NewClient(ttss.Bus),
ttssTramCli: ttss.NewClient(ttss.Tram),
searchCli: s,
}, nil
}