-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathxds.go
32 lines (26 loc) · 965 Bytes
/
xds.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
package api
import (
"fmt"
"github.com/golang/protobuf/ptypes/any"
)
// XDSConfigHandler converts a map according to any.Any
type XDSConfigHandler func(s *any.Any) (map[string]interface{}, error)
var registryXDSConfigFactory map[string]XDSConfigHandler
func init() {
registryXDSConfigFactory = make(map[string]XDSConfigHandler)
}
// RegisterXDSConfigHandler registers the filterType as XDSConfigHandler
func RegisterXDSConfigHandler(filterType string, creator XDSConfigHandler) {
registryXDSConfigFactory[filterType] = creator
}
// HandleXDSConfig converts pb Any to map according to the filterType
func HandleXDSConfig(filterType string, s *any.Any) (map[string]interface{}, error) {
if cf, ok := registryXDSConfigFactory[filterType]; ok {
config, err := cf(s)
if err != nil {
return nil, fmt.Errorf("convert pb.Any to map failed: %v", err)
}
return config, nil
}
return nil, fmt.Errorf("unsupported stream filter type: %v", filterType)
}