-
Notifications
You must be signed in to change notification settings - Fork 136
/
server2.go
52 lines (42 loc) · 1.04 KB
/
server2.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
package main
import (
"context"
"flag"
"log"
"time"
metrics "github.com/rcrowley/go-metrics"
example "github.com/rpcxio/rpcx-examples"
"github.com/smallnest/rpcx/server"
"github.com/smallnest/rpcx/serverplugin"
)
var (
addr = flag.String("addr", "localhost:8973", "server address")
etcdAddr = flag.String("etcdAddr", "localhost:2379", "etcd address")
basePath = flag.String("base", "/rpcx_test", "prefix path")
)
type Arith2 int
func (t *Arith2) Mul(ctx context.Context, args *example.Args, reply *example.Reply) error {
reply.C = args.A * args.B * 100
return nil
}
func main() {
flag.Parse()
s := server.NewServer()
addRegistryPlugin(s)
s.RegisterName("Arith", new(Arith2), "")
s.Serve("tcp", *addr)
}
func addRegistryPlugin(s *server.Server) {
r := &serverplugin.EtcdRegisterPlugin{
ServiceAddress: "tcp@" + *addr,
EtcdServers: []string{*etcdAddr},
BasePath: *basePath,
Metrics: metrics.NewRegistry(),
UpdateInterval: time.Minute,
}
err := r.Start()
if err != nil {
log.Fatal(err)
}
s.Plugins.Add(r)
}