github.com/imannamdari/v2ray-core/v5@v5.0.5/infra/conf/v5cfg/common.go (about) 1 package v5cfg 2 3 import ( 4 "context" 5 "encoding/json" 6 7 "github.com/golang/protobuf/proto" 8 9 "github.com/imannamdari/v2ray-core/v5/common/environment/envctx" 10 "github.com/imannamdari/v2ray-core/v5/common/environment/envimpl" 11 "github.com/imannamdari/v2ray-core/v5/common/registry" 12 ) 13 14 func loadHeterogeneousConfigFromRawJSON(interfaceType, name string, rawJSON json.RawMessage) (proto.Message, error) { 15 fsdef := envimpl.NewDefaultFileSystemDefaultImpl() 16 ctx := envctx.ContextWithEnvironment(context.TODO(), fsdef) 17 if len(rawJSON) == 0 { 18 rawJSON = []byte("{}") 19 } 20 return registry.LoadImplementationByAlias(ctx, interfaceType, name, []byte(rawJSON)) 21 } 22 23 // LoadHeterogeneousConfigFromRawJSON private API 24 func LoadHeterogeneousConfigFromRawJSON(ctx context.Context, interfaceType, name string, rawJSON json.RawMessage) (proto.Message, error) { 25 return loadHeterogeneousConfigFromRawJSON(interfaceType, name, rawJSON) 26 }