init commit

This commit is contained in:
flswld committed 2022-11-20 15:38:00 +08:00
1 parent eda2b643b9
commit 3efed3defe
5834 files changed
+636508

No files matched your search

+85
View File
@@ -0,0 +1,85 @@
package controller
import (
"github.com/gin-gonic/gin"
"net/http"
"time"
)
func (c *Controller) pollHttpService(context *gin.Context) {
serviceName := context.Query("name")
recvrNtfr := c.service.RegistryHttpNotifyReceiver(serviceName)
timeout := time.NewTicker(time.Second * 30)
select {
case inst := <-recvrNtfr.NotifyChannel:
c.service.CancelHttpNotifyReceiver(serviceName, recvrNtfr.Id)
context.JSON(http.StatusOK, gin.H{
"code": 0,
"instance": inst,
})
case <-timeout.C:
c.service.CancelHttpNotifyReceiver(serviceName, recvrNtfr.Id)
context.JSON(http.StatusOK, gin.H{
"code": 0,
"instance": nil,
})
}
}
func (c *Controller) pollAllHttpService(context *gin.Context) {
recvrNtfr := c.service.RegistryAllHttpNotifyReceiver()
timeout := time.NewTicker(time.Second * 30)
select {
case svc := <-recvrNtfr.NotifyChannel:
c.service.CancelAllHttpNotifyReceiver(recvrNtfr.Id)
context.JSON(http.StatusOK, gin.H{
"code": 0,
"service": svc,
})
case <-timeout.C:
c.service.CancelAllHttpNotifyReceiver(recvrNtfr.Id)
context.JSON(http.StatusOK, gin.H{
"code": 0,
"service": nil,
})
}
}
func (c *Controller) pollRpcService(context *gin.Context) {
serviceName := context.Query("name")
recvrNtfr := c.service.RegistryRpcNotifyReceiver(serviceName)
timeout := time.NewTicker(time.Second * 30)
select {
case inst := <-recvrNtfr.NotifyChannel:
c.service.CancelRpcNotifyReceiver(serviceName, recvrNtfr.Id)
context.JSON(http.StatusOK, gin.H{
"code": 0,
"instance": inst,
})
case <-timeout.C:
c.service.CancelRpcNotifyReceiver(serviceName, recvrNtfr.Id)
context.JSON(http.StatusOK, gin.H{
"code": 0,
"instance": nil,
})
}
}
func (c *Controller) pollAllRpcService(context *gin.Context) {
recvrNtfr := c.service.RegistryAllRpcNotifyReceiver()
timeout := time.NewTicker(time.Second * 30)
select {
case svc := <-recvrNtfr.NotifyChannel:
c.service.CancelAllRpcNotifyReceiver(recvrNtfr.Id)
context.JSON(http.StatusOK, gin.H{
"code": 0,
"service": svc,
})
case <-timeout.C:
c.service.CancelAllRpcNotifyReceiver(recvrNtfr.Id)
context.JSON(http.StatusOK, gin.H{
"code": 0,
"service": nil,
})
}
}