1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| package main
import ( "aTrustRpcClient/gen-go/sdptrusttunnelservice" "encoding/json" "fmt" "net/http" "time"
"context"
"github.com/apache/thrift/lib/go/thrift" )
var defaultCtx = context.Background()
func tunnelRpcHandler(reqJson string, w http.ResponseWriter, r *http.Request) { startTime := currentTimeMillis()
cfg := &thrift.TConfiguration{} var transport thrift.TTransport transport = thrift.NewTSocketConf("localhost:"+fmt.Sprint(tunnelRpcPort), cfg) transport = thrift.NewTBufferedTransport(transport, 10240) iprot := thrift.NewTBinaryProtocolConf(transport, cfg) oprot := thrift.NewTMultiplexedProtocol(iprot, "SdpTrustTunnelService")
if err := transport.Open(); err != nil { http.Error(w, err.Error(), 500) return } defer transport.Close()
client := sdptrusttunnelservice.NewSdpTrustTunnelServiceClientProtocol(transport, iprot, oprot) res, err := client.GetModuleStatus(defaultCtx, rpcReqData.ModuleName) if err != nil { http.Error(w, err.Error(), 500) return }
endTime := currentTimeMillis() fmt.Println("Program exit. time->", endTime, startTime, (endTime - startTime)) w.Header().Set("Content-Type", "application/json") fmt.Fprintf(w, "%s", res) }
func currentTimeMillis() int64 { return time.Now().UnixNano() / 1000000 }
|