Skip to content

fanxu/thrift_unix_domain

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

thrift_unix_domain

thrift golang unix domain socket

reference by https://github.com/apache/thrift/tree/master/lib/go

Using Thrift Unix Domain with Go

go get github.com/apache/thrift/lib/go/thrift

go get github.com/fanxu/thrift_unix_domain

Server:

func main() {

transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()

serverTransport, err := thrift_unix_domain.NewTServerUnixDomain("/tmp/thrift.sock")
if err != nil {
    fmt.Println("Error!", err)
    os.Exit(1)
}
handler := &Handler{} //your thrift struct
processor := thriftMsg.NewThriftMsgProcessor(handler) //your thrift function
server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
fmt.Println("thrift server in", "/tmp/thrift.sock")
server.Serve()

}

Client:

func main() {

transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
transport, err := thrift_unix_domain.NewTUnixDomain("/tmp/thrift.sock")
if err != nil {
    fmt.Fprintln(os.Stderr, "error resolving address:", err)
    os.Exit(1)
}
useTransport := transportFactory.GetTransport(transport)
client := thriftMsg.NewThriftMsgClientFactory(useTransport, protocolFactory) //you thrift function
if err := transport.Open(); err != nil {
    fmt.Fprintln(os.Stderr, "Error opening socket to /tmp/thrift.sock", " ", err)
    os.Exit(1)
}
defer transport.Close()

}

About

thrift golang unix domain socket

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%