Minor code cleanup to client package before rewrite

This commit is contained in:
Kenneth Shaw 2018-07-13 11:35:03 +07:00
parent 4ae10864e4
commit 74e379587b

View File

@ -121,8 +121,7 @@ func (c *Client) ListTargets(ctxt context.Context) ([]Target, error) {
var err error var err error
var l []json.RawMessage var l []json.RawMessage
err = c.doReq(ctxt, "list", &l) if err = c.doReq(ctxt, "list", &l); err != nil {
if err != nil {
return nil, err return nil, err
} }
@ -201,8 +200,7 @@ func (c *Client) newTarget(ctxt context.Context, buf []byte) (Target, error) {
case "chrome", "chromium", "microsoft edge", "safari", "": case "chrome", "chromium", "microsoft edge", "safari", "":
x := new(Chrome) x := new(Chrome)
if buf != nil { if buf != nil {
err = easyjson.Unmarshal(buf, x) if err = easyjson.Unmarshal(buf, x); err != nil {
if err != nil {
return nil, err return nil, err
} }
} }
@ -227,8 +225,7 @@ func (c *Client) NewPageTargetWithURL(ctxt context.Context, urlstr string) (Targ
u += "?" + urlstr u += "?" + urlstr
} }
err = c.doReq(ctxt, u, t) if err = c.doReq(ctxt, u, t); err != nil {
if err != nil {
return nil, err 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. // VersionInfo returns information about the remote debugging protocol.
func (c *Client) VersionInfo(ctxt context.Context) (map[string]string, error) { func (c *Client) VersionInfo(ctxt context.Context) (map[string]string, error) {
var err error v := make(map[string]string)
if err := c.doReq(ctxt, "version", &v); err != nil {
v := map[string]string{}
err = c.doReq(ctxt, "version", &v)
if err != nil {
return nil, err return nil, err
} }
return v, nil return v, nil
} }
// WatchPageTargets watches for new page targets. // WatchPageTargets watches for new page targets.
func (c *Client) WatchPageTargets(ctxt context.Context) <-chan Target { func (c *Client) WatchPageTargets(ctxt context.Context) <-chan Target {
if ctxt == nil {
ctxt = context.Background()
}
ch := make(chan Target) ch := make(chan Target)
go func() { go func() {
defer close(ch) defer close(ch)