-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathroutemap.go
41 lines (36 loc) · 1.23 KB
/
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
39
40
41
package sniproxy
import (
"encoding/json"
"fmt"
"os"
)
//HostMap lists the MethodPathMaps to each Host
type HostMap struct {
Host string `json:"Host"`
MethodPathMaps []MethodPathMap `json:"MethodPathMaps"`
}
//MethodPathMap maps each inbound method+path combination to backend route
type MethodPathMap struct {
Method string `json:"Method"`
Path string `json:"Path"`
Route []interface{} `json:"Route"`
AuthenticatorScheme string `json:"AuthenticatorScheme"`
TokenType string `json:"TokenType"`
MaxRequestBodyBytes *int64 `json:"MaxRequestBodyBytes,omitempty"`
}
//RouteMap is a collection of HostMap called Routes
type RouteMap struct {
Routes []HostMap `json:"Routes"`
}
func buildRouteMap(routeMapFilePath *string, routeMap *RouteMap) error {
routeMapFile, fileErr := os.Open(*routeMapFilePath)
if fileErr != nil {
return fmt.Errorf("Error while opening routeMapFile -%#v: %#v", *routeMapFilePath, fileErr.Error())
}
routeMapDecoder := json.NewDecoder(routeMapFile)
decodeErr := routeMapDecoder.Decode(routeMap)
if decodeErr != nil {
return fmt.Errorf("Error while decoding Json: %#v", decodeErr.Error())
}
return nil
}