ztelur commented on a change in pull request #347:
URL: https://github.com/apache/dubbo-go-pixiu/pull/347#discussion_r784065166
##########
File path: pkg/filterchain/network_filter_chain.go
##########
@@ -34,51 +38,74 @@ type NetworkFilterChain struct {
config model.FilterChain
}
+// ServeHTTP handle http request
func (fc NetworkFilterChain) ServeHTTP(w http.ResponseWriter, r *http.Request)
{
// todo: only one filter will exist for now, needs change when more
than one
for _, filter := range fc.filtersArray {
filter.ServeHTTP(w, r)
}
}
-func CreateNetworkFilterChain(config model.FilterChain, bs *model.Bootstrap)
*NetworkFilterChain {
- filtersArray := make([]filter.NetworkFilter, len(config.Filters))
- // todo: split code block like http filter manager
+// OnDecode decode bytes received from getty listener
+func (fc NetworkFilterChain) OnDecode(data []byte) (interface{}, int, error) {
// todo: only one filter will exist for now, needs change when more
than one
- for i, f := range config.Filters {
- if f.Name == constant.GRPCConnectManagerFilter {
- gcmc := &model.GRPCConnectionManagerConfig{}
- if err := yaml.ParseConfig(gcmc, f.Config); err != nil {
- logger.Error("CreateNetworkFilterChain %s parse
config error %s", f.Name, err)
- }
- p, err :=
filter.GetNetworkFilterPlugin(constant.GRPCConnectManagerFilter)
- if err != nil {
- logger.Error("CreateNetworkFilterChain %s
getNetworkFilterPlugin error %s", f.Name, err)
- }
- filter, err := p.CreateFilter(gcmc, bs)
- if err != nil {
- logger.Error("CreateNetworkFilterChain %s
createFilter error %s", f.Name, err)
- }
- filtersArray[i] = filter
- } else if f.Name == constant.HTTPConnectManagerFilter {
- hcmc := &model.HttpConnectionManagerConfig{}
- if err := yaml.ParseConfig(hcmc, f.Config); err != nil {
- logger.Error("CreateNetworkFilterChain parse %s
config error %s", f.Name, err)
- }
- p, err :=
filter.GetNetworkFilterPlugin(constant.HTTPConnectManagerFilter)
- if err != nil {
- logger.Error("CreateNetworkFilterChain %s
getNetworkFilterPlugin error %s", f.Name, err)
- }
- filter, err := p.CreateFilter(hcmc, bs)
- if err != nil {
- logger.Error("CreateNetworkFilterChain %s
createFilter error %s", f.Name, err)
- }
- filtersArray[i] = filter
+ for _, filter := range fc.filtersArray {
+ return filter.OnDecode(data)
+ }
+ return nil, 0, errors.Errorf("filterChain don't have network filter")
+}
+
+// OnEncode encode struct to bytes sent to getty listener
+func (fc NetworkFilterChain) OnEncode(p interface{}) ([]byte, error) {
+ // todo: only one filter will exist for now, needs change when more
than one
+ for _, filter := range fc.filtersArray {
+ return filter.OnEncode(p)
+ }
+ return nil, errors.Errorf("filterChain don't have network filter")
+}
+
+// OnData handle dubbo rpc invocation
+func (fc NetworkFilterChain) OnData(data interface{}) (interface{}, error) {
+ // todo: only one filter will exist for now, needs change when more
than one
+ for _, filter := range fc.filtersArray {
+ return filter.OnData(data)
+ }
+ return nil, errors.Errorf("filterChain don't have network filter")
+}
+
+// OnTripleData handle triple rpc invocation
+func (fc *NetworkFilterChain) OnTripleData(ctx context.Context, methodName
string, arguments []interface{}) (interface{}, error) {
+ // todo: only one filter will exist for now, needs change when more
than one
+ for _, filter := range fc.filtersArray {
+ return filter.OnTripleData(ctx, methodName, arguments)
+ }
+ return nil, errors.Errorf("filterChain don't have network filter")
+}
+
+// CreateNetworkFilterChain create network filter chain
+func CreateNetworkFilterChain(config model.FilterChain, bs *model.Bootstrap)
*NetworkFilterChain {
+ var filters []filter.NetworkFilter
+
+ for _, f := range config.Filters {
+ p, err := filter.GetNetworkFilterPlugin(f.Name)
+ if err != nil {
+ logger.Error("CreateNetworkFilterChain %s
getNetworkFilterPlugin error %s", f.Name, err)
+ }
+
+ config := p.Config()
+ if err := yaml.ParseConfig(config, f.Config); err != nil {
+ logger.Error("CreateNetworkFilterChain %s parse config
error %s", f.Name, err)
+ }
+
+ filter, err := p.CreateFilter(config, bs)
+ if err != nil {
+ logger.Error("CreateNetworkFilterChain %s createFilter
error %s", f.Name, err)
Review comment:
Done
##########
File path: pkg/filter/network/dubboproxy/manager.go
##########
@@ -0,0 +1,198 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dubboproxy
+
+import (
+ "context"
+ "reflect"
+)
+
+import (
+ dubboConstant "dubbo.apache.org/dubbo-go/v3/common/constant"
+ "dubbo.apache.org/dubbo-go/v3/protocol/dubbo"
+ "dubbo.apache.org/dubbo-go/v3/protocol/invocation"
+ "dubbo.apache.org/dubbo-go/v3/remoting"
+
+ hessian "github.com/apache/dubbo-go-hessian2"
+
+ "github.com/dubbogo/grpc-go/metadata"
+
+ "github.com/go-errors/errors"
+
+ perrors "github.com/pkg/errors"
+)
+
+import (
+ "github.com/apache/dubbo-go-pixiu/pkg/common/constant"
+ "github.com/apache/dubbo-go-pixiu/pkg/common/extension/filter"
+ router2 "github.com/apache/dubbo-go-pixiu/pkg/common/router"
+ dubbo2 "github.com/apache/dubbo-go-pixiu/pkg/context/dubbo"
+ "github.com/apache/dubbo-go-pixiu/pkg/logger"
+ "github.com/apache/dubbo-go-pixiu/pkg/model"
+)
+
+// HttpConnectionManager network filter for http
+type DubboProxyConnectionManager struct {
Review comment:
Fix
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]