watch

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2022 License: MIT Imports: 15 Imported by: 1

Documentation

Overview

Package watch 监视文件变化并编译

Index

Constants

View Source
const (
	LogTypeSuccess int8 = iota
	LogTypeInfo
	LogTypeWarn
	LogTypeError
	LogTypeIgnore // 默认情况下被忽略的信息,一般内容比较多,且价格不高的内容会显示在此通道。
	LogTypeApp    // 被编译程序返回的信息
	LogTypeGo     // Go 编译器返回的信息
)

日志类型

View Source
const MinWatcherFrequency = 1 * time.Second

MinWatcherFrequency 监视器更新频率的最小值

Variables

This section is empty.

Functions

func Watch

func Watch(ctx context.Context, opt *Options) error

Watch 执行热编译服务

如果初始化参数有误,则反错误信息,如果是编译过程中出错,将直接将错误内容输出到 logs。

Types

type Flags

type Flags map[string]string

func (Flags) MarshalXML

func (f Flags) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*Flags) UnmarshalXML

func (f *Flags) UnmarshalXML(d *xml.Decoder, s xml.StartElement) error

type Logger added in v1.1.0

type Logger interface {
	// Output 输出日志内容
	//
	// t 表示日志类型,一般表示日志的重要程度或是日志的来源信息。
	Output(t int8, message string)
}

Logger 热编译过程中的日志接收对象

func NewConsoleLogger added in v1.1.0

func NewConsoleLogger(showIgnore bool, err, out io.Writer) Logger

NewConsoleLogger 返回将日志输出到控制台的 Logger 接口实现

type Options

type Options struct {
	XMLName struct{} `xml:"gobuild" json:"-" yaml:"-"`

	// 指定本地化的输出对象
	//
	// 如果为空,表示原样输出,不具备本地化的功能。
	Printer *message.Printer `xml:"-" json:"-" yaml:"-"`

	// 日志输出对象
	//
	// 如为空,则被初始化 *ConsoleLogger 对象。
	Logger Logger `xml:"-" json:"-" yaml:"-"`

	// 在 go.mod 发生变化自动运行 go mod tidy
	AutoTidy bool `xml:"tidy,omitempty" json:"tidy,omitempty" yaml:"tidy,omitempty"`

	// 指定编译的文件
	//
	// 为 go build 最后的文件参数,可以为空,表示当前目录。
	MainFiles string `xml:"main,omitempty" json:"main,omitempty" yaml:"main,omitempty"`

	// 指定可执行文件输出的文件路径
	//
	// 为空表示默认值,若不带路径信息,会附加在 Dirs 的第一个路径上;
	//
	// windows 系统无须指定 .exe 扩展名,会自行添加。
	//
	// 如果带路径信息,则会使用该文件所在目录作为工作目录。
	OutputName string `xml:"output,omitempty" json:"output,omitempty" yaml:"output,omitempty"`

	// 传递各个工具的参数
	//
	// 大致有以下几个,具体可参考 go build 的 xxflags 系列参数。
	//  - asm   --> asmflags
	//  - gccgo --> gccgoflags
	//  - gc    --> gcflags
	//  - ld    --> ldflags
	Flags Flags `xml:"flags,omitempty" json:"flags,omitempty" yaml:"flags,omitempty"`

	// 指定监视的文件扩展名
	//
	// 为空表示不监视任何文件,如果指定了 *,表示所有文件类型,包括没有扩展名的文件。
	Exts []string `xml:"exts,omitempty" json:"exts,omitempty" yaml:"exts,omitempty"`

	// 忽略的文件
	//
	// 采用 [path.Match] 作为匹配方式。
	Excludes []string `xml:"excludes>glob,omitempty" json:"excludes,omitempty" yaml:"excludes,omitempty"`

	// 传递给编译成功后的程序的参数
	AppArgs string `xml:"args,omitempty" yaml:"args,omitempty" json:"args,omitempty"`

	// 是否监视子目录
	Recursive bool `xml:"recursive,omitempty" yaml:"recursive,omitempty" json:"recursive,omitempty"`

	// 表示需要监视的目录
	//
	// 至少指定一个目录,第一个目录被当作主目录,将编译其下的文件作为执行主体。
	// 如果你在 go.mod 中设置了 replace 或是更高级的 workspace 中有相关设置,
	// 可以在此处指定这些需要跟踪的包。
	//
	// 如果 OutputName 中未指定目录的话,第一个目录会被当作工作目录使用。
	Dirs []string `xml:"dirs,omitempty" yaml:"dirs,omitempty" json:"dirs,omitempty"`

	// 监视器的更新频率
	//
	// 只有文件更新的时长超过此值,才会被定义为更新。防止文件频繁修改导致的频繁编译调用。
	//
	// 此值不能小于 [MinWatcherFrequency]。
	//
	// 默认值为 [MinWatcherFrequency]。
	WatcherFrequency time.Duration `xml:"freq,omitempty" yaml:"freq,omitempty" json:"freq,omitempty"`
	// contains filtered or unexported fields
}

Options 热编译的选项

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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