Skip to content

Commit

Permalink
Add config sample
Browse files Browse the repository at this point in the history
  • Loading branch information
andeya committed Mar 8, 2018
1 parent e06533c commit ec99b7a
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
32 changes: 32 additions & 0 deletions samples/config/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"github.com/henrylee2cn/cfgo"
tp "github.com/henrylee2cn/teleport"
)

func main() {
cfg := tp.PeerConfig{}

// auto create and sync config from config/config.yaml
cfgo.MustGet("config/config.yaml", true).MustReg("cfg_cli", &cfg)

cli := tp.NewPeer(cfg)
defer cli.Close()

sess, err := cli.Dial(":9090")
if err != nil {
tp.Fatalf("%v", err)
}

var reply int
rerr := sess.Pull("/math/add?push_status=yes",
[]int{1, 2, 3, 4, 5},
&reply,
).Rerror()

if rerr != nil {
tp.Fatalf("%v", rerr)
}
tp.Printf("reply: 1+2+3+4+5 = %d", reply)
}
23 changes: 23 additions & 0 deletions samples/config/config/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
cfg_cli:
count_time: false
default_body_codec: json
default_context_age: 0s
default_dial_timeout: 0s
default_session_age: 0s
listen_address: ""
network: tcp
print_body: false
redial_times: 0
slow_comet_duration: 0s

cfg_srv:
network: tcp
listen_address: :9090
default_dial_timeout: 0s
redial_times: 0
default_body_codec: json
default_session_age: 0s
default_context_age: 0s
slow_comet_duration: 0s
print_body: false
count_time: true
32 changes: 32 additions & 0 deletions samples/config/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"github.com/henrylee2cn/cfgo"
tp "github.com/henrylee2cn/teleport"
)

func main() {
cfg := tp.PeerConfig{
CountTime: true,
ListenAddress: ":9090",
}

// auto create and sync config from config/config.yaml
cfgo.MustGet("config/config.yaml", true).MustReg("cfg_srv", &cfg)

svr := tp.NewPeer(cfg)
svr.RoutePull(new(math))
svr.Listen()
}

type math struct {
tp.PullCtx
}

func (m *math) Add(args *[]int) (int, *tp.Rerror) {
var r int
for _, a := range *args {
r += a
}
return r, nil
}

0 comments on commit ec99b7a

Please sign in to comment.