forked from samuel/go-thrift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
40 lines (33 loc) · 887 Bytes
/
main.go
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
package main
import (
"fmt"
"net"
"net/rpc"
"github.com/samuel/go-thrift/examples/scribe"
"github.com/samuel/go-thrift/thrift"
)
// implementation
type scribeServiceImplementation int
func (s *scribeServiceImplementation) Log(messages []*scribe.LogEntry) (scribe.ResultCode, error) {
for _, m := range messages {
fmt.Printf("MSG: %+v\n", m)
}
return scribe.ResultCodeOk, nil
}
func main() {
scribeService := new(scribeServiceImplementation)
rpc.RegisterName("Thrift", &scribe.ScribeServer{Implementation: scribeService})
ln, err := net.Listen("tcp", ":1463")
if err != nil {
panic(err)
}
for {
conn, err := ln.Accept()
if err != nil {
fmt.Printf("ERROR: %+v\n", err)
continue
}
fmt.Printf("New connection %+v\n", conn)
go rpc.ServeCodec(thrift.NewServerCodec(thrift.NewFramedReadWriteCloser(conn, 0), thrift.NewBinaryProtocol(true, false)))
}
}