writers

package
v0.0.0-...-3449cf6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2015 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

writer包提供了一组实现io.Writer接口的结构。

Index

Constants

View Source
const Version = "0.3.4.150620"

Variables

This section is empty.

Functions

This section is empty.

Types

type Adder

type Adder interface {
	// 向容器添加一个io.Writer实例
	Add(io.Writer) error
}

io.Writer的容器。

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

Buffer 实现对输出内容的缓存,只有输出数量达到指定的值 才会真正地向指定的io.Writer输出。

func NewBuffer

func NewBuffer(size int) *Buffer

新建一个Buffer。 w最终输出的方向;当size<=1时,所有的内容都不会缓存,直接向w输出。

func (*Buffer) Add

func (b *Buffer) Add(w io.Writer) error

Adder.Add()

func (*Buffer) Flush

func (b *Buffer) Flush() (size int, err error)

Flusher.Flush() 若容器为空时,则相当于不作任何动作。

func (*Buffer) SetSize

func (b *Buffer) SetSize(size int)

设置缓存的大小,若值小于2,则所有的输出都不会被缓存。

func (*Buffer) Write

func (b *Buffer) Write(bs []byte) (int, error)

io.Writer.Write() 若容器为空时,则相当于不作任何动作。

type Console

type Console struct {
	// contains filtered or unexported fields
}

带色彩输出的控制台。

func NewConsole

func NewConsole(out int, foreground, background colors.Color) *Console

新建Console实例

out为输出方向,可以是colors.Stderr和colors.Stdout两个值。 foreground,background 为输出文字的前景色和背景色。

func (*Console) SetColor

func (c *Console) SetColor(foreground, background colors.Color)

更改输出颜色

func (*Console) Write

func (c *Console) Write(b []byte) (size int, err error)

io.Writer

type Container

type Container struct {
	// contains filtered or unexported fields
}

io.Writer的容器。

func NewContainer

func NewContainer() *Container

构造Container实例

func (*Container) Add

func (c *Container) Add(w io.Writer) error

添加一个io.Writer实例

func (*Container) Clear

func (c *Container) Clear()

清除所有的writer

func (*Container) Flush

func (c *Container) Flush() (size int, err error)

调用所有子项的Flush函数。

func (*Container) Len

func (c *Container) Len() int

包含的元素

func (*Container) Write

func (c *Container) Write(bs []byte) (size int, err error)

当某一项出错时,将直接返回其信息,后续的都将中断。 若容器为空时,则相当于不作任何动作。

type FlushAdder

type FlushAdder interface {
	Flusher
	Adder
}

Flusher + Adder

type Flusher

type Flusher interface {
	// 将缓存的内容输出
	Flush() (size int, err error)
}

缓存接口

go中并没有提供析构函数的机制,所以想要在对象销毁时自动输出缓存中的内容, 只能定义一个接口。

type Rotate

type Rotate struct {
	// contains filtered or unexported fields
}

可按大小进行分割的文件

import "log"
// 每个文件以100M大小进行分割,以日期名作为文件名保存在/var/log下。
f,_ := NewRotate("/var/log", 100*1024*1024)
l := log.New(f, "DEBUG", log.LstdFlags)

func NewRotate

func NewRotate(prefix, dir string, size int) (*Rotate, error)

新建Rotate。 prefix 文件名前缀。 dir为文件保存的目录,若不存在会尝试创建。 size为每个文件的最大尺寸,单位为byte。size应该足够大,如果size 的大小不足够支撑一秒钟产生的量,则会继续在原有文件之后追加内容。

func (*Rotate) Close

func (r *Rotate) Close() error

io.WriteCloser.Close()

func (*Rotate) Flush

func (r *Rotate) Flush()

Flusher.Flush()

func (*Rotate) Write

func (r *Rotate) Write(buf []byte) (int, error)

io.WriteCloser.Write()

type Smtp

type Smtp struct {
	// contains filtered or unexported fields
}

实现io.Writer接口的邮件发送。

func NewSmtp

func NewSmtp(username, password, subject, host string, sendTo []string) *Smtp

新建Smtp对象。 username为smtp的账号; password为smtp对应的密码; subject为发送邮件的主题; host为smtp的主机地址,需要带上端口号; sendTo为接收者的地址。

func (*Smtp) Write

func (s *Smtp) Write(msg []byte) (int, error)

io.Writer

type WriteAdder

type WriteAdder interface {
	Adder
	io.Writer
}

io.Writer + Adder

type WriteFlushAdder

type WriteFlushAdder interface {
	io.Writer
	Flusher
	Adder
}

io.Writer + Flusher + Adder

type WriteFlusher

type WriteFlusher interface {
	Flusher
	io.Writer
}

io.Writer + Flusher

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL