fresher

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2019 License: MIT Imports: 15 Imported by: 0

README

fresher Go Report Card Actions Status

※ Click here for the Japanese version

fresher is a hot reload tool that restarts the Go application when the group of monitored files changes.

This tool is a library that implements the minimum required functions at https://github.com/gravityblast/fresh and add some functions to monitor more efficiently and efficiently.

Developing for better-fresh.

Features

fresher supports the following features.

  • Features of https://github.com/gravityblast/fresh
  • Flexible setting of monitoring file
  • Execute Command before and after build
  • Support to set env and args for build
  • Build with local and run with docker, hot reload faster with docker

Install

go get github.com/kanataxa/fresher/cmd/fresher

Quick Start

1. Install CLI

go get github.com/kanataxa/fresher/cmd/fresher

2. Create YAML Config

touch your_config.yml

3. Edit YAML config

path:
  - .

4. Run fresher

fresher -c your_config.yml

FAQ

Where is the example?

See here for a simple example in _example.

Want to monitor or ignore files more closely

you can determine the files to be monitored in more detail by making two settings

  1. Set path finely
  2. Set exclude

Basically, the file to be monitored is determined from the configuration file according to the following rules.

  1. Starting from the directory described in path, recursively determine whether it is a file to be monitored

  2. If include is specified, only directories that are recursively viewed and files to be monitored should match those specified in include. If they match files set in exclude, Exclude from monitoring

  3. include / exclude does not distinguish between files and directories, and uses filepath.Match to monitor / exclude matches

If you want to ignore everything, exclude it with exclude. If you want to monitor / ignore specific files and directories in that directory, specify include / exclude in path.

The following is an example.

bash-3.2$ tree ./
./
├── fresher_config.yml
├── main.go
├── controller
│   ├── controller.go
│   └── const.go
├── model
│   ├── message.go
│   └── message_test.go
└── pkg
    ├── config.go
    ├── const.go
    ├── pkg.go
    └── utils
        ├── utils.go
        └── utils_test.go
path:
  - .
  - name: controller
    exclude:
      - const.go
  - model
  - name: pkg
    include:
      - utils*
      - config.go
exclude:
  - vendor
  - '*_test.go'

Want to build a high-speed hot reload environment using Docker For Mac

In case of CGO_ENABLED=0

Include the following settings in the build field, launch a docker container and execute fresher on the host side. GOOS and GOARCH need to be set when the host and container OS are different.

fresher cross-compiles and runs the binary in docker.

build:
  host:
    docker: container_name
  env:
    GOOS: linux
    GOARCH: amd64
In case of CGO_ENABLED=1

If you want to cross-compile binaries containing cgo, you need to prepare.

  1. Prepare c / c ++ compiler for cross compilation

  2. If the c source used for cgo uses an external library, compile with the compiler prepared in step 1 and prepare it as a static library

  3. Make the following settings in the configuration file

build:
  host:
    docker: container
  env:
    GOOS: linux
    GOARCH: amd64
    CC: /your/cross-compile-cc-compiler/path
    CXX: /your/cross-compile-cxx-compiler/path
    CGO_ENABLED: 1
    CGO_LDFLAGS:  /your/static/lib/libz.a
    CGO_CXXFLAGS: -I/your/header/path/include
  arg:
    - --ldflags
    - '-linkmode external -extldflags -static'

Bug reports and requests

Please create Issue in English or Japanese.

License

MIT

Documentation

Index

Constants

