github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/tests/http_proxies/run-proxy.go (about) 1 // Copyright 2021 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package main 15 16 import ( 17 "flag" 18 "fmt" 19 20 "github.com/pingcap/log" 21 "go.uber.org/zap" 22 23 grpc_proxy "github.com/bradleyjkemp/grpc-tools/grpc-proxy" 24 "google.golang.org/grpc" 25 ) 26 27 func main() { 28 grpc_proxy.RegisterDefaultFlags() 29 flag.Parse() 30 proxy, err := grpc_proxy.New( 31 grpc_proxy.WithInterceptor(intercept), 32 grpc_proxy.DefaultFlags(), 33 ) 34 if err != nil { 35 log.Fatal("failed to create proxy", zap.Error(err)) 36 } 37 err = proxy.Start() 38 if err != nil { 39 log.Fatal("failed to start proxy", zap.Error(err)) 40 } 41 } 42 43 func intercept(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error { 44 fmt.Println(info.FullMethod) 45 return handler(srv, ss) 46 }