forked from JointCloud/pcm-octopus
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
"gitlink.org.cn/JointCloud/pcm-octopus/internal/common"
|
|
"gitlink.org.cn/JointCloud/pcm-octopus/internal/svc"
|
|
"gitlink.org.cn/JointCloud/pcm-octopus/octopus"
|
|
"log"
|
|
)
|
|
|
|
type GetTrainJobLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewGetTrainJobLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetTrainJobLogic {
|
|
return &GetTrainJobLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *GetTrainJobLogic) GetTrainJob(in *octopus.GetTrainJobReq) (*octopus.GetTrainJobResp, error) {
|
|
resp := &octopus.GetTrainJobResp{}
|
|
|
|
var url_prefix = common.OctopusUrls[in.Platform]
|
|
var reqUrl = url_prefix + l.svcCtx.Config.OctopusApi.GetTrainJob
|
|
|
|
token := common.GetToken(in.Platform)
|
|
if token == "" {
|
|
log.Println("获取token失败, platform : ", in.Platform)
|
|
return nil, errors.New("获取token失败")
|
|
}
|
|
|
|
req := common.GetRestyRequest()
|
|
_, err := req.
|
|
SetHeader("Authorization", "Bearer "+token).
|
|
SetPathParam("id", in.Id).
|
|
SetResult(resp).
|
|
Get(reqUrl)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return resp, nil
|
|
}
|