watch

package
v3.7.17 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: Apache-2.0 Imports: 14 Imported by: 1

Documentation

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 GoVersion added in v3.2.18

func GoVersion() (string, error)

GoVersion 返回本地 Go 的版本信息

func Watch added in v3.2.18

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

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

Types

type Flags added in v3.2.18

type Flags map[string]string

type Logger added in v3.2.18

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

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

func NewConsoleLogger added in v3.2.18

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

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

type Options added in v3.2.18

type Options struct {

	// 日志输出对象
	//
	// 如为空,则被初始化 *ConsoleLogger 对象。
	Logger Logger

	// 在 go.mod 发生变化自动运行 go mod tidy
	AutoTidy bool

	// 指定编译的文件
	//
	// 为 go build 最后的文件参数,可以为空,表示当前目录。
	MainFiles string

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

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

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

	// 忽略的文件
	//
	// 采用 [path.Match] 作为匹配方式。
	Excludes []string

	// 传递给编译成功后的程序的参数
	AppArgs string

	// 是否监视子目录
	Recursive bool

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

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

Options 热编译的选项

Jump to

Keyboard shortcuts

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