AlexStocks commented on a change in pull request #315:
URL: https://github.com/apache/dubbo-go-pixiu/pull/315#discussion_r775859664



##########
File path: pkg/listener/http2/http2_listener.go
##########
@@ -0,0 +1,119 @@
+/*
+ * 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 http2
+
+import (
+       "net"
+       "net/http"
+       "strconv"
+)
+
+import (
+       "golang.org/x/net/http2"
+       "golang.org/x/net/http2/h2c"
+)
+
+import (
+       "github.com/apache/dubbo-go-pixiu/pkg/filterchain"
+       "github.com/apache/dubbo-go-pixiu/pkg/listener"
+       "github.com/apache/dubbo-go-pixiu/pkg/logger"
+       "github.com/apache/dubbo-go-pixiu/pkg/model"
+)
+
+func init() {
+       listener.SetListenerServiceFactory(model.ProtocolTypeHTTP2, 
newHttp2ListenerService)
+}
+
+type (
+       // ListenerService the facade of a listener
+       Http2ListenerService struct {
+               listener.BaseListenerService
+               listener net.Listener
+               server   *http.Server
+       }
+)
+
+type handleWrapper struct {
+       fc *filterchain.FilterChain
+}
+
+type h2cWrapper struct {
+       w *handleWrapper
+       h http.Handler
+}
+
+func (h *h2cWrapper) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+       h.h.ServeHTTP(w, r)
+}
+
+// 转发 grpc 的请求
+func (h *handleWrapper) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+       h.fc.ServeHTTP(w, r)
+}
+
+func newHttp2ListenerService(lc *model.Listener, bs *model.Bootstrap) 
(listener.ListenerService, error) {
+       fc := filterchain.CreateFilterChain(lc.FilterChain, bs)
+       return &Http2ListenerService{
+               BaseListenerService: listener.BaseListenerService{
+                       Config:      lc,
+                       FilterChain: fc,
+               },
+               listener: nil,
+               server:   nil,
+       }, nil
+}
+
+func (ls Http2ListenerService) Start() error {

Review comment:
       Add comment or ’nolint‘ for this func, pls.

##########
File path: pkg/listener/http2/http2_listener.go
##########
@@ -0,0 +1,119 @@
+/*
+ * 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 http2
+
+import (
+       "net"
+       "net/http"
+       "strconv"
+)
+
+import (
+       "golang.org/x/net/http2"
+       "golang.org/x/net/http2/h2c"
+)
+
+import (
+       "github.com/apache/dubbo-go-pixiu/pkg/filterchain"
+       "github.com/apache/dubbo-go-pixiu/pkg/listener"
+       "github.com/apache/dubbo-go-pixiu/pkg/logger"
+       "github.com/apache/dubbo-go-pixiu/pkg/model"
+)
+
+func init() {
+       listener.SetListenerServiceFactory(model.ProtocolTypeHTTP2, 
newHttp2ListenerService)
+}
+
+type (
+       // ListenerService the facade of a listener
+       Http2ListenerService struct {
+               listener.BaseListenerService
+               listener net.Listener
+               server   *http.Server
+       }
+)
+
+type handleWrapper struct {
+       fc *filterchain.FilterChain
+}
+
+type h2cWrapper struct {
+       w *handleWrapper
+       h http.Handler
+}
+
+func (h *h2cWrapper) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+       h.h.ServeHTTP(w, r)
+}
+
+// 转发 grpc 的请求

Review comment:
       Chinese comment?

##########
File path: pkg/listener/http2/http2_listener.go
##########
@@ -0,0 +1,119 @@
+/*
+ * 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 http2
+
+import (
+       "net"
+       "net/http"
+       "strconv"
+)
+
+import (
+       "golang.org/x/net/http2"
+       "golang.org/x/net/http2/h2c"
+)
+
+import (
+       "github.com/apache/dubbo-go-pixiu/pkg/filterchain"
+       "github.com/apache/dubbo-go-pixiu/pkg/listener"
+       "github.com/apache/dubbo-go-pixiu/pkg/logger"
+       "github.com/apache/dubbo-go-pixiu/pkg/model"
+)
+
+func init() {
+       listener.SetListenerServiceFactory(model.ProtocolTypeHTTP2, 
newHttp2ListenerService)
+}
+
+type (
+       // ListenerService the facade of a listener
+       Http2ListenerService struct {
+               listener.BaseListenerService
+               listener net.Listener
+               server   *http.Server
+       }
+)
+
+type handleWrapper struct {
+       fc *filterchain.FilterChain
+}
+
+type h2cWrapper struct {
+       w *handleWrapper
+       h http.Handler
+}
+
+func (h *h2cWrapper) ServeHTTP(w http.ResponseWriter, r *http.Request) {

Review comment:
       Add comment for this func, pls.

##########
File path: samples/dubbogo/multi/config/conf.yaml
##########
@@ -20,16 +20,12 @@
 static_resources:
   listeners:
     - name: "net/http"
+      protocol_type: "HTTP"
       address:
         socket_address:
-          protocol_type: "HTTP"
           address: "0.0.0.0"
           port: 8882
       filter_chains:
-        - filter_chain_match:
-          domains:
-            - api.dubbo.com
-            - api.pixiu.com
           filters:
             - name: dgp.filter.httpconnectionmanager

Review comment:
       as above, using its abbrevlation instead.

##########
File path: samples/grpc/server/app/server.go
##########
@@ -0,0 +1,85 @@
+/*
+ * 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 main
+
+import (
+       "context"
+       "net"
+)
+
+import (
+       "google.golang.org/grpc"
+)
+
+import (
+       "github.com/apache/dubbo-go-pixiu/pkg/logger"
+       "github.com/apache/dubbo-go-pixiu/samples/http/grpc/proto"
+)
+
+const (
+       MsgUserNotFound          = "user not found"
+       MsgUserQuerySuccessfully = "user(s) query successfully"
+)
+
+// Test Cases
+// curl http://127.0.0.1:8881/api/v1/provider.UserProvider/GetUser
+// curl http://127.0.0.1:8881/api/v1/provider.UserProvider/GetUser -X POST -d 
'{"userId":1}'
+
+type server struct {
+       users map[int32]*proto.User
+       proto.UnimplementedUserProviderServer
+}
+
+func (s *server) GetUser(ctx context.Context, request *proto.GetUserRequest) 
(*proto.GetUserResponse, error) {
+       us := make([]*proto.User, 0)
+       if request.GetUserId() == 0 {
+               for i := 1; i <= 2; i++ {
+                       us = append(us, s.users[int32(i)])
+               }
+       } else {
+               u, ok := s.users[request.GetUserId()]
+               if !ok {
+                       return &proto.GetUserResponse{Message: 
MsgUserNotFound}, nil
+               }
+               us = append(us, u)
+       }
+       return &proto.GetUserResponse{Message: MsgUserQuerySuccessfully, Users: 
us}, nil
+}
+
+func main() {

Review comment:
       as usual, the main func is always placed at the bottom.

##########
File path: pkg/server/listener_manager.go
##########
@@ -18,19 +18,24 @@
 package server
 
 import (
+       "github.com/apache/dubbo-go-pixiu/pkg/listener"
+       "github.com/apache/dubbo-go-pixiu/pkg/logger"
        "github.com/apache/dubbo-go-pixiu/pkg/model"
 )
 
 type ListenerManager struct {
        activeListener        []*model.Listener
-       activeListenerService []*ListenerService
+       activeListenerService []listener.ListenerService
 }
 
 func CreateDefaultListenerManager(bs *model.Bootstrap) *ListenerManager {

Review comment:
       Add comment or ’nolint‘ for this func, pls.




-- 
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]

Reply via email to