mirror of
https://github.com/valentineus/go-metatrader4.git
synced 2025-07-07 17:30:28 +03:00
Added GitHub Actions (#4)
This commit is contained in:
@ -3,7 +3,6 @@ package mt4
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"go.popov.link/metatrader4/internal/conn"
|
||||
@ -18,7 +17,6 @@ type Client struct {
|
||||
readTimeout time.Duration
|
||||
writeTimeout time.Duration
|
||||
autoClose bool
|
||||
dialer net.Dialer
|
||||
c *conn.Conn
|
||||
}
|
||||
|
||||
@ -86,7 +84,7 @@ func (c *Client) Execute(ctx context.Context, command string, params map[string]
|
||||
encoded, err := proto.EncodeParams(params)
|
||||
if err != nil {
|
||||
if c.autoClose {
|
||||
c.Close()
|
||||
_ = c.Close()
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
@ -94,14 +92,14 @@ func (c *Client) Execute(ctx context.Context, command string, params map[string]
|
||||
|
||||
if err := c.c.Send(ctx, req, c.writeTimeout); err != nil {
|
||||
if c.autoClose {
|
||||
c.Close()
|
||||
_ = c.Close()
|
||||
}
|
||||
return "", fmt.Errorf("send: %w", err)
|
||||
}
|
||||
|
||||
respBytes, err := c.c.Receive(ctx, c.readTimeout)
|
||||
if c.autoClose {
|
||||
c.Close()
|
||||
_ = c.Close()
|
||||
}
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("receive: %w", err)
|
||||
|
@ -15,10 +15,10 @@ import (
|
||||
func mockServer(response string) (net.Conn, net.Conn) {
|
||||
server, client := net.Pipe()
|
||||
go func() {
|
||||
defer server.Close()
|
||||
defer func() { _ = server.Close() }()
|
||||
buf := make([]byte, 1024)
|
||||
server.Read(buf) // read request ignoring
|
||||
server.Write([]byte(response))
|
||||
_, _ = server.Read(buf) // read request ignoring
|
||||
_, _ = server.Write([]byte(response))
|
||||
}()
|
||||
return client, server
|
||||
}
|
||||
|
Reference in New Issue
Block a user