Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
feature: make supernode compatible with the 0.2.x dfget
Browse files Browse the repository at this point in the history
Signed-off-by: Starnop <[email protected]>
  • Loading branch information
starnop committed Sep 16, 2019
1 parent d28e8f8 commit f1e9bd6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ require (
github.com/golang/mock v1.3.1
github.com/gorilla/context v0.0.0-20181012153548-51ce91d2eadd // indirect
github.com/gorilla/mux v1.5.0
github.com/gorilla/schema v1.1.0
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/magiconair/properties v1.8.1 // indirect
github.com/mailru/easyjson v0.0.0-20170902151237-2a92e673c9a6 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ github.com/gorilla/context v0.0.0-20181012153548-51ce91d2eadd h1:bB2XEQHhNsTTpqN
github.com/gorilla/context v0.0.0-20181012153548-51ce91d2eadd/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
github.com/gorilla/mux v1.5.0 h1:mq8bRov+5x+pZNR/uAHyUEgovR9gLgYFwDQIeuYi9TM=
github.com/gorilla/mux v1.5.0/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/schema v1.1.0 h1:CamqUDOFUBqzrvxuz2vEwo8+SUdwsluFh7IlzJh30LY=
github.com/gorilla/schema v1.1.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlIO2eleU=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
Expand Down
22 changes: 19 additions & 3 deletions supernode/server/0.3_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
sutil "github.com/dragonflyoss/Dragonfly/supernode/util"

"github.com/go-openapi/strfmt"
"github.com/gorilla/schema"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -68,10 +69,25 @@ var resultMap = map[string]string{
}

func (s *Server) registry(ctx context.Context, rw http.ResponseWriter, req *http.Request) (err error) {
reader := req.Body
request := &types.TaskRegisterRequest{}
if err := json.NewDecoder(reader).Decode(request); err != nil {
return errors.Wrap(errortypes.ErrInvalidValue, err.Error())

// parse request.Body to the types.TaskRegisterRequest struct
ct := req.Header.Get("Content-Type")
if ct == "application/x-www-form-urlencoded" {
if err := req.ParseForm(); err != nil {
return errors.Wrapf(errortypes.ErrInvalidValue, "failed to parse the request body as a form: %v", err)
}

decoder := schema.NewDecoder()
err = decoder.Decode(request, req.PostForm)
if err != nil {
return errors.Wrap(errortypes.ErrInvalidValue, err.Error())
}
} else {
reader := req.Body
if err := json.NewDecoder(reader).Decode(request); err != nil {
return errors.Wrap(errortypes.ErrInvalidValue, err.Error())
}
}

if err := request.Validate(strfmt.NewFormats()); err != nil {
Expand Down

0 comments on commit f1e9bd6

Please sign in to comment.