Skip to content

Commit

Permalink
Merge pull request ao-space#12 from big-dust/ability
Browse files Browse the repository at this point in the history
refactor: InitAbility by sdk
  • Loading branch information
zhongguang-iscas authored Oct 18, 2023
2 parents 8afa4f6 + 7a4bac6 commit 1116597
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions biz/service/platform/ability.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,24 @@ package platform

import (
"agent/biz/model/device"
"agent/biz/model/platform"
"agent/biz/service/call"
"agent/config"
"agent/utils"
"agent/biz/service/pair"
"agent/utils/logger"
"github.com/dungeonsnd/gocom/encrypt/random"
"github.com/big-dust/platform-sdk-go/v2"
)

var platformApis *platform.PlatformAPIs
var platformApis *platform.GetAbilityResponse

func InitPlatformAbility() *platform.GetAbilityResponse {

func InitPlatformAbility() *platform.PlatformAPIs {
var headers = map[string]string{
"Request-Id": random.GenUUID(),
}
apiBaseUrl := device.GetApiBaseUrl()
logger.AppLogger().Debugf("apiBaseUrl:%s", apiBaseUrl)
url, _ := utils.JoinUrl(apiBaseUrl, config.Config.Platform.Ability.Path)
err := call.CallServiceByGet(url, headers, nil, &platformApis)

client, err := pair.GetSdkClientWithDeviceRegKey(apiBaseUrl)
if err != nil {
logger.AppLogger().Errorf("Get Platform Ability Request error:%v", err)
logger.AppLogger().Errorf("Get SDK Client Request error:%v", err)
return nil
}
platformApis, err = client.GetAbility()
logger.AppLogger().Infof("Get Platform Ability Request Successfully")
logger.AppLogger().Debugf("platformApis: %v", platformApis)
return platformApis
Expand All @@ -48,9 +44,9 @@ func CheckPlatformAbility(uri string) bool {
platformApis = InitPlatformAbility()
}

for _, apis := range platformApis.PlatformAPIs {
for _, api := range platformApis.PlatformApis {
//logger.AppLogger().Debugf(apis.URI)
if uri == apis.URI {
if uri == api.Uri {
return true
}
}
Expand Down

0 comments on commit 1116597

Please sign in to comment.