代码拉取完成,页面将自动刷新
package main
import (
"gitee.com/micro-tools/micro/module"
"gitee.com/micro-tools/micro/module/base"
"gitee.com/micro-tools/wf/encoding/gjson"
"gitee.com/micro-tools/wf/frame/g"
"gitee.com/micro-tools/wf/os/glog"
"gitee.com/micro-tools/wf/os/gtime"
"gitee.com/micro-tools/wf/os/gtimer"
"time"
)
type Client struct {
base.Module
}
func New() module.Module {
this := new(Client)
return this
}
func (c *Client) GetType() string {
return "Blocking Query"
}
func (c *Client) OnInit(app module.App) {
c.Module.OnInit(c, app)
i := 0
gtimer.SetInterval(time.Second*2, func() {
bs, _ := gjson.Encode(g.Map{"value": i})
bs2, _ := gjson.Encode(g.Map{"value": gtime.Now()})
c.putValue("/corex/blocking", bs)
c.putValue("blocking", bs2)
i += 1
})
//go func() {
// type Config struct {
// Blocking string `json:"blocking,omitempty"`
// Nats string `json:"nats,omitempty"`
// }
// prefix := "/"
// c.GetApp().Registry().BlockingQuery(&Config{}, prefix, func(value interface{}) {
// var val Config
// _ = gconv.Struct(value, &val)
// glog.Info(val)
// })
//}()
}
func (c *Client) Run(closeSig chan bool) {
c.App.Logger().Infof("%s模块运行中...", c.GetType())
<-closeSig
c.App.Logger().Infof("%s模块已停止...", c.GetType())
}
func (c *Client) OnDestroy() {
c.Module.OnDestroy()
c.App.Logger().Infof("%s模块已回收...", c.GetType())
}
func (c *Client) putValue(key string, value interface{}) {
err := c.GetApp().Registry().Put(key, value)
if err != nil {
glog.Error(err)
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。