mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
update glide
This commit is contained in:
@@ -2,7 +2,6 @@ package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"path"
|
||||
|
||||
@@ -64,16 +63,14 @@ func (r *Route) Validate() error {
|
||||
res = append(res, ErrRoutesValidationInvalidPath)
|
||||
}
|
||||
|
||||
if r.Type == "" {
|
||||
r.Type = "sync"
|
||||
if r.Type == TypeNone {
|
||||
r.Type = TypeSync
|
||||
}
|
||||
|
||||
if r.Type != "async" && r.Type != "sync" {
|
||||
if r.Type != TypeAsync && r.Type != TypeSync {
|
||||
res = append(res, ErrRoutesValidationInvalidType)
|
||||
}
|
||||
|
||||
fmt.Println(">>>", r.Type)
|
||||
|
||||
if len(res) > 0 {
|
||||
return apiErrors.CompositeValidationError(res...)
|
||||
}
|
||||
|
||||
@@ -12,6 +12,15 @@ import (
|
||||
"github.com/go-openapi/validate"
|
||||
)
|
||||
|
||||
const (
|
||||
// TypeNone ...
|
||||
TypeNone = ""
|
||||
// TypeSync ...
|
||||
TypeSync = "sync"
|
||||
// TypeAsync ...
|
||||
TypeAsync = "async"
|
||||
)
|
||||
|
||||
/*Task task
|
||||
|
||||
swagger:model Task
|
||||
|
||||
@@ -53,7 +53,7 @@ func testRouter() *gin.Engine {
|
||||
func(ctx *gin.Context) {
|
||||
handleRequest(ctx, nil)
|
||||
},
|
||||
func(ctx *gin.Context, del bool) {})
|
||||
func(ctx *gin.Context) {})
|
||||
return r
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
@@ -92,8 +91,9 @@ func (s *Server) handleRunnerRequest(c *gin.Context) {
|
||||
handleRequest(c, enqueue)
|
||||
}
|
||||
|
||||
func (s *Server) handleTaskRequest(c *gin.Context, del bool) {
|
||||
if !del {
|
||||
func (s *Server) handleTaskRequest(c *gin.Context) {
|
||||
switch c.Request.Method {
|
||||
case "GET":
|
||||
task, err := s.MQ.Reserve()
|
||||
if err != nil {
|
||||
logrus.WithError(err)
|
||||
@@ -101,25 +101,18 @@ func (s *Server) handleTaskRequest(c *gin.Context, del bool) {
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusAccepted, task)
|
||||
} else {
|
||||
case "DELETE":
|
||||
body, err := ioutil.ReadAll(c.Request.Body)
|
||||
if err != nil {
|
||||
logrus.WithError(err)
|
||||
c.JSON(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
bodyStr := strings.TrimSpace(string(body))
|
||||
if bodyStr == "null" {
|
||||
logrus.WithError(err)
|
||||
c.JSON(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
var task models.Task
|
||||
if err = json.Unmarshal(body, &task); err != nil {
|
||||
logrus.WithError(err)
|
||||
c.JSON(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := s.MQ.Delete(&task); err != nil {
|
||||
@@ -141,7 +134,6 @@ func extractFields(c *gin.Context) logrus.Fields {
|
||||
}
|
||||
|
||||
func (s *Server) Run(ctx context.Context) {
|
||||
|
||||
s.Router.Use(func(c *gin.Context) {
|
||||
ctx, _ := titancommon.LoggerWithFields(ctx, extractFields(c))
|
||||
c.Set("ctx", ctx)
|
||||
@@ -155,7 +147,7 @@ func (s *Server) Run(ctx context.Context) {
|
||||
s.Router.Run()
|
||||
}
|
||||
|
||||
func bindHandlers(engine *gin.Engine, reqHandler func(ginC *gin.Context), taskHandler func(ginC *gin.Context, del bool)) {
|
||||
func bindHandlers(engine *gin.Engine, reqHandler func(ginC *gin.Context), taskHandler func(ginC *gin.Context)) {
|
||||
engine.GET("/", handlePing)
|
||||
engine.GET("/version", handleVersion)
|
||||
|
||||
@@ -180,15 +172,8 @@ func bindHandlers(engine *gin.Engine, reqHandler func(ginC *gin.Context), taskHa
|
||||
}
|
||||
}
|
||||
|
||||
taskHandlerDelete := func(ginC *gin.Context) {
|
||||
taskHandler(ginC, true)
|
||||
}
|
||||
taskHandlerReserve := func(ginC *gin.Context) {
|
||||
taskHandler(ginC, false)
|
||||
}
|
||||
|
||||
engine.GET("/tasks", taskHandlerReserve)
|
||||
engine.DELETE("/tasks", taskHandlerDelete)
|
||||
engine.DELETE("/tasks", taskHandler)
|
||||
engine.GET("/tasks", taskHandler)
|
||||
engine.Any("/r/:app/*route", reqHandler)
|
||||
|
||||
// This final route is used for extensions, see Server.Add
|
||||
|
||||
Reference in New Issue
Block a user