當前位置: 首頁>>代碼示例>>Golang>>正文


Golang textproto.Dial函數代碼示例

本文整理匯總了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
}
開發者ID:nieware,項目名稱:goftp,代碼行數:35,代碼來源:ftp.go

示例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
}
開發者ID:edsrzf,項目名稱:beanstalk.go,代碼行數:8,代碼來源:beanstalk.go

示例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
}
開發者ID:darxen,項目名稱:goftp,代碼行數:31,代碼來源:ftp.go

示例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
}
開發者ID:juster,項目名稱:maw,代碼行數:7,代碼來源:ftp.go

示例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)
}
開發者ID:hobeone,項目名稱:nntp,代碼行數:14,代碼來源:nntp.go

示例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
}
開發者ID:edsrzf,項目名稱:beanstalk.go,代碼行數:30,代碼來源:beanstalk.go

示例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()
}
開發者ID:JSchwehn,項目名稱:GoIrcBot,代碼行數:28,代碼來源:main.go

示例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
}
開發者ID:j6n,項目名稱:anolis,代碼行數:32,代碼來源:connection.go

示例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
}
開發者ID:j6n,項目名稱:noye,代碼行數:10,代碼來源:conn.go

示例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
}
開發者ID:ScottBrooks,項目名稱:gocuc,代碼行數:10,代碼來源:runner.go

示例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")
}
開發者ID:peterkeen,項目名稱:macguffin,代碼行數:12,代碼來源:client.go

示例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)
}
開發者ID:GDG-Korea,項目名稱:Andnyang,代碼行數:12,代碼來源:bot.go

示例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
}
開發者ID:dustin,項目名稱:go-aprs,代碼行數:13,代碼來源:aprsis.go

示例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
}
開發者ID:2722,項目名稱:lantern,代碼行數:14,代碼來源:dict.go

示例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
}
開發者ID:yansal,項目名稱:nntp,代碼行數:14,代碼來源:nntp.go


注:本文中的net/textproto.Dial函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。