osgconv.go 1.6 KB

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