FILE / ScuroNeko/mtg

telegram/dialer.go

Исходный файл и его история в репозитории.
FILE 0e2898f6be9ea71980ba8d13aaf28a9c1c94c9e2
Files
mtg/telegram/dialer.go
T
2018-07-02 08:09:22 +03:00

40 lines
739 B
Go

package telegram
import (
"io"
"net"
"time"
"github.com/juju/errors"
"github.com/9seconds/mtg/config"
"github.com/9seconds/mtg/wrappers"
)
const telegramDialTimeout = 10 * time.Second
type tgDialer struct {
net.Dialer
}
func (t *tgDialer) dial(addr string) (net.Conn, error) {
conn, err := t.Dialer.Dial("tcp", addr)
if err != nil {
return nil, errors.Annotate(err, "Cannot connect to Telegram")
}
if err = config.SetSocketOptions(conn); err != nil {
return nil, errors.Annotate(err, "Cannot set socket options")
}
return conn, nil
}
func (t *tgDialer) dialRWC(addr string) (io.ReadWriteCloser, error) {
conn, err := t.dial(addr)
if err != nil {
return nil, err
}
return wrappers.NewTimeoutRWC(conn), nil
}