writers

package
v2.5.4 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adder

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

Adder 为 io.Writer 的容器。

type Buffer

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

Buffer 实现对输出内容的缓存

只有输出数量达到指定的值才会真正地向指定的 io.Writer 输出。

func NewBuffer

func NewBuffer(size int) *Buffer

NewBuffer 新建一个 Buffer

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

func (*Buffer) Add

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

Add 添加一个 io.Writer 实例

func (*Buffer) Flush

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

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

func (*Buffer) SetSize

func (b *Buffer) SetSize(size int)

SetSize 设置缓存的大小

若值小于 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
}

Console 带色彩输出的控制台

func NewConsole

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

NewConsole 新建 Console 实例

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

func (*Console) SetColor

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

SetColor 更改输出颜色

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
}

Container 为 io.Writer 的容器

func NewContainer

func NewContainer() *Container

NewContainer 构造 Container 实例

func (*Container) Add

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

Add 添加一个 io.Writer 实例

func (*Container) Clear

func (c *Container) Clear()

Clear 清除所有的 writer

func (*Container) Flush

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

Flush 调用所有子项的 Flush 函数

func (*Container) Len

func (c *Container) Len() int

Len 包含的元素

func (*Container) Write

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

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

type FlushAdder

type FlushAdder interface {
	Flusher
	Adder
}

type Flusher

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

Flusher 缓存接口

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

type SMTP

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

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

func NewSMTP

func NewSMTP(username, password, subject, host string, sendTo []string) *SMTP

NewSMTP 新建 SMTP 对象

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

func (*SMTP) Write

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

type WriteAdder

type WriteAdder interface {
	Adder
	io.Writer
}

type WriteFlushAdder

type WriteFlushAdder interface {
	io.Writer
	Flusher
	Adder
}

type WriteFlusher

type WriteFlusher interface {
	Flusher
	io.Writer
}

Directories

Path Synopsis
Package rotate 提供一个可以按文件大小进行分割的 io.Writer 实例。
Package rotate 提供一个可以按文件大小进行分割的 io.Writer 实例。

Jump to

Keyboard shortcuts

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