| | |
| | | |
| | | return vo.StatusSuccess |
| | | } |
| | | |
| | | func UpdateSubscribe(url string, msg []byte) int { |
| | | rsp, err := util.HttpPut(url, headers, msg) |
| | | if err != nil { |
| | |
| | | |
| | | return vo.StatusSuccess |
| | | } |
| | | |
| | | func GetSubscribes(url string) ([]byte, error) { |
| | | rsp, err := util.HttpGet(url, headers) |
| | | if err != nil { |
| | | logger.Warn("Put subscribe failed, %s", err.Error()) |
| | | |
| | | } |
| | | |
| | | return rsp, err |
| | | } |
| | |
| | | |
| | | c.JSON(http.StatusOK, gin.H{"msg": "ok"}) |
| | | } |
| | | |
| | | func (s SubscribeController) List(c *gin.Context) { |
| | | if c.Param("id") == "" { |
| | | c.JSON(http.StatusBadRequest, gin.H{"msg": "下级id为空"}) |
| | | } |
| | | |
| | | list, err := s.Repository.ListByFromId(c.Param("id")) |
| | | if err != nil { |
| | | c.JSON(http.StatusInternalServerError, gin.H{"msg": err.Error()}) |
| | | return |
| | | } |
| | | |
| | | c.JSON(http.StatusOK, gin.H{"msg": "ok", "data": list}) |
| | | } |
| | | |
| | | func (s SubscribeController) RemoteList(c *gin.Context) { |
| | | if c.Param("id") == "" { |
| | | c.JSON(http.StatusBadRequest, gin.H{"msg": "下级id为空"}) |
| | | } |
| | | |
| | | data, err := s.Repository.RemoteList(c.Param("id")) |
| | | if err != nil { |
| | | c.JSON(http.StatusInternalServerError, gin.H{"msg": err.Error()}) |
| | | return |
| | | } |
| | | |
| | | c.JSON(http.StatusOK, gin.H{"msg": "ok", "data": data}) |
| | | } |
| | |
| | | return err |
| | | } |
| | | |
| | | func (s *SubscribeRepository) RemoteList(sid string) ([]byte, error) { |
| | | // 查找下级 |
| | | var platform models.SubPlatform |
| | | err := platform.FindById(sid) |
| | | if err != nil { |
| | | return nil, err |
| | | } |
| | | |
| | | uri := fmt.Sprintf("http://%s:%d/VIID/Subscribes", platform.RemoteIP, platform.RemotePort) |
| | | |
| | | return client.GetSubscribes(uri) |
| | | } |
| | | |
| | | func (s *SubscribeRepository) SaveReceiveSubscribe(fromId string, subscribe *vo.Subscribe) error { |
| | | var sub = models.Subscribe{ |
| | | Id: subscribe.SubscribeID, |
| | |
| | | { |
| | | router.POST("/:id", subCtl.CreateSubscribes) |
| | | router.PUT("/:id", subCtl.UpdateSubscribes) |
| | | router.PUT("/cancel/:id", subCtl.UpdateSubscribes) |
| | | router.PUT("/cancel/:id", subCtl.CancelSubscribes) |
| | | router.GET("/list/:id", subCtl.List) |
| | | router.GET("/remote_list/:id", subCtl.RemoteList) |
| | | //router.GET("/:id", subCtl.Faces) |
| | | //router.DELETE("/:id", subCtl.Faces) |
| | | } |
| | |
| | | return body, nil |
| | | } |
| | | |
| | | func HttpGet(url string) error { |
| | | _, err := http.Get(url) |
| | | func HttpGet(url string, header map[string]string) ([]byte, error) { |
| | | req, err := http.NewRequest(http.MethodGet, url, nil) |
| | | if err != nil { |
| | | return err |
| | | return nil, err |
| | | } |
| | | |
| | | return nil |
| | | //req.Header.Set("Content-Type", "applicaiton/json; charset=UTF-8") |
| | | if header != nil { |
| | | for k, v := range header { |
| | | req.Header.Set(k, v) |
| | | } |
| | | } |
| | | cli := &http.Client{} |
| | | resp, err := cli.Do(req) |
| | | if err != nil { |
| | | return nil, err |
| | | } |
| | | |
| | | defer resp.Body.Close() |
| | | body, err := io.ReadAll(resp.Body) |
| | | if err != nil { |
| | | return nil, err |
| | | } |
| | | |
| | | return body, nil |
| | | } |