微盟云开放平台的GO项目的能力SDK,根据开放能力的元数据规范,提供一套GO语言的能力定义,帮助开发者减少开发成本,使其可以快速接入微盟云的开放生态。
- API能力定义
- Client
- Request
- Response
- SPI能力定义
- Service
- Request
- Response
- MSG能力定义
- Service
- Message
|-- .editorconfig
|-- .gitignore
|-- go.mod
|-- LICENSE.MD
|-- pkg/ # 源码目录
| |-- sdk/
| |-- api/ #API数据结构及抽象
| |-- auth/ #授权数据结构及抽象
| |-- msg/ #MSG数据结构及抽象
| |-- spi/ #SPI数据结构及抽象
| |-- wapi/ # API能力定义
| |-- wos/ # Wos开放能力
| |-- xinyun/ # Xinyun开放能力
| |-- wspi/ # SPI能力定义
| |-- wos/ # Wos开放能力
| |-- xinyun/ # Xinyun开放能力
| |-- wmsg/ # MSG能力定义
| |-- wos/ # Wos开放能力
| |-- xinyun/ # Xinyun开放能力
-
使用go module管理包,在go项目工程的go.module添加依赖
require ( github.com/weimob-tech/go-ability-sdk v0.0.0 )
-
安装包,使用go命令
GO111MODULE=on GOPROXY=https://goproxy.cn,direct go mod tidy
-
Api调用
//API调用的逻辑
func testApi(shopId, shopType string){
clientInfo := auth.GetClientInfo("product-a")
client, err := weimob_shop.NewClientWithClientKey(clientInfo.ClientId, clientInfo.ClientSecret)
if err != nil {
panic(err)
}
req := weimob_shop.CreateCommentGoodsGetRequest()
req.ShopId = shopId
req.ShopType = shopType
req.QueryParameter = weimob_shop.CommentGoodsGetRequestQueryParameter{CommentIds: []int64{1, 2}}
req.BasicInfo = weimob_shop.CommentGoodsGetRequestBasicInfo{Vid: 55}
res, err := client.CommentGoodsGet(req)
if err != nil {
panic(err)
}
wlog.I().Msgf("api response: %v", codec.ToJson(res))
}
-
Spi实现
//实现SPI的逻辑 func main() { shop, err := weimob_shop.NewService() if err != nil { panic(err) } shop.OnPaasWeimobShopCouponPaasBatchLockCouponServiceInvocation( func(ctx context.Context, request *spi.WosInvocationRequest[weimob_shop.PaasWeimobShopCouponPaasBatchLockCouponRequest]) (response spi.InvocationResponse[weimob_shop.PaasWeimobShopCouponPaasBatchLockCouponResponse], err error) { wlog.I().Msgf("got request: %v", codec.ToJson(request)) ret := weimob_shop.PaasWeimobShopCouponPaasBatchLockCouponResponse{Success: true} return spi.Ok(&ret), nil }) }
-
Msg实现
//实现消息订阅逻辑
func main() {
shop, err := weimob_shop.NewService()
if err != nil {
panic(err)
}
shop.OnMallOrderMallOrderMessageEvent(
func(ctx context.Context, message *msg.WosOpenMessage[weimob_shop.MallOrderMallOrderMessageEvent]) (response x.Result, err error) {
wlog.I().Msgf("got request: %v", codec.ToJson(message))
event := message.GetMsgBody()
wlog.I().Msgf("got request body: %v", codec.ToJson(event))
return x.Ok(), nil
})
}
- 申请加入weimob_tech