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


Golang Encoding.EncodeToString方法代碼示例

本文整理匯總了Golang中encoding/base64.Encoding.EncodeToString方法的典型用法代碼示例。如果您正苦於以下問題:Golang Encoding.EncodeToString方法的具體用法?Golang Encoding.EncodeToString怎麽用?Golang Encoding.EncodeToString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在encoding/base64.Encoding的用法示例。


在下文中一共展示了Encoding.EncodeToString方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: dns

func dns(username string, password string, domain string, ip string) string {
	//base64
	Authorization := username + ":" + password
	encodeStd := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
	var en *base64.Encoding = base64.NewEncoding(encodeStd)
	var buf *bytes.Buffer = bytes.NewBufferString(Authorization)
	enS := en.EncodeToString(buf.Bytes())

	//http request and header
	url := fmt.Sprintf("http://ddns.oray.com/ph/update?hostname=%s&myip=%s", domain, ip)
	requ, _ := http.NewRequest("GET", url, nil)
	requ.Header.Add("Authorization", "Basic "+enS)
	requ.Header.Add("User-Agent", "FUCKALL")

	client := new(http.Client)
	resp, _ := client.Do(requ)
	defer resp.Body.Close()

	body, _ := ioutil.ReadAll(resp.Body)
	buf = bytes.NewBuffer(body)
	bufS := buf.String()
	return bufS
}
開發者ID:fengzai,項目名稱:snippet,代碼行數:23,代碼來源:dynamicDns.go

示例2: SendMail

func (this *Sender) SendMail() (e error) {
	var (
		deadline time.Duration = 5 * time.Second
		encoding *base64.Encoding
		buf      []byte = make([]byte, 512)
		r        int
	)
	encoding = base64.NewEncoding(tb)
	conn, e := net.Dial("tcp", this.Host)
	if e != nil {
		return
	}
	defer conn.Close()

	conn.SetDeadline(time.Now().Add(deadline))
	r, e = conn.Read(buf)
	if e != nil {
		return
	}
	fmt.Println(string(buf[:r-1]))

	conn.Write([]byte("EHLO Juxuny\r\n"))
	conn.SetDeadline(time.Now().Add(deadline))
	r, e = conn.Read(buf)
	if e != nil {
		return
	}
	fmt.Println(string(buf[:r-1]))

	conn.Write([]byte("AUTH LOGIN\r\n"))
	conn.SetDeadline(time.Now().Add(deadline))
	r, e = conn.Read(buf)
	if e != nil {
		return
	}
	fmt.Println(string(buf[:r-1]))

	conn.Write([]byte(encoding.EncodeToString([]byte(this.UserName)) + "\r\n"))
	conn.SetDeadline(time.Now().Add(deadline))
	r, e = conn.Read(buf)
	if e != nil {
		return
	}
	fmt.Println(string(buf[:r-1]))

	conn.Write([]byte(encoding.EncodeToString([]byte(this.Password)) + "\r\n"))
	conn.SetDeadline(time.Now().Add(deadline))
	r, e = conn.Read(buf)
	if e != nil {
		return
	}
	fmt.Println(string(buf[:r-1]))

	conn.Write([]byte("MAIL FROM: <" + this.From + ">" + "\r\n"))
	conn.SetDeadline(time.Now().Add(deadline))
	r, e = conn.Read(buf)
	if e != nil {
		return
	}
	fmt.Println(string(buf[:r-1]))

	conn.Write([]byte("RCPT TO <" + this.To + ">\r\n"))
	conn.SetDeadline(time.Now().Add(deadline))
	r, e = conn.Read(buf)
	if e != nil {
		return
	}
	fmt.Println(string(buf[:r-1]))

	conn.Write([]byte("DATA\r\n"))
	conn.Write([]byte("\r\n"))
	conn.Write([]byte("Message-ID: <" + this.From + ">\r\n"))
	conn.Write([]byte("X-Mailer: <MMail 1.0>"))
	conn.Write([]byte("MIME-Version: 1.0"))
	conn.Write([]byte("Content-Type: text/plain"))
	conn.Write([]byte("From: <" + this.From + ">\r\n"))
	conn.Write([]byte("To: <" + this.To + ">\r\n"))
	conn.Write([]byte("Subject: " + this.Subject + "\r\n"))
	conn.Write([]byte("\r\n"))
	conn.Write([]byte(this.Text))
	conn.Write([]byte("\r\n.\r\n"))

	time.Sleep(5e9)
	conn.Write([]byte("QUIT\r\n"))
	conn.SetDeadline(time.Now().Add(deadline))
	r, e = conn.Read(buf)
	if e != nil {
		fmt.Println(e)
		return
	}
	fmt.Println(string(buf[:r-1]))

	return
}
開發者ID:yanue,項目名稱:go-webmail,代碼行數:94,代碼來源:smtp.go


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