package data_api import ( "context" "gd_management/apis" "gd_management/errors" "github.com/astaxie/beego/orm" "time" ) func DataApiAddApi(ctx context.Context, req *apis.ManagementDataApiAddApiReq, reply *apis.ManagementDataApiAddApiReply) error { if req.DataApiName == "" || req.Version == "" { return errors.ArgsError } o := orm.NewOrm() var dataApiInfo apis.DataApi err := o.QueryTable("t_gd_data_api").Filter("data_api_name", req.DataApiName).Filter("version", req.Version).One(&dataApiInfo) if err != nil { if err != orm.ErrNoRows { return errors.DataBaseError } } else { return errors.DataApiExist } var timeLayout = "2006-01-02 15:04:05" timeNow := time.Now().Format(timeLayout) dataApiInfo.DataApiName = req.DataApiName dataApiInfo.DataApiDesc = req.DataApiDesc dataApiInfo.DataApiType = req.DataApiType dataApiInfo.Version = req.Version dataApiInfo.CreateTime = timeNow dataApiInfo.UpdateTime = timeNow dataApiInfo.ReleaseTime = "0000-00-00 00:00:00" id, err := o.Insert(&dataApiInfo) if err != nil { return errors.DataBaseError } reply.DataApiId = id return nil }