writers

package
v3.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2022 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 {
	// Add 向容器添加一个 io.Writer 实例
	Add(io.Writer) error
}

type Buffer

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

Buffer 实现对输出内容的缓存

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

func NewBuffer

func NewBuffer(size int) *Buffer

NewBuffer 新建一个 Buffer

当 size<=1 时,所有的内容都不会被缓存。

func (*Buffer) Add

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

Add 添加一个 io.Writer 实例

func (*Buffer) Flush

func (b *Buffer) Flush() 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)

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)

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() 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 Flusher

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

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)

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