Skip to content

Commit

Permalink
update: [AccTask] Invoke
Browse files Browse the repository at this point in the history
  • Loading branch information
kainonly committed Oct 19, 2023
1 parent 698addf commit 99f8188
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 33 deletions.
16 changes: 16 additions & 0 deletions api/acc_tasks/controller.go
Original file line number Diff line number Diff line change
@@ -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)
}
37 changes: 36 additions & 1 deletion api/acc_tasks/service.go
Original file line number Diff line number Diff line change
@@ -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
}
7 changes: 4 additions & 3 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 0 additions & 28 deletions api/tencent/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"net/http"
"net/url"
"sort"
"strconv"
"strings"
"time"
)
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion bootstrap/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 99f8188

Please sign in to comment.