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


Golang io.WriterTo類代碼示例

本文整理匯總了Golang中io.WriterTo的典型用法代碼示例。如果您正苦於以下問題:Golang WriterTo類的具體用法?Golang WriterTo怎麽用?Golang WriterTo使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: Send

func (c *smtpSender) Send(from string, to []string, msg io.WriterTo) error {
	if err := c.Mail(from); err != nil {
		if err == io.EOF {
			// This is probably due to a timeout, so reconnect and try again.
			sc, derr := c.d.Dial()
			if derr == nil {
				if s, ok := sc.(*smtpSender); ok {
					*c = *s
					return c.Send(from, to, msg)
				}
			}
		}
		return err
	}

	for _, addr := range to {
		if err := c.Rcpt(addr); err != nil {
			return err
		}
	}

	w, err := c.Data()
	if err != nil {
		return err
	}

	if _, err = msg.WriteTo(w); err != nil {
		w.Close()
		return err
	}

	return w.Close()
}
開發者ID:wk66,項目名稱:grafana,代碼行數:33,代碼來源:smtp.go

示例2: doV3n11

// Redirect -- only accessible if method == POST
func (p *wmDecisionCore) doV3n11() WMDecision {
	var postIsCreate bool
	var httpCode int
	var httpError error
	var httpHeaders http.Header
	var writerTo io.WriterTo
	postIsCreate, p.req, p.cxt, httpCode, httpError = p.handler.PostIsCreate(p.req, p.cxt)
	if httpCode > 0 {
		p.writeHaltOrError(httpCode, httpError)
		return wmResponded
	}
	if postIsCreate {
		log.Print("[WM]: v3n11: Creating Path\n")
		_, p.req, p.cxt, httpCode, httpError = p.handler.CreatePath(p.req, p.cxt)
		if httpCode > 0 {
			p.writeHaltOrError(httpCode, httpError)
			return wmResponded
		}
		log.Print("[WM]: v3n11: Running Accept Helper\n")
		if p.runAcceptHelper() {
			return wmResponded
		}
	} else {
		log.Print("[WM]: v3n11: Running Process Post\n")
		p.req, p.cxt, httpCode, httpHeaders, writerTo, httpError = p.handler.ProcessPost(p.req, p.cxt)
		if httpCode > 0 {
			p.updateHttpResponseHeaders(httpHeaders)
			if httpError != nil {
				p.writeHaltOrError(httpCode, httpError)
			} else if writerTo != nil {
				p.resp.WriteHeader(httpCode)
				writerTo.WriteTo(p.resp)
			} else {
				p.resp.WriteHeader(httpCode)
			}
			return wmResponded
		}
		// TODO Aalok check what should be done here
		//p.resp.WriteHeader(n)
		//log.Print("Wrote Header but may not return wmResponded in doV3n11()\n")
		//p.encodeBodyIfSet()
	}
	log.Print("[WM]: v3n11: Running Response is Redirect?\n")
	var respIsRedirect bool
	respIsRedirect, p.req, p.cxt, httpCode, httpError = p.handler.ResponseIsRedirect(p.req, p.cxt)
	if httpCode > 0 {
		p.writeHaltOrError(httpCode, httpError)
		return wmResponded
	}
	if respIsRedirect {
		if len(p.resp.Header().Get("Location")) > 0 {
			p.resp.WriteHeader(http.StatusSeeOther)
		} else {
			p.resp.WriteHeader(http.StatusInternalServerError)
			io.WriteString(p.resp, "Response had do_redirect but no Location")
		}
		return wmResponded
	}
	return v3p11
}
開發者ID:pomack,項目名稱:webmachine.go,代碼行數:61,代碼來源:decision.go

示例3: main

