watch

package
v1.7.5 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: MIT Imports: 16 Imported by: 1

Documentation

Overview

Package watch 监视文件变化并编译

Index

Constants

View Source
const (
	System = "system" // gobuild 系统信息
	Go     = "go"     // go 编译器的信息
	App    = "app"    // 被编译程序的信息
)

日志类型

View Source
const (
	Success int8 = iota
	Info
	Warn
	Error
	Ignore // 默认情况下被忽略的信息,一般内容比较多,且价值不高的内容会显示在此通道。
)
View Source
const MinWatcherFrequency = time.Second

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

Variables

This section is empty.

Functions

func Watch

func Watch(ctx context.Context, p *message.Printer, l Logger, opt *Options) error

Watch 执行热编译服务

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

Types

type Logger added in v1.1.0

type Logger interface {
	// Output 输出日志内容
	//
	// source 表示信息来源;
	// t 表示信息类型;
	Output(source string, t int8, message string)
}

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

func NewConsoleLogger added in v1.1.0

func NewConsoleLogger(showIgnore bool, out io.Writer, colors map[int8]colors.Color, sources map[string]string) Logger

NewConsoleLogger 将日志输出到控制台的 Logger 实现

colors 表示各类日志的颜色值; sources 表示各类信息源的名称; colors 和 prefixes 可以为 nil,会采用默认值。

type Options

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

	// 指定编译的文件
	//
	// 为 go build 最后的文件参数,可以为空,表示当前目录。
	//
	// 同时也会根据此值查找 go.mod 的项目根目录。
	MainFiles string `xml:"main,omitempty" json:"main,omitempty" yaml:"main,omitempty"`

	// 传递给编译器的参数
	//
	// 即传递给 go build 命令的参数,但是不应该包含 -o 等参数
	Args []string `xml:"args,omitempty" json:"args,omitempty" yaml:"args,omitempty"`

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

	// 忽略的文件
	//
	// 采用 [path.Match] 作为匹配方式。_test.go 始终被忽略,不需要在此指定。默认为空。
	Excludes []string `xml:"excludes>glob,omitempty" json:"excludes,omitempty" yaml:"excludes,omitempty"`

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

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

Options 热编译的选项

Jump to

Keyboard shortcuts

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