mirror of
https://github.com/v2ray/v2ray-core.git
synced 2026-11-22 15:12:48 +00:00
remove use of any
This commit is contained in:
72 files changed
+728
-792
No files matched your search
@@ -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
|
||||
}
|
||||
@@ -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")
|
||||
}
|
||||
Reference in new issue
Block a user