本文整理汇总了Golang中encoding/base64.NewEncoder函数的典型用法代码示例。如果您正苦于以下问题:Golang NewEncoder函数的具体用法?Golang NewEncoder怎么用?Golang NewEncoder使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewEncoder函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
binding := flag.String("b", "post", "Binding. Values are post, redirect, or nourl.")
flag.Parse()
input, e := ioutil.ReadAll(os.Stdin)
if e != nil {
log.Fatal(e)
}
if *binding == "redirect" {
deflated := deflate(input)
buf := bytes.Buffer{}
encoder := base64.NewEncoder(base64.StdEncoding, &buf)
encoder.Write(deflated)
encoder.Close()
fmt.Print(percentURLEncode(buf.String()))
} else if *binding == "nourl" {
deflated := deflate(input)
encoder := base64.NewEncoder(base64.StdEncoding, os.Stdout)
encoder.Write(deflated)
encoder.Close()
} else if *binding == "post" {
encoder := base64.NewEncoder(base64.StdEncoding, os.Stdout)
encoder.Write(input)
encoder.Close()
} else {
log.Fatal("Invalid Binding.")
}
}
开发者ID:kazuyamamoto,项目名称:samlenc,代码行数:35,代码来源:samlenc.go
示例2: SendMulti
// only allows single content
func SendMulti(auth Auth, email MultipartEmail) error {
if len(email.Content) != 1 {
panic("only 1 content supported")
}
a := smtp.PlainAuth("", auth.User, auth.Password, auth.Host)
buf := new(bytes.Buffer)
boundary := randomBoundary()
header := make(textproto.MIMEHeader)
header.Set("Subject", email.Subject)
header.Set("From", email.From)
header.Set("To", strings.Join(email.To, ", "))
if len(email.Cc) > 0 {
header.Set("Cc", strings.Join(email.Cc, ", "))
}
header.Set("MIME-Version", "1.0")
header.Set("Content-Type", "multipart/mixed; boundary="+boundary)
for k, v := range header {
for _, s := range v {
fmt.Fprintf(buf, "%s: %s%s", k, textproto.TrimString(s), crlf)
}
}
fmt.Fprint(buf, crlf)
mm := multipart.NewWriter(buf)
mm.SetBoundary(boundary)
{
content := email.Content[0]
header := make(textproto.MIMEHeader)
header.Set("Content-Type", content.Type)
header.Set("Content-Transfer-Encoding", "base64")
part, err := mm.CreatePart(header)
if err != nil {
return err
}
lw := &lineWriter{Writer: part, Length: 75}
e := base64.NewEncoder(base64.StdEncoding, lw)
e.Write(content.Data)
e.Close()
}
for _, a := range email.Attachments {
header := make(textproto.MIMEHeader)
header.Set("Content-Type", fmt.Sprintf(`%s; name="%s"`, a.Type, a.Filename))
if len(a.ContentID) > 0 {
header.Set("Content-ID", fmt.Sprintf(`<%s>`, a.ContentID))
}
header.Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, a.Filename))
header.Set("Content-Transfer-Encoding", "base64")
part, err := mm.CreatePart(header)
if err != nil {
return err
}
lw := &lineWriter{Writer: part, Length: 75}
e := base64.NewEncoder(base64.StdEncoding, lw)
e.Write(a.Data)
e.Close()
}
mm.Close()
addr := fmt.Sprintf("%s:%d", auth.Host, auth.Port)
return smtp.SendMail(addr, a, email.From, email.To, buf.Bytes())
}
开发者ID:xoba,项目名称:goutil,代码行数:61,代码来源:smtpc.go
示例3: base64encode
func base64encode(src []byte) string {
var buf bytes.Buffer
encoder := base64.NewEncoder(base64.StdEncoding, &buf)
encoder.Write(src)
encoder.Close()
return buf.String()
}
开发者ID:mschlimp,项目名称:lemming,代码行数:7,代码来源:oauth.go
示例4: encodedAuth
func encodedAuth(user, pwd string) string {
var buf bytes.Buffer
encoder := base64.NewEncoder(base64.StdEncoding, &buf)
encoder.Write([]byte(user + ":" + pwd))
encoder.Close()
return buf.String()
}
开发者ID:pvulgaris,项目名称:httpstream,代码行数:7,代码来源:stream.go
示例5: signV2
// signV2 sign the request before Do() (AWS Signature Version 2).
func signV2(req http.Request, accessKeyID, secretAccessKey string) *http.Request {
// Signature calculation is not needed for anonymous credentials.
if accessKeyID == "" || secretAccessKey == "" {
return &req
}
// Initial time.
d := time.Now().UTC()
// Add date if not present.
if date := req.Header.Get("Date"); date == "" {
req.Header.Set("Date", d.Format(http.TimeFormat))
}
// Calculate HMAC for secretAccessKey.
stringToSign := getStringToSignV2(req)
hm := hmac.New(sha1.New, []byte(secretAccessKey))
hm.Write([]byte(stringToSign))
// Prepare auth header.
authHeader := new(bytes.Buffer)
authHeader.WriteString(fmt.Sprintf("%s %s:", signV2Algorithm, accessKeyID))
encoder := base64.NewEncoder(base64.StdEncoding, authHeader)
encoder.Write(hm.Sum(nil))
encoder.Close()
// Set Authorization header.
req.Header.Set("Authorization", authHeader.String())
return &req
}
开发者ID:ptrimble,项目名称:dreamhost-personal-backup,代码行数:32,代码来源:request-signature-v2.go
示例6: handlePodSign
func handlePodSign(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
token := mux.Vars(r)["token"]
uuid, err := pods.getUUID(token)
if err != nil {
w.WriteHeader(http.StatusUnauthorized)
fmt.Fprintln(w, err)
return
}
content := r.FormValue("content")
if content == "" {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(w, "content form value not found")
return
}
// HMAC(UID:content)
h := hmac.New(sha512.New, hmacKey[:])
h.Write((*uuid)[:])
h.Write([]byte(content))
// Send back HMAC as the signature
w.Header().Add("Content-Type", "text/plain")
w.WriteHeader(http.StatusOK)
enc := base64.NewEncoder(base64.StdEncoding, w)
enc.Write(h.Sum(nil))
enc.Close()
}
开发者ID:hwinkel,项目名称:rkt,代码行数:31,代码来源:metadata_service.go
示例7: PutObject
func (c *Client) PutObject(name, bucket string, md5 hash.Hash, size int64, body io.Reader) error {
req := newReq("http://" + bucket + ".s3.amazonaws.com/" + name)
req.Method = "PUT"
req.ContentLength = size
if md5 != nil {
b64 := new(bytes.Buffer)
encoder := base64.NewEncoder(base64.StdEncoding, b64)
encoder.Write(md5.Sum(nil))
encoder.Close()
req.Header.Set("Content-MD5", b64.String())
}
c.Auth.SignRequest(req)
req.Body = ioutil.NopCloser(body)
res, err := c.httpClient().Do(req)
if res != nil && res.Body != nil {
defer res.Body.Close()
}
if err != nil {
return err
}
if res.StatusCode != 200 {
res.Write(os.Stderr)
return fmt.Errorf("Got response code %d from s3", res.StatusCode)
}
return nil
}
开发者ID:JayBlaze420,项目名称:camlistore,代码行数:27,代码来源:client.go
示例8: Base64Encoding
func Base64Encoding(s string) string {
var buf bytes.Buffer
encoder := base64.NewEncoder(base64.StdEncoding, &buf)
defer encoder.Close()
encoder.Write([]byte(s))
return buf.String()
}
开发者ID:rose312,项目名称:mzr,代码行数:7,代码来源:helper.go
示例9: CalcBase64
func CalcBase64(data string) string {
var buf bytes.Buffer
encoder := base64.NewEncoder(base64.StdEncoding, &buf)
encoder.Write([]byte(data))
encoder.Close()
return buf.String()
}
开发者ID:WH-Wang,项目名称:libgo,代码行数:7,代码来源:utils.go
示例10: Encode
// Encode encodes the transport as a single string for the purpose of letting a
// user paste it into his application configuraion.
func (t *Connection) Encode() (string, error) {
resultWriter := new(bytes.Buffer)
// Write version number first and verify that it wrote exactly two characters
n, _ := resultWriter.WriteString(ShareableTansportConnectionVersion)
if n != 2 {
panic("invalid version lentgh")
}
data := struct {
Transport string `json:"t"`
Secret string `json:"s"`
Addr string `json:"a"`
}{
Transport: t.Transport,
Secret: t.Secret,
Addr: t.Addr,
}
// JSON encode the data struct
jsonBytes, err := json.Marshal(data)
if err != nil {
panic(err)
}
// Base64 encode the JSON data
encoder := base64.NewEncoder(base64.URLEncoding, resultWriter)
encoder.Write(jsonBytes)
encoder.Close()
return string(resultWriter.Bytes()[:]), nil
}
开发者ID:thomasf,项目名称:alkasir,代码行数:33,代码来源:connection.go
示例11: writeBase64String
func writeBase64String(s string, b *bufio.Writer, f *Format) {
b.WriteRune('|')
w := base64.NewEncoder(base64.StdEncoding, b)
w.Write([]byte(s))
w.Close()
b.WriteRune('|')
}
开发者ID:hlandau,项目名称:sx,代码行数:7,代码来源:sx.go
示例12: PutObject
func (c *Client) PutObject(name, bucket string, md5 hash.Hash, size int64, body io.Reader) error {
req := newReq("http://" + bucket + "." + c.hostname() + "/" + name)
req.Method = "PUT"
req.ContentLength = size
if md5 != nil {
b64 := new(bytes.Buffer)
encoder := base64.NewEncoder(base64.StdEncoding, b64)
encoder.Write(md5.Sum(nil))
encoder.Close()
req.Header.Set("Content-MD5", b64.String())
}
if c.DefaultACL != "" {
req.Header.Set("x-amz-acl", c.DefaultACL)
}
contentType := mime.TypeByExtension(path.Ext(name))
if contentType == "" {
contentType = "application/octet-stream"
}
req.Header.Set("Content-Type", contentType)
c.Auth.SignRequest(req)
req.Body = ioutil.NopCloser(body)
res, err := c.httpClient().Do(req)
if res != nil && res.Body != nil {
defer httputil.CloseBody(res.Body)
}
if err != nil {
return err
}
if res.StatusCode != http.StatusOK {
res.Write(os.Stderr)
return fmt.Errorf("Got response code %d from s3", res.StatusCode)
}
return nil
}
开发者ID:simonz05,项目名称:util,代码行数:35,代码来源:client.go
示例13: encode64
func encode64(value string) (result string) {
buffer := &bytes.Buffer{}
encoder := base64.NewEncoder(base64.StdEncoding, buffer)
encoder.Write([]byte(value))
encoder.Close()
return buffer.String()
}
开发者ID:qrush,项目名称:higo,代码行数:7,代码来源:sessions.go
示例14: Encode
// Encode encodes data to a base64 encoded using the secconf codec.
// data is encrypted with all public keys found in the supplied keyring.
func Encode(data []byte, keyring io.Reader) ([]byte, error) {
entityList, err := openpgp.ReadArmoredKeyRing(keyring)
if err != nil {
return nil, err
}
buffer := new(bytes.Buffer)
encoder := base64.NewEncoder(base64.StdEncoding, buffer)
pgpWriter, err := openpgp.Encrypt(encoder, entityList, nil, nil, nil)
if err != nil {
return nil, err
}
gzWriter := gzip.NewWriter(pgpWriter)
if _, err := gzWriter.Write(data); err != nil {
return nil, err
}
if err := gzWriter.Close(); err != nil {
return nil, err
}
if err := pgpWriter.Close(); err != nil {
return nil, err
}
if err := encoder.Close(); err != nil {
return nil, err
}
return buffer.Bytes(), nil
}
开发者ID:untoldone,项目名称:bloomapi,代码行数:28,代码来源:secconf.go
示例15: wrap64
// wrap64 writes a byte payload as wrapped base64 to an io.writer
func wrap64(writer io.Writer, b []byte, wrap int) {
breaker := NewLineBreaker(writer, wrap)
b64 := base64.NewEncoder(base64.StdEncoding, breaker)
b64.Write(b)
b64.Close()
breaker.Close()
}
开发者ID:crooks,项目名称:yamn,代码行数:8,代码来源:linebreaker_test.go
示例16: tcp_checksum
func tcp_checksum(b []byte) uint16 {
if len(b)%2 != 0 {
panic(fmt.Sprintf("tcp checksum bad length: %d", len(b)))
}
buf := bytes.NewBuffer(make([]byte, 0))
enc := base64.NewEncoder(base64.StdEncoding, buf)
enc.Write(b)
// b64, _ := ioutil.ReadAll(buf)
// Trace("To Checksum: %v", string(b64))
var sum uint32 = 0
var tmp uint16
for c := 0; c < len(b); c = c + 2 {
tmp = uint16(b[c]) | uint16(b[c+1])<<8
sum += uint32(tmp)
}
sum = (sum >> 16) + (sum & 0xffff)
sum += (sum >> 16)
Trace("tcp checksum: %d", uint16(^sum))
return uint16(^sum)
}
开发者ID:jpg0,项目名称:eyego,代码行数:25,代码来源:checksum_reader.go
示例17: WriteTo
// WriteTo writes the LogplexLineFormatter to the provided writer
// in Kinesis' PutRecordsFormat. Conforms to the WriterTo interface.
func (r KinesisRecord) WriteTo(w io.Writer) (n int64, err error) {
var t int
var t64 int64
var b string
// Add an integer in the PartitionKey to enable distribution
// over multiple shards in the Kinesis stream.
b = partitionKeyHeader + r.partitionKey() + partitionKeyFooter
t, err = w.Write([]byte(b))
n += int64(t)
if err != nil {
return
}
e := base64.NewEncoder(base64.StdEncoding, w)
t64, err = io.Copy(e, r.llf)
n += encodedLen(t64)
if err != nil {
return
}
if err = e.Close(); err != nil {
return
}
t, err = w.Write([]byte(`"}`))
n += int64(t)
return
}
开发者ID:heroku,项目名称:log-shuttle,代码行数:32,代码来源:kinesis_types.go
示例18: PutObject
func (c *Client) PutObject(key, bucket string, md5 hash.Hash, size int64, body io.Reader) error {
req := newReq(c.keyURL(bucket, key))
req.Method = "PUT"
req.ContentLength = size
if md5 != nil {
b64 := new(bytes.Buffer)
encoder := base64.NewEncoder(base64.StdEncoding, b64)
encoder.Write(md5.Sum(nil))
encoder.Close()
req.Header.Set("Content-MD5", b64.String())
}
c.Auth.SignRequest(req)
req.Body = ioutil.NopCloser(body)
res, err := c.transport().RoundTrip(req)
if res != nil && res.Body != nil {
defer httputil.CloseBody(res.Body)
}
if err != nil {
return err
}
if res.StatusCode != http.StatusOK {
// res.Write(os.Stderr)
return fmt.Errorf("Got response code %d from s3", res.StatusCode)
}
return nil
}
开发者ID:sfrdmn,项目名称:camlistore,代码行数:27,代码来源:client.go
示例19: encodedUsernameAndPassword
func encodedUsernameAndPassword(user, pwd string) string {
bb := &bytes.Buffer{}
encoder := base64.NewEncoder(base64.StdEncoding, bb)
encoder.Write([]byte(user + ":" + pwd))
encoder.Close()
return bb.String()
}
开发者ID:rene-dev,项目名称:go-twitter,代码行数:7,代码来源:http_auth.go
示例20: encode
func encode(r io.Reader) error {
p := new(bytes.Buffer)
defer flush(p)
e := base64.NewEncoder(base64.StdEncoding, p)
defer e.Close()
var b [8192]byte
for {
n, err := r.Read(b[:])
if n > 0 {
e.Write(b[:n])
}
write(p)
if err == io.EOF {
break
}
if err != nil {
return err
}
}
return nil
}
开发者ID:qeedquan,项目名称:misc_utilities,代码行数:25,代码来源:base64.go
注:本文中的encoding/base64.NewEncoder函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论