1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- package provider
- import (
- "context"
- "gd_management/apis"
- "gd_management/errors"
- "gd_management/impl/pubsub"
- "fmt"
- "strings"
- "time"
- "github.com/astaxie/beego/orm"
- )
- func ManagementAddProviderApi(ctx context.Context, req *apis.ManagementAddProviderApiReq, reply *apis.ManagementAddProviderApiReply) error {
- fmt.Println(req)
- if req.ProviderId == 0 || req.ThirdpartApiName == "" || req.ThirdpartApiRouter == "" || req.ThirdpartHost == "" || req.ProviderApiCode == "" {
- return errors.ArgsError
- }
- var provider apis.ProviderPlatform
- err := orm.NewOrm().QueryTable("t_gd_provider").Filter("id", req.ProviderId).One(&provider)
- if err != nil {
- if err == orm.ErrNoRows {
- return errors.PorviderPlatformNotExist
- } else {
- return errors.DataBaseError
- }
- }
- var providerApi apis.ProviderApi
- if strings.Contains(req.ProviderApiCode, "-") == false {
- providerApi.ProviderApiCode = provider.PlatformCode + "-" + req.ProviderApiCode
- } else {
- providerApi.ProviderApiCode = req.ProviderApiCode
- }
- if strings.HasPrefix(req.ThirdpartApiRouter, "/") == true {
- providerApi.ThirdpartApiRouter = req.ThirdpartApiRouter[1:]
- } else {
- providerApi.ThirdpartApiRouter = req.ThirdpartApiRouter
- }
- if strings.HasSuffix(req.ThirdpartHost, "/") == true {
- providerApi.ThirdpartHost = req.ThirdpartHost[0 : len(req.ThirdpartHost)-1]
- } else {
- providerApi.ThirdpartHost = req.ThirdpartHost
- }
- providerApi.Count = req.Count
- //providerApi.ThirdpartApiRouter = req.ThirdpartApiRouter
- providerApi.ThirdpartApiName = req.ThirdpartApiName
- providerApi.ProviderId = req.ProviderId
- providerApi.Cost = req.Cost
- providerApi.ThirdpartApiMethod = strings.ToUpper(req.ThirdpartApiMethod)
- providerApi.State = req.State
- providerApi.Timeout = req.Timeout
- var timeLayout = "2006-01-02 15:04:05"
- timeNow := time.Now().Format(timeLayout)
- providerApi.CreateTime = timeNow
- providerApi.UpdateTime = timeNow
- id, err := orm.NewOrm().Insert(&providerApi)
- if err != nil {
- return errors.DataBaseError
- }
- pubsub.PublishProviderExportInfoNotify()
- reply.ProviderApiId = id
- return nil
- }
|