main.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package tag
  2. import (
  3. "fmt"
  4. "github.com/guonaihong/gout"
  5. "gogs.uu.mdfitnesscao.com/Algor/sdk"
  6. "gogs.uu.mdfitnesscao.com/Algor/sdk/response"
  7. )
  8. // 获取标签分类信息
  9. func DetailTagCategory(id string) (*sdk.BaseResponse[sdk.DetailResponse[*sdk.TagCategory]], *response.ErrCode) {
  10. var resp *sdk.BaseResponse[sdk.DetailResponse[*sdk.TagCategory]]
  11. resp, err := postReq[*sdk.BaseResponse[sdk.DetailResponse[*sdk.TagCategory]]]("/tagService/openapi/tagCategory/detail", gout.H{
  12. "id": id,
  13. })
  14. if err != nil {
  15. return nil, &response.ErrCode{
  16. Code: response.PLATFORM_ERROR,
  17. Msg: err.Error(),
  18. }
  19. }
  20. if resp == nil {
  21. return nil, response.ErrPlatform
  22. }
  23. if resp.Code != 200 {
  24. return nil, &response.ErrCode{
  25. Code: resp.Code,
  26. Msg: resp.Message,
  27. }
  28. }
  29. return resp, nil
  30. }
  31. // 获取标签分类信息
  32. func SetArchivesTag(tagId string, archivesId string, remarks string, operatorName string) (*sdk.BaseResponse[map[string]any], *response.ErrCode) {
  33. var resp *sdk.BaseResponse[map[string]any]
  34. resp, err := postReq[*sdk.BaseResponse[map[string]any]]("/tagService/openapi/archive/tag", gout.H{
  35. "tagId": tagId,
  36. "archiveId": archivesId,
  37. "remarks": remarks,
  38. "operatorName": operatorName,
  39. })
  40. if err != nil {
  41. return nil, &response.ErrCode{
  42. Code: response.PLATFORM_ERROR,
  43. Msg: err.Error(),
  44. }
  45. }
  46. if resp == nil {
  47. return nil, response.ErrPlatform
  48. }
  49. if resp.Code != 200 {
  50. return nil, &response.ErrCode{
  51. Code: resp.Code,
  52. Msg: resp.Message,
  53. }
  54. }
  55. return resp, nil
  56. }
  57. // postReq 发送post请求
  58. func postReq[T any](path string, data gout.H) (T, error) {
  59. var res T
  60. fmt.Println(sdk.GetConfig())
  61. // 检查配置
  62. if sdk.GetConfig().ApiDomain == "" {
  63. return res, fmt.Errorf("请先配置API域名")
  64. }
  65. url := fmt.Sprintf("%s%s", sdk.GetConfig().ApiDomain, path)
  66. fmt.Println("请求地址 ===>", url)
  67. err := gout.POST(url).Debug(sdk.GetConfig().AppDebug).
  68. SetHeader(gout.H{}).
  69. SetJSON(data).
  70. BindJSON(&res).
  71. Do()
  72. if err != nil {
  73. fmt.Println("请求失败: ", err)
  74. return res, err
  75. }
  76. return res, nil
  77. }