func main() {
	flag.Parse()
	fname := flag.Arg(0)
	if fname == "" {
		usage()
		os.Exit(1)
	}
	f, err := os.Create(fname)
	if err != nil {
		log.Fatalf("%s", err)
	}
	defer f.Close()
	var w io.WriterTo
	d := captcha.RandomDigits(*flagLen)
	switch {
	case *flagAudio:
		w = captcha.NewAudio(d, *flagLang)
	case *flagImage:
		w = captcha.NewImage(d, *flagImgW, *flagImgH)
	}
	_, err = w.WriteTo(f)
	if err != nil {
		log.Fatalf("%s", err)
	}
	fmt.Println(d)
}
開發者ID:WalterShe,項目名稱:captcha,代碼行數:26,代碼來源:main.go

示例4: stringifyWriterTo

func stringifyWriterTo(w io.WriterTo) (string, error) {
	var buf bytes.Buffer
	_, err := w.WriteTo(&buf)
	if err != nil {
		return "", err
	}
	return buf.String(), nil
}
開發者ID:jessethegame,項目名稱:lush,代碼行數:8,代碼來源:metacmd.go

示例5: writeFile

func writeFile(dst string, src io.WriterTo) (int64, error) {
	f, err := os.Create(dst)
	if err != nil {
		return 0, fmt.Errorf("error creating file %q: %v", dst, err)
	}
	defer fi.SafeClose(f)
	return src.WriteTo(f)
}
開發者ID:crohling,項目名稱:kops,代碼行數:8,代碼來源:export_kubecfg.go

示例6: writeTo

func writeTo(w io.Writer, wt io.WriterTo, n *int64, err *error) {
	if *err != nil {
		return
	}
	var nn int64
	nn, *err = wt.WriteTo(w)
	*n += nn
}
開發者ID:BenLubar,項目名稱:bit,代碼行數:8,代碼來源:writer.go

示例7: offlineSend

func offlineSend(from string, to []string, msg io.WriterTo) error {
	if OfflineLogger.IsInfo() {
		var buf bytes.Buffer
		if _, err := msg.WriteTo(&buf); err != nil {
			return log.Error("mail.daemon.OfflineSend", "err", err, "buf", buf.String(), "message", msg)
		}
		OfflineLogger.Info("mail.Send", "from", from, "to", to, "msg", buf.String())
	}
	return nil
}
開發者ID:hafeez3000,項目名稱:csfw,代碼行數:10,代碼來源:daemon.go

示例8: writeToFile

// writeToFile creates the specified output file from the contents of w.
func writeToFile(ctx context.Context, w io.WriterTo, path string) error {
	f, err := os.Create(path)
	if err != nil {
		return err
	}
	if _, err := w.WriteTo(f); err != nil {
		f.Close()
		return err
	}
	return f.Close()
}
開發者ID:benjyw,項目名稱:kythe,代碼行數:12,代碼來源:bazel_go_extractor.go

示例9: Send

func (msc mockSendCloser) Send(from string, to []string, msg io.WriterTo) error {
	assert.NotEmpty(msc.t, from)
	assert.NotEmpty(msc.t, to)

	var buf bytes.Buffer
	msg.WriteTo(&buf)
	assert.NotEmpty(msc.t, buf.String())

	//msc.t.Log(buf.String())

	return msc.sendErr
}
開發者ID:hafeez3000,項目名稱:csfw,代碼行數:12,代碼來源:mocks_test.go

示例10: Deliver

func (s *SMTPDeliverer) Deliver(ctx scope.Context, from, to string, email io.WriterTo) error {
	// Connect and authenticate to SMTP server.
	c, err := smtp.Dial(s.addr)
	if err != nil {
		return fmt.Errorf("%s: dial error: %s", s, err)
	}
	defer c.Quit()

	if err := c.Hello(s.localName); err != nil {
		return fmt.Errorf("%s: ehlo error: %s", s, err)
	}

	if s.tlsConfig != nil {
		if err := c.StartTLS(s.tlsConfig); err != nil {
			return fmt.Errorf("%s: starttls error: %s", s, err)
		}
	}

	if s.auth != nil {
		if err := c.Auth(s.auth); err != nil {
			return fmt.Errorf("%s: auth error: %s", s, err)
		}
	}

	// Send email.
	if from == "" {
		from = "[email protected]" + s.localName
	}
	if err := c.Mail(from); err != nil {
		return fmt.Errorf("%s: mail error: %s", s, err)
	}

	if err := c.Rcpt(to); err != nil {
		return fmt.Errorf("%s: rcpt error: %s", s, err)
	}

	wc, err := c.Data()
	if err != nil {
		return fmt.Errorf("%s: data error: %s", s, err)
	}

	if _, err := email.WriteTo(wc); err != nil {
		return fmt.Errorf("%s: write error: %s", s, err)
	}
	if err := wc.Close(); err != nil {
		return fmt.Errorf("%s: close error: %s", s, err)
	}

	return nil
}
開發者ID:rmasoni,項目名稱:heim,代碼行數:50,代碼來源:smtp.go

