如何在Go,Thrift版本0.10.0中从Thrift服务器获取客户端IP?

如何在Go,Thrift版本0.10.0中从Thrift服务器获取客户端IP?,go,thrift,Go,Thrift,我正在Golang编写一个thrift服务,我想了解如何在handler函数实现中获取客户机的IP地址 我已经在Java中尝试过了,可以通过覆盖TProcessor#process(in,out)来获得,但这种方式在Golang中似乎不起作用 serverTransport, err := thrift.NewTServerSocket(net.JoinHostPort(ip, strconv.FormatInt(port, 10))) //serverTransport, err :=

我正在Golang编写一个thrift服务,我想了解如何在handler函数实现中获取客户机的IP地址

我已经在Java中尝试过了,可以通过覆盖TProcessor#process(in,out)来获得,但这种方式在Golang中似乎不起作用

serverTransport, err := thrift.NewTServerSocket(net.JoinHostPort(ip, strconv.FormatInt(port, 10)))
    //serverTransport, err := thrift.NewTServerSocket(net.JoinHostPort("127.0.0.1", "9999"))
    if err != nil {
        log.Error(err.Error())
        os.Exit(1)
    }
    protocolFactory := thrift.NewTCompactProtocolFactory()
    transportFactory := thrift.NewTFramedTransportFactoryMaxLength(thrift.NewTTransportFactory(), 524288000) 

    processor := iface.NewNMPDataServiceProcessor(new(impl.NMPDataService))

    server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
    server.Serve()

    defer server.Stop()
NMPDataService接口的处理程序实现:

package impl

import (
    "NMPService/Framework/logger"
    "NMPService/NmpService/thrift/iface"
    "NMPService/NmpService/utils"
    "syscall"
    "errors"
    "fmt"
    "io"
    "io/ioutil"
    "os"
    "path/filepath"
    "regexp"
    "strconv"
    "strings"
    "time"

    "github.com/yeka/zip"
)

var log = logger.GetBeeLogger()

// NMPDataService .
type NMPDataService struct {
}

const (
    // MaxDownloadFileLimit ...
    MaxDownloadFileLimit int64 = 15728640
    TempFolder string = "tmp"
)

// ExistsFolder method
// Parameters:
//  - Path
func (handler *NMPDataService) ExistsFolder(path string) (bool, error) {
    log.Info("Check exist folder, path: %s", path)
    if strings.Contains(path, "\\") {
        path = strings.ReplaceAll(path, "\\", "/")
    }
    fileInfo, err := os.Stat(path)
    if os.IsNotExist(err) {
        log.Error("folder %s not exist", path)
        return false, nil
    }

    if !fileInfo.IsDir() {
        msg := "the path is not folder."
        log.Error(msg)
        return false, NewRPCException(1, msg, errors.New(msg))
    }

    if err != nil {
        log.Error("Check exist folder error.")
        return false, NewRPCException(1, "Check exist folder error", err)
    }

    return true, nil
}


上面是我在服务器端的代码。我想从服务器获取客户端IP信息。

处理程序在哪里?在上面添加了一些处理程序代码。处理程序只是接口的实现。我想我在这里无能为力。通常我希望处理程序中的某种连接能够从中获取IP。但我没有使用过thrift,它的工作方式似乎有所不同。顺便说一句,thrift 0.10.0可能与thrift 0.10.0的版本不同。