fswatcher

package module
v0.0.0-...-b89d3ad Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2018 License: MIT Imports: 8 Imported by: 0

README

FSWATCHER

Build Status Go Report Card GoDoc

A library to listen to the changes of File/Folder:

  • CREATE
  • REMOVE
  • RENAME
  • DELETE

Installation

go get github.com/raomuyang/fswatcher/iusync

Watcher

Listen for changes to files or directories.

  • Directory: All subfiles and subdirectories are recursively monitored (the file at initialization is not processed).
  • File: only listen for changes to this file, and stop listening when the file is deleted.
package exapmle
import (
	"github.com/raomuyang/fswatcher"
	"time"
)

func demo() {
	callable := fswatcher.Callable{
		OnCreate: onCreateFunc,
		OnRename: onRenameFunc,
		OnWrite:  onWriteFunc,
		OnRemove: onRemoveFunc,
	}

	dw, err := fswatcher.Watch("/path/to/target/", callable)
	defer dw.Stop()

	if err != nil {
		panic(err)
	}
	
	<-time.After(time.Minute * 10)
}

iusync

A tool for synchronizing local files to cloud storage in real time. When you use Markdown to write a blog, you can easily sync the local image of the image to the map bed and get the image link.

Usage
  • install iusync by golang (You can also download the compiled executable binary file from release.)
go get github.com/raomuyang/fswatcher/iusync
  • write config
store_type: qiniu # qiniu / oss
log_level: 5 # DEBUG(5) INFO(4) WARN(3) ERROR(2) FATAL(1) PANIC(0)
log_path: /path/to/save/log # specify the log path
scan_at_start: true # default false
include_hidden: true # default false
opt_delay: 3 # default 3 (seconds)
access:
  access_key_id: your_access_key_id
  access_key_secret: your_access_key_secret
  bucket: your_bucket_name
  domain: http://eg.xxx.cn # The bound custom domain name(to assemble a visible url)
  endpoint: xxx  # if the store type is qiniu, this section is optional
  • run
iusync -target=/path/to/target/folder/or/image [-conf=specify/conf/file]

Future

  • file hook

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callable

type Callable struct {
	// CREATE corresponding function
	OnCreate func(filePath string)
	// REMOVE corresponding function
	OnRemove func(filePath string)
	// WRITE corresponding function
	OnWrite func(filePath string)
	// RENAME corresponding function
	OnRename func(filePath string)
}

type DeepWatch

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

Listen for changes to files or directories. When the target is a directory, all subfiles and subdirectories are recursively monitored (the file at initialization is not processed). When the target is a file, only listen for changes to this file, and stop listening when the file is deleted.

func Watch

func Watch(path string, callable Callable) (dw DeepWatch, err error)

Start watch

func (DeepWatch) Stop

func (dw DeepWatch) Stop()

Stop all watchers

type DelayTrigger

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

通知到达时延迟执行,可以被打断

func NewDelayTrigger

func NewDelayTrigger(filePath string, delay int, callback func(filePath string)) DelayTrigger

func (DelayTrigger) AsyncDo

func (trigger DelayTrigger) AsyncDo()

异步执行

func (DelayTrigger) Interrupt

func (trigger DelayTrigger) Interrupt()

中断即将执行的动作

type Watcher

type Watcher struct {
	// target path to watch
	Path     string
	Callable Callable
	// contains filtered or unexported fields
}

The watcher of file/folder, listen to the changes of file or subitems

func (Watcher) Stop

func (watcher Watcher) Stop()

Stop the watch process

func (*Watcher) Watch

func (watcher *Watcher) Watch() error

Start the watch process in a new goroutine

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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