示例11: Deliver

func (td *TestDeliverer) Deliver(ctx scope.Context, from, to string, email io.WriterTo) error {
	td.Lock()
	defer td.Unlock()

	buf := &bytes.Buffer{}
	if _, err := email.WriteTo(buf); err != nil {
		return err
	}

	if ch, ok := td.channels[to]; ok {
		ch <- buf.Bytes()
	} else {
		fmt.Printf("delivered:\n%s\n", buf.String())
	}

	return nil
}
開發者ID:rmasoni,項目名稱:heim,代碼行數:17,代碼來源:deliverer.go

示例12: gen

func gen(fname string) (Id string) {

	f, err := os.Create(fname)
	if err != nil {
		log.Fatalf("%s", err)
	}
	defer f.Close()
	var w io.WriterTo
	d := captcha.RandomDigits(6) // six digits is enough
	w = captcha.NewImage(d, captcha.StdWidth, captcha.StdHeight)
	_, err = w.WriteTo(f)
	if err != nil {
		log.Fatalf("%s", err)
	}
	log.Println("DEBUG Captcha: Created new image ", d)
	str := trans(d)
	return str
}
開發者ID:elbing,項目名稱:jailblog,代碼行數:18,代碼來源:jailBlogCaptcha.go

示例13: stats

func stats(w io.WriterTo, regex string, h *generic.Histogram) (sum, final float64) {
	re := regexp.MustCompile(regex)
	buf := &bytes.Buffer{}
	w.WriteTo(buf)
	//fmt.Fprintf(os.Stderr, "%s\n", buf.String())
	s := bufio.NewScanner(buf)
	for s.Scan() {
		match := re.FindStringSubmatch(s.Text())
		f, err := strconv.ParseFloat(match[1], 64)
		if err != nil {
			panic(err)
		}
		sum += f
		final = f
		if h != nil {
			h.Observe(f)
		}
	}
	return sum, final
}
開發者ID:basvanbeek,項目名稱:kit,代碼行數:20,代碼來源:buffers.go

示例14: WriteToPathExclusive

func WriteToPathExclusive(path string, source io.WriterTo, mode os.FileMode) error {
	file, exists, err := OpenFileExclusive(path, mode)
	if err != nil {
		return err
	}
	if exists {
		if _, err := file.Seek(0, 0); err != nil {
			file.Close()
			return err
		}
		if err := file.Truncate(0); err != nil {
			file.Close()
			return err
		}
	}
	if _, err := source.WriteTo(file); err != nil {
		file.Close()
		return err
	}
	return file.Close()
}
開發者ID:jcantrill,項目名稱:geard,代碼行數:21,代碼來源:io.go

示例15: HandlePageRequestById

func (serv *Server) HandlePageRequestById(w http.ResponseWriter, r *http.Request) {
	m := draftPageReg.FindStringSubmatch(r.URL.Path)
	if m == nil {
		http.Error(w, "Not found", 404)
		return
	}
	id := m[1]
	fmt.Println("req by id", id)

	var d io.WriterTo
	var ok bool
	d, ok = serv.activeDrafts[id]
	if !ok {
		d, ok = serv.archive.GetDraft(id)
	}
	if !ok {
		//404
	}
	_, err := d.WriteTo(w)
	if err != nil {
		//server error
	}
}
開發者ID:zmj,項目名稱:MTG-Drafter,代碼行數:23,代碼來源:server.go


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