1 Star 0 Fork 0

micro-tools/micro

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
client.go 1.50 KB
一键复制 编辑 原始数据 按行查看 历史
545403892 提交于 2023-06-05 23:58 +08:00 . init
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)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/micro-tools/micro.git
git@gitee.com:micro-tools/micro.git
micro-tools
micro
micro
v1.0.2

搜索帮助