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
58
59
60
61
62
63
64
|
package service
import (
"context"
"fmt"
"lyrJudger/thrift/gen-go/CodeRunService"
"testing"
// "git.apache.org/thrift.git/lib/go/thrift"
"log"
"net"
"github.com/apache/thrift/lib/go/thrift"
)
const (
HOST = "localhost"
PORT = "6860"
)
func Test_runservice(t *testing.T) {
handler := NewJudgeService()
processor := CodeRunService.NewJudgerServiceProcessor(handler)
serverTransport, err := thrift.NewTServerSocket(HOST + ":" + PORT)
if err != nil {
fmt.Println("Error:", err)
}
transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
fmt.Println("Running at:", HOST+":"+PORT)
server.Serve()
fmt.Println("结果是---")
}
func Test_run_client(t *testing.T) {
// const (
// HOST = "localhost"
// PORT = "8080"
// )
tSocket, err := thrift.NewTSocket(net.JoinHostPort(HOST, PORT))
if err != nil {
log.Fatalln("tSocket error:", err)
}
transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
transport, _ := transportFactory.GetTransport(tSocket)
protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
client := CodeRunService.NewJudgerServiceClientFactory(transport, protocolFactory)
if err := transport.Open(); err != nil {
fmt.Println("Error opening:", HOST+":"+PORT)
}
defer transport.Close()
// data := example.Data{Text: "hello,world!"}
var ctx = context.Background()
d, err := client.DoRun(ctx, CodeRunService.NewCodeRun())
fmt.Println(" 得到结果 result === -> ", d, err)
}
|