From 74e379587b2eeb785c12408be082e3bac6f91642 Mon Sep 17 00:00:00 2001 From: Kenneth Shaw Date: Fri, 13 Jul 2018 11:35:03 +0700 Subject: [PATCH] Minor code cleanup to client package before rewrite --- client/client.go | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/client/client.go b/client/client.go index 1e957d6..c4f4c05 100644 --- a/client/client.go +++ b/client/client.go @@ -121,8 +121,7 @@ func (c *Client) ListTargets(ctxt context.Context) ([]Target, error) { var err error var l []json.RawMessage - err = c.doReq(ctxt, "list", &l) - if err != nil { + if err = c.doReq(ctxt, "list", &l); err != nil { return nil, err } @@ -201,8 +200,7 @@ func (c *Client) newTarget(ctxt context.Context, buf []byte) (Target, error) { case "chrome", "chromium", "microsoft edge", "safari", "": x := new(Chrome) if buf != nil { - err = easyjson.Unmarshal(buf, x) - if err != nil { + if err = easyjson.Unmarshal(buf, x); err != nil { return nil, err } } @@ -227,8 +225,7 @@ func (c *Client) NewPageTargetWithURL(ctxt context.Context, urlstr string) (Targ u += "?" + urlstr } - err = c.doReq(ctxt, u, t) - if err != nil { + if err = c.doReq(ctxt, u, t); err != nil { return nil, err } @@ -252,23 +249,15 @@ func (c *Client) CloseTarget(ctxt context.Context, t Target) error { // VersionInfo returns information about the remote debugging protocol. func (c *Client) VersionInfo(ctxt context.Context) (map[string]string, error) { - var err error - - v := map[string]string{} - err = c.doReq(ctxt, "version", &v) - if err != nil { + v := make(map[string]string) + if err := c.doReq(ctxt, "version", &v); err != nil { return nil, err } - return v, nil } // WatchPageTargets watches for new page targets. func (c *Client) WatchPageTargets(ctxt context.Context) <-chan Target { - if ctxt == nil { - ctxt = context.Background() - } - ch := make(chan Target) go func() { defer close(ch)