本文整理汇总了Golang中github.com/kandoo/beehive.RcvContext.Printf方法的典型用法代码示例。如果您正苦于以下问题:Golang RcvContext.Printf方法的具体用法?Golang RcvContext.Printf怎么用?Golang RcvContext.Printf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/kandoo/beehive.RcvContext
的用法示例。
在下文中一共展示了RcvContext.Printf方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Rcvf
// Rcvf receives the message and the context.
func Rcvf(msg beehive.Msg, ctx beehive.RcvContext) error {
// msg is an envelope around the Hello message.
// You can retrieve the Hello, using msg.Data() and then
// you need to assert that its a Hello.
hello := msg.Data().(Hello)
// Using ctx.Dict you can get (or create) a dictionary.
dict := ctx.Dict("hello_dict")
// Using Get(), you can get the value associated with
// a key in the dictionary. Keys are always string
// and values are generic interface{}'s.
v, err := dict.Get(hello.Name)
// If there is an error, the entry is not in the
// dictionary. Otherwise, we set cnt based on
// the value we already have in the dictionary
// for that name.
cnt := 0
if err == nil {
cnt = v.(int)
}
// Now we increment the count.
cnt++
// And then we print the hello message.
ctx.Printf("hello %s (%d)!\n", hello.Name, cnt)
// Finally we update the count stored in the dictionary.
return dict.Put(hello.Name, cnt)
}
示例2: rcvf
func rcvf(msg bh.Msg, ctx bh.RcvContext) error {
name := msg.Data().(string)
cnt := 0
if v, err := ctx.Dict(helloDict).Get(name); err == nil {
cnt = v.(int)
}
cnt++
ctx.Printf("hello %s (%d)!\n", name, cnt)
ctx.Dict(helloDict).Put(name, cnt)
return nil
}
示例3: hostJoinedRcvf
func hostJoinedRcvf(msg bh.Msg, ctx bh.RcvContext) error {
ctx.Printf("Rcv of HostJoinedHandler Called")
ctx.Printf("%v", msg.Data().(nom.HostJoined))
return nil
}