-
Notifications
You must be signed in to change notification settings - Fork 1
/
routemap.go
38 lines (33 loc) · 904 Bytes
/
routemap.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
package main
import (
"encoding/json"
"fmt"
"os"
)
//HostMap lists the MethodPathMaps to each Host
type HostMap struct {
Host string
MethodPathMaps []MethodPathMap
}
//MethodPathMap maps each inbound method+path combination to backend route
type MethodPathMap struct {
Method string
Path string
Route []interface{}
}
//RouteMap is a collection of HostMap called Routes
type RouteMap struct {
Routes []HostMap
}
func buildRouteMap(routeMapFilePath *string, routeMap *RouteMap) error {
routeMapFile, fileErr := os.Open(*routeMapFilePath)
if fileErr != nil {
return fmt.Errorf("\nError while opening routeMapFile -%#v: %#v", *routeMapFilePath, fileErr.Error())
}
routeMapDecoder := json.NewDecoder(routeMapFile)
decodeErr := routeMapDecoder.Decode(routeMap)
if decodeErr != nil {
return fmt.Errorf("\nError while decoding Json: %#v", decodeErr.Error())
}
return nil
}