summaryrefslogtreecommitdiff
path: root/protocol.go
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2020-11-18 18:15:09 +0300
committerValery Piashchynski <[email protected]>2020-11-18 18:15:09 +0300
commit8fab090abc369237d5f9be2ee676005b24c2a470 (patch)
tree9f7fc358b66357f0218b8256d8073616995b91db /protocol.go
parent4ccd58fc363264d24f642ab7e0ccfe6538a0b91c (diff)
Handler test
Diffstat (limited to 'protocol.go')
-rwxr-xr-xprotocol.go27
1 files changed, 16 insertions, 11 deletions
diff --git a/protocol.go b/protocol.go
index bdf78296..5e8be37a 100755
--- a/protocol.go
+++ b/protocol.go
@@ -1,15 +1,13 @@
package roadrunner
import (
- "fmt"
"os"
json "github.com/json-iterator/go"
+ "github.com/spiral/errors"
"github.com/spiral/goridge/v2"
)
-var j = json.ConfigCompatibleWithStandardLibrary
-
type stopCommand struct {
Stop bool `json:"stop"`
}
@@ -19,35 +17,42 @@ type pidCommand struct {
}
func sendControl(rl goridge.Relay, v interface{}) error {
+ const op = errors.Op("send control")
if data, ok := v.([]byte); ok {
- return rl.Send(data, goridge.PayloadControl|goridge.PayloadRaw)
+ err := rl.Send(data, goridge.PayloadControl|goridge.PayloadRaw)
+ if err != nil {
+ return errors.E(op, err)
+ }
+ return nil
}
- data, err := j.Marshal(v)
+ data, err := json.Marshal(v)
if err != nil {
- return fmt.Errorf("invalid payload: %s", err)
+ return errors.E(op, errors.Errorf("invalid payload: %s", err))
}
return rl.Send(data, goridge.PayloadControl)
}
func fetchPID(rl goridge.Relay) (int64, error) {
+ const op = errors.Op("fetchPID")
err := sendControl(rl, pidCommand{Pid: os.Getpid()})
if err != nil {
- return 0, err
+ return 0, errors.E(op, err)
}
body, p, err := rl.Receive()
if err != nil {
- return 0, err
+ return 0, errors.E(op, err)
}
if !p.HasFlag(goridge.PayloadControl) {
- return 0, fmt.Errorf("unexpected response, header is missing")
+ return 0, errors.E(op, errors.Str("unexpected response, header is missing"))
}
link := &pidCommand{}
- if err := json.Unmarshal(body, link); err != nil {
- return 0, err
+ err = json.Unmarshal(body, link)
+ if err != nil {
+ return 0, errors.E(op, err)
}
return int64(link.Pid), nil