package httpcall import ( "context" "encoding/json" "errors" "finclip-app-manager/infrastructure/config" "finclip-app-manager/infrastructure/utility" "net/http" ) type PubNotifyRuleEngineReq struct { AppId string `json:"appId"` Version int `json:"version"` PubStatus string `json:"pubStatus"` IsDev bool `json:"isDev"` Exp map[string]interface{} `json:"exp"` } func (c *Client) PubNotifyRuleEngine(ctx context.Context, appId string, version int, accountId string, isDev bool) error { url := config.GetConfig().RuleEngineHost + config.GetConfig().PubNotifyRuleEngineURL req := PubNotifyRuleEngineReq{ AppId: appId, Version: version, IsDev: isDev, } h := c.getNewDefaultReqHeader() h["X-Consumer-Custom-ID"] = accountId log.Errorf("PubNotifyRuleEngine req:%+v,header:%+v", req, h) rsp, err := c.Request(ctx).SetHeaders(h).SetBody(req).Patch(url) if err != nil { log.Errorf("PubNotifyRuleEngine fetch err:%s", err.Error()) return err } if rsp.StatusCode() != http.StatusOK { log.Errorf("PubNotifyRuleEngine StatusCode err,body:%s", rsp.Body()) return errors.New(ErrHttpCode) } log.Errorf("PubNotifyRuleEngine StatusCode err,body:%s", rsp.Body()) resp := make(map[string]interface{}) if err = json.Unmarshal(rsp.Body(), &resp); err != nil { log.Errorf("PubNotifyRuleEngine Failed to unmarshal response to GetGroupIDResponse: %v\n", err) return err } return nil } type GetAuthByUserIdAndGroupsReq struct { UserId string `json:"userId"` Groups []string `json:"groups"` Type string `json:"type"` } type GetAuthByUserIdAndGroupsRspData struct { AuthList map[string]GetAuthByUserIdAndGroupsRspDataItem `json:"authList"` HasAuth bool `json:"hasAuth"` } type GetAuthByUserIdAndGroupsRspDataItem struct { Dev bool `json:"dev"` Trial bool `json:"trial"` } type GetAuthByUserIdAndGroupsRsp struct { Data GetAuthByUserIdAndGroupsRspData `json:"data"` Errcode string `json:"errcode"` Error string `json:"error"` } func (c *Client) GetAuthByUserIdAndGroups(ctx context.Context, t, userId string, groups []string) (*GetAuthByUserIdAndGroupsRspData, error) { url := config.GetConfig().RuleEngineHost + config.GetConfig().GetUserAuthURL req := GetAuthByUserIdAndGroupsReq{ UserId: userId, Groups: groups, Type: t, } h := c.getNewDefaultReqHeader() rsp, err := c.Request(ctx).SetHeaders(h).SetBody(req).Post(url) if err != nil { log.Errorf("GetAuthByUserIdAndGroups request err:%s", err.Error()) return nil, err } if rsp.StatusCode() != http.StatusOK { log.Errorf("GetAuthByUserIdAndGroups code err,code:%v", rsp.StatusCode()) return nil, errors.New("http code err") } result := GetAuthByUserIdAndGroupsRsp{} if err := json.Unmarshal(rsp.Body(), &result); err != nil { log.Errorf("GetAuthByUserIdAndGroups bind err:%s", err.Error()) return nil, err } if result.Errcode != utility.OK { log.Errorf("GetAuthByUserIdAndGroups errcode err,rsp:%v", result) return nil, errors.New("errcode err") } return &result.Data, nil }