0
mirror of https://github.com/valentineus/go-metatrader4.git synced 2025-06-08 10:13:33 +03:00

Merge pull request #7 from valentineus/codex/prepare-documentation-for-methods-and-types

Improve package documentation
This commit is contained in:
Valentin Popov 2025-06-05 02:39:45 +04:00 committed by GitHub
commit 3b579b3bab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 0 deletions

View File

@ -7,6 +7,7 @@ import (
"time" "time"
) )
// Conn is a wrapper around net.Conn with convenience helpers.
type Conn struct { type Conn struct {
netConn net.Conn netConn net.Conn
} }
@ -14,6 +15,7 @@ type Conn struct {
// FromNetConn wraps an existing net.Conn. Useful for tests. // FromNetConn wraps an existing net.Conn. Useful for tests.
func FromNetConn(n net.Conn) *Conn { return &Conn{netConn: n} } func FromNetConn(n net.Conn) *Conn { return &Conn{netConn: n} }
// Dial opens a TCP connection to addr using the given timeout.
func Dial(ctx context.Context, addr string, timeout time.Duration) (*Conn, error) { func Dial(ctx context.Context, addr string, timeout time.Duration) (*Conn, error) {
d := net.Dialer{Timeout: timeout} d := net.Dialer{Timeout: timeout}
c, err := d.DialContext(ctx, "tcp", addr) c, err := d.DialContext(ctx, "tcp", addr)
@ -23,6 +25,7 @@ func Dial(ctx context.Context, addr string, timeout time.Duration) (*Conn, error
return &Conn{netConn: c}, nil return &Conn{netConn: c}, nil
} }
// Close closes the underlying network connection.
func (c *Conn) Close() error { func (c *Conn) Close() error {
if c.netConn == nil { if c.netConn == nil {
return nil return nil
@ -30,6 +33,7 @@ func (c *Conn) Close() error {
return c.netConn.Close() return c.netConn.Close()
} }
// Send writes data to the connection with the provided timeout.
func (c *Conn) Send(ctx context.Context, data []byte, timeout time.Duration) error { func (c *Conn) Send(ctx context.Context, data []byte, timeout time.Duration) error {
if dl, ok := ctx.Deadline(); ok { if dl, ok := ctx.Deadline(); ok {
if err := c.netConn.SetWriteDeadline(dl); err != nil { if err := c.netConn.SetWriteDeadline(dl); err != nil {
@ -44,6 +48,7 @@ func (c *Conn) Send(ctx context.Context, data []byte, timeout time.Duration) err
return err return err
} }
// Receive reads all data from the connection with the provided timeout.
func (c *Conn) Receive(ctx context.Context, timeout time.Duration) ([]byte, error) { func (c *Conn) Receive(ctx context.Context, timeout time.Duration) ([]byte, error) {
if dl, ok := ctx.Deadline(); ok { if dl, ok := ctx.Deadline(); ok {
if err := c.netConn.SetReadDeadline(dl); err != nil { if err := c.netConn.SetReadDeadline(dl); err != nil {

2
internal/conn/doc.go Normal file
View File

@ -0,0 +1,2 @@
// Package conn wraps net.Conn with simple timeout helpers.
package conn

2
internal/proto/doc.go Normal file
View File

@ -0,0 +1,2 @@
// Package proto provides helpers for encoding requests and decoding responses.
package proto

5
mt4/doc.go Normal file
View File

@ -0,0 +1,5 @@
// Package mt4 provides a lightweight client for MetaTrader 4 servers.
//
// It establishes a TCP connection, sends commands, and returns the decoded
// server response.
package mt4