-
Notifications
You must be signed in to change notification settings - Fork 353
/
Copy pathfile.go
40 lines (31 loc) · 1.17 KB
/
file.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
37
38
39
40
package eskipfile
import (
"os"
"github.com/zalando/skipper/eskip"
)
// Client contains the route definitions from an eskip file, not implementing file watch. Use the Open function
// to create instances of it.
type Client struct{ routes []*eskip.Route }
// Opens an eskip file and parses it, returning a DataClient implementation. If reading or parsing the file
// fails, returns an error. This implementation doesn't provide file watch.
func Open(path string) (*Client, error) {
content, err := os.ReadFile(path)
if err != nil {
return nil, err
}
routes, err := eskip.Parse(string(content))
if err != nil {
return nil, err
}
return &Client{routes}, nil
}
func (c Client) LoadAndParseAll() (routeInfos []*eskip.RouteInfo, err error) {
for _, route := range c.routes {
routeInfos = append(routeInfos, &eskip.RouteInfo{Route: *route})
}
return
}
// LoadAll returns the parsed route definitions found in the file.
func (c Client) LoadAll() ([]*eskip.Route, error) { return c.routes, nil }
// LoadUpdate: noop. The current implementation doesn't support watching the eskip file for changes.
func (c Client) LoadUpdate() ([]*eskip.Route, []string, error) { return nil, nil, nil }