remove use of any

This commit is contained in:
Darien Raymond committed 2016-10-16 14:22:21 +02:00
1 parent 5d9e6b0799
commit e33b7df34c
72 files changed
+728 -792

No files matched your search

-50
View File
@@ -1,50 +0,0 @@
package registry
import (
"v2ray.com/core/common/loader"
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/any"
)
var (
inboundConfigCreatorCache = loader.ConfigCreatorCache{}
outboundConfigCreatorCache = loader.ConfigCreatorCache{}
)
func RegisterInboundConfig(protocol string, creator loader.ConfigCreator) error {
return inboundConfigCreatorCache.RegisterCreator(protocol, creator)
}
func RegisterOutboundConfig(protocol string, creator loader.ConfigCreator) error {
return outboundConfigCreatorCache.RegisterCreator(protocol, creator)
}
func MarshalInboundConfig(protocol string, settings *any.Any) (interface{}, error) {
config, err := inboundConfigCreatorCache.CreateConfig(protocol)
if err != nil {
return nil, err
}
if settings == nil {
return config, nil
}
if err := ptypes.UnmarshalAny(settings, config.(proto.Message)); err != nil {
return nil, err
}
return config, nil
}
func MarshalOutboundConfig(protocol string, settings *any.Any) (interface{}, error) {
config, err := outboundConfigCreatorCache.CreateConfig(protocol)
if err != nil {
return nil, err
}
if settings == nil {
return config, nil
}
if err := ptypes.UnmarshalAny(settings, config.(proto.Message)); err != nil {
return nil, err
}
return config, nil
}
-25
View File
@@ -1,25 +0,0 @@
// +build json
package registry
import (
"v2ray.com/core/common/loader"
)
var (
inboundConfigCache loader.ConfigLoader
outboundConfigCache loader.ConfigLoader
)
func CreateInboundConfig(protocol string, data []byte) (interface{}, error) {
return inboundConfigCache.LoadWithID(data, protocol)
}
func CreateOutboundConfig(protocol string, data []byte) (interface{}, error) {
return outboundConfigCache.LoadWithID(data, protocol)
}
func init() {
inboundConfigCache = loader.NewJSONConfigLoader(inboundConfigCreatorCache, "protocol", "settings")
outboundConfigCache = loader.NewJSONConfigLoader(outboundConfigCreatorCache, "protocol", "settings")
}