osgconv.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package funcgraph
  2. import (
  3. "assetcenter/conf"
  4. "fmt"
  5. "strings"
  6. "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
  7. functiongraph "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/functiongraph/v2"
  8. "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/functiongraph/v2/model"
  9. region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/functiongraph/v2/region"
  10. )
  11. const (
  12. ak = "RA1D7CFVCVKUFX1FHHPB"
  13. sk = "cDrR2NgAF2KaA4MRkcK19r93P3P6hLKOPhHvPu9p"
  14. )
  15. func createFuncGraphClient() *functiongraph.FunctionGraphClient {
  16. auth := basic.NewCredentialsBuilder().
  17. WithAk(ak).
  18. WithSk(sk).
  19. Build()
  20. return functiongraph.NewFunctionGraphClient(
  21. functiongraph.FunctionGraphClientBuilder().
  22. WithRegion(region.ValueOf("cn-east-3")).
  23. WithCredential(auth).
  24. Build())
  25. }
  26. func OsgConvRequest(meshUrl string, assetId string, dbId string, table string, natsUrl string) error {
  27. OsgConvStreamTopic := conf.AppConfig.Nats.OsgConvStreamTopic
  28. streamTopics := strings.Split(OsgConvStreamTopic, "#")
  29. client := createFuncGraphClient()
  30. request := &model.AsyncInvokeFunctionRequest{Body: map[string]interface{}{
  31. "meshUrl": meshUrl,
  32. "assetId": assetId,
  33. "dbId": dbId,
  34. "table": table,
  35. "notifyNatsUrl": natsUrl,
  36. "notifyStream": streamTopics[0],
  37. "notifySubject": streamTopics[1],
  38. }}
  39. fmt.Println(request)
  40. // request.FunctionUrn = "urn:fss:cn-east-3:0956c65fd600f29f2ff6c00dbb3d1e2e:function:default:osgconv:v1"
  41. // request.FunctionUrn = "urn:fss:cn-east-3:0956c65fd600f29f2ff6c00dbb3d1e2e:function:default:osgconv:v2"
  42. request.FunctionUrn = "urn:fss:cn-east-3:0956c65fd600f29f2ff6c00dbb3d1e2e:function:default:osgconv:latest"
  43. response, err := client.AsyncInvokeFunction(request)
  44. if err == nil {
  45. fmt.Printf("%+v\n", response)
  46. return nil
  47. }
  48. fmt.Println(err)
  49. return err
  50. }