.
This commit is contained in:
@@ -29,7 +29,8 @@ FROM alpine:latest
|
|||||||
WORKDIR /opt/zhub
|
WORKDIR /opt/zhub
|
||||||
|
|
||||||
# 从构建阶段复制可执行文件到当前阶段
|
# 从构建阶段复制可执行文件到当前阶段
|
||||||
COPY --from=builder /opt/zhub .
|
COPY --from=builder /opt/zhub/zhub.sh .
|
||||||
|
COPY --from=builder /opt/zhub/app.ini .
|
||||||
|
|
||||||
# 复制 app.ini 配置文件到容器中
|
# 复制 app.ini 配置文件到容器中
|
||||||
COPY app.ini .
|
COPY app.ini .
|
||||||
|
|||||||
@@ -38,6 +38,9 @@ func ReadConfig() Config {
|
|||||||
viper.SetDefault("log.handlers", "console")
|
viper.SetDefault("log.handlers", "console")
|
||||||
viper.SetDefault("log.level", "info")
|
viper.SetDefault("log.level", "info")
|
||||||
viper.SetDefault("service.auth", true)
|
viper.SetDefault("service.auth", true)
|
||||||
|
defer func() {
|
||||||
|
os.MkdirAll(conf.Data.Dir, os.ModeDir)
|
||||||
|
}()
|
||||||
|
|
||||||
/*// 读取指定的配置文件
|
/*// 读取指定的配置文件
|
||||||
if !strings.EqualFold("", fileName) {
|
if !strings.EqualFold("", fileName) {
|
||||||
|
|||||||
@@ -39,55 +39,15 @@ func StartWatch() {
|
|||||||
zsub.Hub.Publish(topic, value)
|
zsub.Hub.Publish(topic, value)
|
||||||
c.JSON(http.StatusOK, "+OK")
|
c.JSON(http.StatusOK, "+OK")
|
||||||
})
|
})
|
||||||
|
r.GET("/topic/delay", func(c *gin.Context) {
|
||||||
|
topic := c.Query("topic")
|
||||||
|
value := c.Query("value")
|
||||||
|
delay := c.Query("delay")
|
||||||
|
|
||||||
|
zsub.Hub.Delay([]string{"delay", topic, value, delay})
|
||||||
|
c.JSON(http.StatusOK, "+OK")
|
||||||
|
})
|
||||||
|
|
||||||
watchAddr := zsub.Conf.Service.Watch
|
watchAddr := zsub.Conf.Service.Watch
|
||||||
r.Run(watchAddr)
|
r.Run(watchAddr)
|
||||||
|
|
||||||
/*dir, _ := os.Getwd()
|
|
||||||
webDir := path.Join(dir, "/public")
|
|
||||||
|
|
||||||
http.Handle("/", http.FileServer(http.Dir(webDir)))
|
|
||||||
http.HandleFunc("/info", info)
|
|
||||||
http.HandleFunc("/cleanup", cleanup)
|
|
||||||
http.HandleFunc("/retimer", retimer)
|
|
||||||
http.HandleFunc("/topic/publish", publish)
|
|
||||||
|
|
||||||
watchAddr := zsub.Conf.Service.Watch
|
|
||||||
log.Println("zhub.watch = ", watchAddr)
|
|
||||||
http.ListenAndServe(watchAddr, nil)*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*func publish(w http.ResponseWriter, r *http.Request) {
|
|
||||||
topic := r.FormValue("topic")
|
|
||||||
value := r.FormValue("value")
|
|
||||||
zsub.Hub.Publish(topic, value)
|
|
||||||
renderJson(w, "+ok")
|
|
||||||
}
|
|
||||||
|
|
||||||
// retimer 重载定时调度
|
|
||||||
func retimer(w http.ResponseWriter, _ *http.Request) {
|
|
||||||
zsub.Hub.ReloadTimer()
|
|
||||||
renderJson(w, "+reload timer ok")
|
|
||||||
}
|
|
||||||
|
|
||||||
func cleanup(w http.ResponseWriter, _ *http.Request) {
|
|
||||||
zsub.Hub.Clearup()
|
|
||||||
renderJson(w, "+OK")
|
|
||||||
}
|
|
||||||
|
|
||||||
func info(w http.ResponseWriter, _ *http.Request) {
|
|
||||||
info := zsub.Info()
|
|
||||||
renderJson(w, info)
|
|
||||||
}
|
|
||||||
|
|
||||||
func renderJson(w http.ResponseWriter, d interface{}) {
|
|
||||||
var bytes []byte
|
|
||||||
|
|
||||||
if str, ok := d.(string); ok {
|
|
||||||
bytes = []byte(str)
|
|
||||||
} else {
|
|
||||||
bytes, _ = json.Marshal(d)
|
|
||||||
w.Header().Set("content-type", "application/json; charset=utf-8;")
|
|
||||||
}
|
|
||||||
w.Write(bytes)
|
|
||||||
}*/
|
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ func handleMessage(v Message) {
|
|||||||
case "broadcast":
|
case "broadcast":
|
||||||
Hub.broadcast(rcmd[1], rcmd[2])
|
Hub.broadcast(rcmd[1], rcmd[2])
|
||||||
case "delay":
|
case "delay":
|
||||||
Hub.delay(rcmd, c)
|
Hub.Delay(rcmd)
|
||||||
case "timer":
|
case "timer":
|
||||||
for _, name := range rcmd[1:] {
|
for _, name := range rcmd[1:] {
|
||||||
Hub.timer([]string{"timer", name}, c) // append to timers
|
Hub.timer([]string{"timer", name}, c) // append to timers
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ func (s *ZSub) loadDelay() {
|
|||||||
if exectime < time.Now().Unix() {
|
if exectime < time.Now().Unix() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
s.delay([]string{"delay", split[0], split[1], strconv.FormatInt((exectime-time.Now().Unix())*1000, 10)}, nil)
|
s.Delay([]string{"delay", split[0], split[1], strconv.FormatInt((exectime-time.Now().Unix())*1000, 10)})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ type ZDelay struct {
|
|||||||
Timer *time.Timer
|
Timer *time.Timer
|
||||||
}
|
}
|
||||||
|
|
||||||
// delay topic value 100 -> publish topic value
|
// Delay : delay topic value 100 -> publish topic value
|
||||||
func (s *ZSub) delay(rcmd []string, c *ZConn) {
|
func (s *ZSub) Delay(rcmd []string) {
|
||||||
s.Lock()
|
s.Lock()
|
||||||
defer func() {
|
defer func() {
|
||||||
s.Unlock()
|
s.Unlock()
|
||||||
@@ -37,13 +37,13 @@ func (s *ZSub) delay(rcmd []string, c *ZConn) {
|
|||||||
s.delayup = true
|
s.delayup = true
|
||||||
}()
|
}()
|
||||||
if len(rcmd) != 4 {
|
if len(rcmd) != 4 {
|
||||||
c.send("-Error: subscribe para number!")
|
// c.send("-Error: subscribe para number!")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
t, err := strconv.ParseInt(rcmd[3], 10, 64)
|
t, err := strconv.ParseInt(rcmd[3], 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.send("-Error: " + strings.Join(rcmd, " "))
|
// c.send("-Error: " + strings.Join(rcmd, " "))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user