本文整理匯總了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
}