Skip to content
Snippets Groups Projects
Unverified Commit cc52696d authored by capossele's avatar capossele
Browse files

:rotating_light: Fix webapi linter warnings

parent 5dec0554
No related branches found
No related tags found
No related merge requests found
...@@ -30,9 +30,9 @@ func (api *GoShimmerAPI) FindMessageByID(base58EncodedIDs []string) (*webapi_mes ...@@ -30,9 +30,9 @@ func (api *GoShimmerAPI) FindMessageByID(base58EncodedIDs []string) (*webapi_mes
// SendPayload send a message with the given payload. // SendPayload send a message with the given payload.
func (api *GoShimmerAPI) SendPayload(payload []byte) (string, error) { func (api *GoShimmerAPI) SendPayload(payload []byte) (string, error) {
res := &webapi_message.MessageResponse{} res := &webapi_message.MsgResponse{}
if err := api.do(http.MethodPost, routeSendPayload, if err := api.do(http.MethodPost, routeSendPayload,
&webapi_message.MessageRequest{Payload: payload}, res); err != nil { &webapi_message.MsgRequest{Payload: payload}, res); err != nil {
return "", err return "", err
} }
......
...@@ -11,34 +11,34 @@ import ( ...@@ -11,34 +11,34 @@ import (
// sendPayload creates a message of the given payload and // sendPayload creates a message of the given payload and
// broadcasts it to the node's neighbors. It returns the message ID if successful. // broadcasts it to the node's neighbors. It returns the message ID if successful.
func sendPayload(c echo.Context) error { func sendPayload(c echo.Context) error {
var request MessageRequest var request MsgRequest
if err := c.Bind(&request); err != nil { if err := c.Bind(&request); err != nil {
log.Info(err.Error()) log.Info(err.Error())
return c.JSON(http.StatusBadRequest, MessageResponse{Error: err.Error()}) return c.JSON(http.StatusBadRequest, MsgResponse{Error: err.Error()})
} }
//TODO: to check max payload size allowed, if exceeding return an error //TODO: to check max payload size allowed, if exceeding return an error
parsedPayload, _, err := payload.FromBytes(request.Payload) parsedPayload, _, err := payload.FromBytes(request.Payload)
if err != nil { if err != nil {
return c.JSON(http.StatusBadRequest, MessageResponse{Error: "not a valid payload"}) return c.JSON(http.StatusBadRequest, MsgResponse{Error: "not a valid payload"})
} }
msg, err := issuer.IssuePayload(parsedPayload) msg, err := issuer.IssuePayload(parsedPayload)
if err != nil { if err != nil {
return c.JSON(http.StatusBadRequest, MessageResponse{Error: err.Error()}) return c.JSON(http.StatusBadRequest, MsgResponse{Error: err.Error()})
} }
return c.JSON(http.StatusOK, MessageResponse{ID: msg.Id().String()}) return c.JSON(http.StatusOK, MsgResponse{ID: msg.Id().String()})
} }
// MessageResponse contains the ID of the message sent. // MsgResponse contains the ID of the message sent.
type MessageResponse struct { type MsgResponse struct {
ID string `json:"id,omitempty"` ID string `json:"id,omitempty"`
Error string `json:"error,omitempty"` Error string `json:"error,omitempty"`
} }
// MessageRequest contains the message to send. // MsgRequest contains the message to send.
type MessageRequest struct { type MsgRequest struct {
Payload []byte `json:"payload"` Payload []byte `json:"payload"`
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment