-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
56 lines (50 loc) · 1.05 KB
/
client.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"fmt"
"github.com/urfave/cli"
"os"
"net"
"net/rpc/jsonrpc"
)
// Func: Remote Procedure Call
func call(method string, task string) {
conn, err := net.DialTimeout("tcp", "127.0.0.1:3333", 1000*1000*1000*30)
if err != nil {
fmt.Printf("create client err:%s\n", err)
return
}
defer conn.Close()
client := jsonrpc.NewClient(conn)
var reply bool
err = client.Call(method, task, &reply)
fmt.Printf("reply: %s, err: %s\n", reply, err)
}
func main() {
app := cli.NewApp()
app.Name = "TaskAgent"
app.Usage = "To Add or Del Task in Server"
app.Version = "0.0.1"
app.Commands = []cli.Command{
{
Name:"add",
Aliases: []string{"add"},
Usage: "Add Task",
Action: func(c *cli.Context) error {
taskName := c.Args().First()
call("TaskUnit.Add", taskName)
return nil
},
},
{
Name:"del",
Aliases: []string{"del"},
Usage: "Delete Task",
Action: func(c *cli.Context) error {
taskName := c.Args().First()
call("TaskUnit.Delete", taskName)
return nil
},
},
}
app.Run(os.Args)
}