View Source
const (
	HostTypeLocal = iota
	HostTypeDocker
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ArgDecoder added in v0.0.3

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

func (*ArgDecoder) UnmarshalYAML added in v0.0.3

func (a *ArgDecoder) UnmarshalYAML(b []byte) error

type ArgDecoders added in v0.0.3

type ArgDecoders []*ArgDecoder

func (ArgDecoders) Argument added in v0.0.3

func (a ArgDecoders) Argument() []string

type BuildConfig

type BuildConfig struct {
	Target         string     `yaml:"target"`
	Host           *Host      `yaml:"host"`
	Output         string     `yaml:"output"`
	Environ        Environ    `yaml:"env"`
	Arg            []string   `yaml:"arg"`
	WithoutRun     bool       `yaml:"without_run"`
	BeforeCommands []*Command `yaml:"before"`
	AfterCommands  []*Command `yaml:"after"`
}

func (*BuildConfig) BuildCommand

func (bc *BuildConfig) BuildCommand() Executor

func (*BuildConfig) Commands

func (bc *BuildConfig) Commands() []Executor

func (*BuildConfig) RunCommand

func (bc *BuildConfig) RunCommand() Executor

func (*BuildConfig) UnmarshalYAML

func (bc *BuildConfig) UnmarshalYAML(b []byte) error

type Command

type Command struct {
	Name    string
	Arg     []string
	Environ []string
	IsAsync bool
	// contains filtered or unexported fields
}

func (*Command) Exec

func (c *Command) Exec() error

func (*Command) ExecContext

func (c *Command) ExecContext(ctx context.Context) error

func (*Command) Kill

func (c *Command) Kill() error

func (*Command) UnmarshalYAML

func (c *Command) UnmarshalYAML(b []byte) error

type Config

type Config struct {
	Build       *BuildConfig     `yaml:"build"`
	Paths       []*WatcherConfig `yaml:"path"`
	ExcludePath *GlobalExclude   `yaml:"exclude"`
	Extensions  Extensions       `yaml:"extension"`
	Interval    time.Duration    `yaml:"interval"`
}

func LoadConfig

func LoadConfig(filename string) (*Config, error)

func (*Config) Options

func (c *Config) Options() []OptionFunc

type DockerCommand

type DockerCommand struct {
	*Command
	// contains filtered or unexported fields
}

func (*DockerCommand) Exec

func (c *DockerCommand) Exec() error

func (*DockerCommand) ExecContext

func (c *DockerCommand) ExecContext(ctx context.Context) error

func (*DockerCommand) Kill

func (c *DockerCommand) Kill() error

type Environ

type Environ []string

func (*Environ) UnmarshalYAML

func (e *Environ) UnmarshalYAML(b []byte) error

type Executor

type Executor interface {
	Exec() error
	ExecContext(context.Context) error
	Kill() error
}

type Extensions

type Extensions []string

func (Extensions) IsIncludeSameExt

func (e Extensions) IsIncludeSameExt(fileName string) bool

type Fresher

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

func New

func New(fns ...OptionFunc) *Fresher

func (*Fresher) Watch

func (f *Fresher) Watch() error

type GlobalExclude

type GlobalExclude []string

func (GlobalExclude) IsExclude

func (g GlobalExclude) IsExclude(path string) (bool, error)

type Host

type Host struct {
	Type         hostType
	LocationName string
}

func (*Host) RunCommand

func (h *Host) RunCommand(path string) Executor

func (*Host) UnmarshalYAML

func (h *Host) UnmarshalYAML(b []byte) error

type Log

type Log struct {
	*logrus.Logger
}

func (*Log) Building

func (l *Log) Building()

func (*Log) Error

func (l *Log) Error(v interface{})

func (*Log) IgnoreFile

func (l *Log) IgnoreFile(path string)

func (*Log) Info

func (l *Log) Info(msg string)

func (*Log) UpdateFile

func (l *Log) UpdateFile(path string)

func (*Log) WatchFile

func (l *Log) WatchFile(path string)

type Option

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

type OptionFunc

type OptionFunc func(f *Fresher)

func ExecTarget

func ExecTarget(bc *BuildConfig) OptionFunc

func ExtensionPaths

func ExtensionPaths(exts Extensions) OptionFunc

func GlobalExcludePath

func GlobalExcludePath(global *GlobalExclude) OptionFunc

func WatchConfigs

func WatchConfigs(configs []*WatcherConfig) OptionFunc

func WatchInterval

func WatchInterval(interval time.Duration) OptionFunc

type WatcherConfig

type WatcherConfig struct {
	Name     string   `yaml:"name"`
	Excludes []string `yaml:"exclude"`
	Includes []string `yaml:"include"`
}

func (*WatcherConfig) IsExclude

func (r *WatcherConfig) IsExclude(path string) (bool, error)

func (*WatcherConfig) IsInclude

func (r *WatcherConfig) IsInclude(path string) (bool, error)

func (*WatcherConfig) ShouldWatchFile

func (r *WatcherConfig) ShouldWatchFile(path string, opt *Option) (bool, error)

func (*WatcherConfig) SkipDir

func (r *WatcherConfig) SkipDir(dirName string, opt *Option) (bool, error)

func (*WatcherConfig) UnmarshalYAML

func (r *WatcherConfig) UnmarshalYAML(b []byte) error

func (*WatcherConfig) Walk

func (r *WatcherConfig) Walk(watcher *fsnotify.Watcher, opt *Option) (*WatcherPath, error)

func (*WatcherConfig) WalkWithDirName

func (r *WatcherConfig) WalkWithDirName(watcher *fsnotify.Watcher, opt *Option, dirName string) (*WatcherPath, error)

type WatcherPath

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

func NewWatcherPath

func NewWatcherPath(wcs []*WatcherConfig, option *Option) *WatcherPath

func (*WatcherPath) AddIfNeeds

func (w *WatcherPath) AddIfNeeds(path string, watcher *fsnotify.Watcher) error

func (*WatcherPath) Merge

func (w *WatcherPath) Merge(wp *WatcherPath)

Directories

Path Synopsis
pkg
cmd

Jump to

Keyboard shortcuts

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