diff --git a/api/acc_tasks/controller.go b/api/acc_tasks/controller.go index 172cef06..6e691990 100644 --- a/api/acc_tasks/controller.go +++ b/api/acc_tasks/controller.go @@ -1,5 +1,21 @@ package acc_tasks +import ( + "context" + "github.com/cloudwego/hertz/pkg/app" +) + type Controller struct { AccTasksService *Service } + +func (x *Controller) Invoke(ctx context.Context, c *app.RequestContext) { + r, err := x.AccTasksService.Invoke(ctx) + + if err != nil { + c.Error(err) + return + } + + c.JSON(200, r) +} diff --git a/api/acc_tasks/service.go b/api/acc_tasks/service.go index f57dd722..e61b9aa3 100644 --- a/api/acc_tasks/service.go +++ b/api/acc_tasks/service.go @@ -1,7 +1,42 @@ package acc_tasks -import "github.com/weplanx/server/common" +import ( + "context" + "github.com/weplanx/server/api/tencent" + "github.com/weplanx/server/common" + "net/url" + "strconv" + "time" +) type Service struct { *common.Inject + TencentService *tencent.Service +} + +func (x *Service) Invoke(ctx context.Context) (r M, err error) { + u, _ := url.Parse(x.V.AccelerateAddress) + timestamp := time.Now().Unix() + headerx := map[string]string{ + "Content-Type": "application/json", + "Host": u.Host, + "X-Scf-Cam-Uin": x.V.CamUin, + } + body := M{} + if _, err = common.HttpClient(u.String()).R().SetContext(ctx). + SetHeaders(headerx). + SetHeader("X-Scf-Cam-Timestamp", strconv.FormatInt(timestamp, 10)). + SetHeader("Authorization", x.TencentService.TC3Authorization(tencent.TC3Option{ + Service: "scf", + Headers: headerx, + Timestamp: timestamp, + Body: body, + })). + SetBody(body). + SetSuccessResult(&r). + Post(""); err != nil { + return + } + + return } diff --git a/api/api.go b/api/api.go index f9f15d61..925dee30 100644 --- a/api/api.go +++ b/api/api.go @@ -183,9 +183,10 @@ func (x *API) Routes(h *server.Hertz) (err error) { _imessages.DELETE(":id/metrics", x.Imessages.DeleteMetrics) _imessages.POST("publish", x.Imessages.Publish) } - //_acc_tasks := h.Group("acc_tasks", m...) - //{ - //} + _accTasks := h.Group("acc_tasks", m...) + { + _accTasks.POST("invoke", x.AccTasks.Invoke) + } _datasets := h.Group("datasets", m...) { _datasets.GET("", x.Datasets.Lists) diff --git a/api/tencent/service.go b/api/tencent/service.go index 02a7cd42..161fa8fa 100644 --- a/api/tencent/service.go +++ b/api/tencent/service.go @@ -18,7 +18,6 @@ import ( "net/http" "net/url" "sort" - "strconv" "strings" "time" ) @@ -151,33 +150,6 @@ func (x *Service) TC3Authorization(option TC3Option) string { ) } -func (x *Service) InvokeAccelerate(ctx context.Context) (r M, err error) { - u, _ := url.Parse(x.V.AccelerateAddress) - timestamp := time.Now().Unix() - headerx := map[string]string{ - "Content-Type": "application/json", - "Host": u.Host, - "X-Scf-Cam-Uin": x.V.CamUin, - } - body := M{} - if _, err = common.HttpClient(u.String()).R().SetContext(ctx). - SetHeaders(headerx). - SetHeader("X-Scf-Cam-Timestamp", strconv.FormatInt(timestamp, 10)). - SetHeader("Authorization", x.TC3Authorization(TC3Option{ - Service: "scf", - Headers: headerx, - Timestamp: timestamp, - Body: body, - })). - SetBody(body). - SetSuccessResult(&r). - Post(""); err != nil { - return - } - - return -} - type KeyAuthResult struct { Date string Txt string diff --git a/bootstrap/wire_gen.go b/bootstrap/wire_gen.go index 1e46bc4e..3a4a878a 100644 --- a/bootstrap/wire_gen.go +++ b/bootstrap/wire_gen.go @@ -158,7 +158,8 @@ func NewAPI(values2 *common.Values) (*api.API, error) { ImessagesServices: imessagesService, } acc_tasksService := &acc_tasks.Service{ - Inject: inject, + Inject: inject, + TencentService: tencentService, } acc_tasksController := &acc_tasks.Controller{ AccTasksService: acc_tasksService,