当前位置: 首页>>代码示例>>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;未经允许,请勿转载。