pcm-octopus/internal/logic/createdatasetlogic.go

51 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 CreateDataSetLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewCreateDataSetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateDataSetLogic {
return &CreateDataSetLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *CreateDataSetLogic) CreateDataSet(in *octopus.CreateDataSetReq) (*octopus.CreateDataSetResp, error) {
resp := &octopus.CreateDataSetResp{}
var url_prefix = common.OctopusUrls[in.Platform]
var reqUrl = url_prefix + l.svcCtx.Config.OctopusApi.CreateDataSet
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).
SetBody(in.CreateDataSet).
SetResult(resp).
Post(reqUrl)
if err != nil {
return nil, err
}
return resp, nil
}