本文整理汇总了Golang中net/textproto.Dial函数的典型用法代码示例。如果您正苦于以下问题:Golang Dial函数的具体用法?Golang Dial怎么用?Golang Dial使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Dial函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Connect
// Connect initializes the connection to the specified ftp server address.
//
// It is generally followed by a call to Login() as most FTP commands require
// an authenticated user.
func Connect(addr string) (*ServerConn, error) {
conn, err := textproto.Dial("tcp", addr)
if err != nil {
return nil, err
}
host, _, err := net.SplitHostPort(addr)
if err != nil {
conn.Close()
return nil, err
}
c := &ServerConn{
conn: conn,
host: host,
features: make(map[string]string),
}
_, _, err = c.conn.ReadResponse(StatusReady)
if err != nil {
c.Quit()
return nil, err
}
err = c.feat()
if err != nil {
c.Quit()
return nil, err
}
return c, nil
}
示例2: Dial
// Dial the beanstalkd server at remote address addr.
func Dial(addr string, onConnect func(*Conn)) (*Conn, os.Error) {
textConn, err := textproto.Dial("tcp", addr)
if err != nil {
return nil, err
}
return newConn(addr, textConn, onConnect), nil
}
示例3: Connect
// Connect initializes the connection to the specified ftp server address.
//
// It is generally followed by a call to Login() as most FTP commands require
// an authenticated user.
func Connect(addr string) (*ServerConn, error) {
conn, err := textproto.Dial("tcp", addr)
if err != nil {
return nil, err
}
a := strings.SplitN(addr, ":", 2)
c := &ServerConn{
conn: conn,
host: a[0],
features: make(map[string]string),
}
_, _, err = c.conn.ReadResponse(StatusReady)
if err != nil {
c.Quit()
return nil, err
}
err = c.feat()
if err != nil {
c.Quit()
return nil, err
}
return c, nil
}
示例4: DialFtp
func DialFtp(addr string) (*FtpConn, os.Error) {
conn, err := proto.Dial("tcp", addr)
if err != nil {
return nil, err
}
return &FtpConn{PreLogin, 0, conn}, nil
}
示例5: New
// New connects to an NNTP server.
// The network and addr are passed to net.Dial to
// make the connection.
//
// Example:
// conn, err := nntp.Dial("tcp", "my.news:nntp")
//
func New(network, addr string) (*Conn, error) {
c, err := textproto.Dial(network, addr)
if err != nil {
return nil, err
}
return newClient(c)
}
示例6: cmd
func (c *Conn) cmd(response, format string, a ...interface{}) *result {
err := c.textConn.PrintfLine(format, a...)
for tries := 0; err != nil && tries < retryCount; tries++ {
c.textConn, err = textproto.Dial("tcp", c.Name)
if err != nil {
continue
}
if c.onConnect != nil {
c.onConnect(c)
}
err = c.textConn.PrintfLine(format, a...)
}
if err != nil {
return &result{err: err}
}
str, err := c.textConn.ReadLine()
if err != nil {
return &result{err: err}
}
var res result
res.line = str
args := strings.Fields(str)
res.name = args[0]
res.args = args[1:]
res.setError(response)
res.readBody(c.textConn.R)
return &res
}
示例7: main
func main() {
// read log file todo: move in function
cfgFile, _ := os.Open("bot.json")
decoder := json.NewDecoder(cfgFile)
cfg := Configuration{}
err := decoder.Decode(&cfg)
if err != nil {
fmt.Println("ERROR cfg: ", err)
return
}
// end config read
// Build bot
bot := new(Bot)
bot.activeAdmins = make(map[string]bool)
bot.voted = make(map[string]bool)
bot.suggestions = make(map[int]Title)
bot.writeChan = make(chan *IrcMessage)
bot.config = &cfg
// connect to the server
bot.conn, err = textproto.Dial("tcp", cfg.Host+":"+cfg.Port)
if err != nil {
fmt.Printf("ERROR: %s\n", err)
return
}
bot.startBot()
}
示例8: Dial
// Dial connects to the address with the nickname
// and returns a Conn
func Dial(conf *Configuration) Context {
initLogger(conf.Verbose)
conn := &Connection{
address: fmt.Sprintf("%s:%d", conf.Hostname, conf.Port),
nickname: conf.Nickname,
ch: &Channels{m: make(map[string]*Channel)},
ev: NewEvents(),
done: make(chan struct{}),
}
log.Debugf("connecting to %s", conn.address)
tp, err := textproto.Dial("tcp", conn.address)
if err != nil {
log.Fatalf(err.Error())
}
conn.conn = tp
if conf.Password != "" {
conn.Raw("PASS %s", conf.Password)
}
conn.Raw("NICK %s", conf.Nickname)
conn.Raw("USER %s 0 * :%s", conf.Username, conf.Realname)
log.Debugf("starting readLoop")
go conn.readLoop()
return conn
}
示例9: Dial
// Dial uses a provided addr:port and opens a connection, returning any error
func (c *Connection) Dial(addr string) (err error) {
tp, err := textproto.Dial("tcp", addr)
if err != nil {
return err
}
c.conn = tp
return
}
示例10: connect
func (ep *endpoint) connect() error {
conn, err := textproto.Dial("tcp", fmt.Sprintf("%s:%d", ep.Host, ep.Port))
if err != nil {
ep.Error = err
return err
}
ep.Conn = conn
log.Printf("Connected to endpoint")
return nil
}
示例11: buildConnection
func buildConnection(addr string, useTls bool) (*textproto.Conn, error) {
if useTls == true {
tls, err := tls.Dial("tcp", addr, nil)
if err != nil {
return nil, err
}
return textproto.NewConn(tls), nil
} else {
return textproto.Dial("tcp", addr)
}
return nil, errors.New("could not build connection")
}
示例12: Connect
func (bot *Bot) Connect() {
conn, err := textproto.Dial("tcp", bot.server+":"+bot.port)
if err != nil {
log.Fatal("unable to connect to IRC server", err)
}
bot.conn = conn
log.Printf("Connected to IRC server %s:%s\n", bot.server, bot.port)
userCommand := fmt.Sprintf("USER %s 8 * :%s\n", bot.user, bot.user)
bot.conn.PrintfLine(userCommand)
bot.conn.PrintfLine("NICK " + bot.nick)
}
示例13: Dial
// Dial an APRS-IS service.
func Dial(prot, addr string) (rv *APRSIS, err error) {
var conn *textproto.Conn
conn, err = textproto.Dial(prot, addr)
if err != nil {
return
}
return &APRSIS{conn: conn,
rawLog: ioutil.Discard,
infoHandler: dumbInfoHandler,
}, nil
}
示例14: Dial
// Dial returns a new client connected to a dictionary server at
// addr on the given network.
func Dial(network, addr string) (*Client, error) {
text, err := textproto.Dial(network, addr)
if err != nil {
return nil, err
}
_, _, err = text.ReadCodeLine(220)
if err != nil {
text.Close()
return nil, err
}
return &Client{text: text}, nil
}
示例15: Dial
func Dial(network, address string) (*Conn, error) {
textprotoConn, err := textproto.Dial(network, address)
if err != nil {
return nil, err
}
conn := Conn{textprotoConn, ""}
_, message, err := conn.ReadCodeLine(200)
if err != nil {
return nil, err
}
conn.message = message
return &conn, nil
}