1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- package funcgraph
- import (
- "fmt"
- "mats/bus"
- "mats/conf"
- "strings"
- "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
- functiongraph "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/functiongraph/v2"
- "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/functiongraph/v2/model"
- region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/functiongraph/v2/region"
- )
- const (
- ak = "RA1D7CFVCVKUFX1FHHPB"
- sk = "cDrR2NgAF2KaA4MRkcK19r93P3P6hLKOPhHvPu9p"
- )
- func createFuncGraphClient() *functiongraph.FunctionGraphClient {
- auth := basic.NewCredentialsBuilder().
- WithAk(ak).
- WithSk(sk).
- Build()
- return functiongraph.NewFunctionGraphClient(
- functiongraph.FunctionGraphClientBuilder().
- WithRegion(region.ValueOf("cn-east-3")).
- WithCredential(auth).
- Build())
- }
- func OsgConvRequest(meshUrl string, assetId string, dbId string, table string) error {
- OsgConvStreamTopic := conf.AppConfig.Nats.OsgConvStreamTopic
- streamTopics := strings.Split(OsgConvStreamTopic, "#")
- client := createFuncGraphClient()
- url, err := bus.NatsCenter.RequestConfig("bus-network")
- if err != nil {
- return err
- }
- request := &model.AsyncInvokeFunctionRequest{Body: map[string]interface{}{
- "meshUrl": meshUrl,
- "assetId": assetId,
- "dbId": dbId,
- "table": table,
- "notifyNatsUrl": url,
- "notifyStream": streamTopics[0],
- "notifySubject": streamTopics[1],
- }}
- request.FunctionUrn = "urn:fss:cn-east-3:0956c65fd600f29f2ff6c00dbb3d1e2e:function:default:osgconv:v1"
- response, err := client.AsyncInvokeFunction(request)
- if err == nil {
- fmt.Printf("%+v\n", response)
- return nil
- }
- fmt.Println(err)
- return err
- }
|