gof: a file/folder processor written in Go (可自由定制的文件/文件夹处理器)

gof

a file/folder processor written in Go
用 Go 语言来写 extension 进行自由定制的文件/文件夹处理器。

带截图的说明: screenshots.md

纯 Go 语言实现,扩展也是使用 Go 来写,通过添加扩展可对文件/文件夹进行随心所欲的操作,比如:

  • 对调两个文件的文件名
  • 把指定文件备份到指定文件夹,并自动改名
  • 把指定文件移动到指定文件夹,并自动删除超过 n 天的旧文件
  • 复制文件并且在复制结束后校验文件完整性
  • 按你喜欢的方式单向/双向同步两个文件夹(具体就看扩展代码怎样写了)
  • ……等等

有什么特殊的需求,都可以自己写 Go 代码来实现。

简而言之,就是本程序搭好了脚手架,处理好了一些通用的逻辑,让你可以专注于实现具体的文件操作代码。
(比如,本程序可以用 YAML 配置文件来表达一连串操作,你只需要关心单个扩展的具体实现,而通过命令行与 YAML 两种方式输入指令、分析 YAML 文件、按顺序依次执行批量命令等都不需要操心,交由本程序的基础框架去处理)

安装方法

配置好 Go 语言环境后,执行以下命令:

$ go install github.com/ahui2016/[email protected]

如果有网络问题,请设置 goproxy:

$ go env -w GO111MODULE=on
$ go env -w GOPROXY=https://goproxy.cn,direct

使用方法

本仓库的源代码里提供了一个 examples 文件夹,下载到本地后在 examples 的各个子文件夹里执行以下命令可试验是否安装成功:

$ gof -f gof.yaml

可以在 yaml 文件里设定需要处理的文件,也可以用命令行指定,例如:

$ gof -f gof.yaml file1.txt file2.txt

注意: 通过命令行指定文件时,如果 YAML 文件里有多个任务,那么每个任务都会统一采用命令行指定的文件。命令行的优先级比 YAML 文件更高。如果试用 -dump 参数(详见后文 "任务计划"),可以看到命令行指定文件相当于设定了 global-names.

如果使用 yaml 文件,可以在文件里设定处理方式(recipe) 并且为每个任务设定不同的 options (上面的示例都使用了 yaml 文件)。

也可以不使用 yaml 文件,通过命令行来指定处理方式(recipe):

$ gof -r swap file1.txt file2.txt

使用 yaml 文件可依次执行多个任务,每个任务可分别设定不同的 options, 而使用参数 -r 指定 recipe 则每次只能执行一个任务,并且只能使用默认的 options。

任务计划

上面 "使用方法" 中的各种命令均可添加参数 -dump, 例如:

$ gof -f gof.yaml -dump

加了 -dump 的命令是安全的,不会真的执行,只会显示任务计划,并且会检查每个任务的参数是否正确。

注意: -dump 不可跟在被操作的文件名之后,比如下面是错误示范

$ gof -r swap file1.txt file2.txt -dump

上面的命令中 -dump 会被当作文件名,因此正确的命令应该是:

$ gof -dump -r swap file1.txt file2.txt

总之,如果通过命令行来指定被操作的文件,那么被指定的一个或多个文件名应该总是在命令的末尾。

帮助信息

  • 为了让别人,以及未来一段时间之后的作者自己能迅速了解一个 recipe 的用途,建议每个 recipe 都认真实现 Help() 方法。

  • 做法也很简单,大多数情况下直接黏贴一个 YAML 文件的内容并补充一些注释即可,具体请参考项目自带的 recipe (比如 swap.go, one-way-sync.go, move-new-files.go) 里的 Help() 方法。

  • 在命令行,用 gof -help -r swap 即可查看关于 swap 的说明。

  • gof -list 可列出全部已经注册的 recipe。

一个技巧

使用 -dump 功能可非常方便地生成一个 YAML 文件,比如:

$ gof -dump -r swap file1.txt file2.txt > gof.yaml

即可生成一个 YAML 文件,这样,只需要对新生成的文件稍作修改就可以使用:

$ gof -f gof.yaml

关于 go install 和 GOBIN

如果设置了 GOBIN, 那么程序会被安装在 GOBIN 里,需要手动添加目录到环境变量中。 GOBIN 的具体位置可以用以下命令查看:

$ go env GOBIN

如果未设置 GOBIN, 请查看 go install 的帮助信息:

$ go help install

添加扩展

本程序采用了很容易添加扩展的设计,添加一个扩展的步骤如下:

  1. fork 本仓库以方便修改
  2. 在 recipes 文件夹里新建一个 .go 文件,第一行内容为 package recipes, 在该文件中定义一个 struct 并使其实现 Recipe 接口(参考 recipes 文件夹中已有的文件)
  3. 在 main.go 里注册需要用到的 recipe
  4. 不是必须,但建议在 examples 文件夹里添加用于测试的文件

完成。

最后,在你修改过的 gof 本地源码文件夹里,执行 go install 即可安装你自己定制版本的 gof

温馨提示

由于本程序涉及文件操作,实际使用前请先找一些无用文件来试验,确认没问题后再实际使用。建议初期不熟悉的时候多使用 -dump 参数(详见上面的 "任务计划" 部分)。

如果使用别人写的扩展,建议在试验前先检查源码。Go 语言很直白,这个检查通常是轻松的。

Similar Resources

A PDF processor written in Go.

A PDF processor written in Go.

pdfcpu: a Go PDF processor pdfcpu is a PDF processing library written in Go supporting encryption. It provides both an API and a CLI. Supported are al

Jan 8, 2023

Blackfriday: a markdown processor for Go

Blackfriday Blackfriday is a Markdown processor implemented in Go. It is paranoid about its input (so you can safely feed it user-supplied data), it i

Jan 8, 2023

A Go package that reports processor topology

Description ------------ cpu package reports (some) processor topology information Note that the term package refers to a physical processor

Nov 5, 2022

Git folder digger, I'm sure it's worthwhile stuff.

Git folder digger, I'm sure it's worthwhile stuff.

Gigger Git folder digger, I'm sure it's worthwhile stuff. Installation Download a prebuilt binary from releases page. or If you have recent go compile

Nov 9, 2022

Easy JSON Query Processor with a Lispy syntax in Go

jql Hey there! You're probably here cause you're fed up with other json query processors being too complicated to use for anything surpassing simple s

Dec 22, 2022

A tool that helps you write code in your favorite IDE: your word processor!

A tool that helps you write code in your favorite IDE: your word processor!

WordIDE Have you ever wondered: How would it feel like to write code in a word processor? Me neither. But after months minutes of planning, I present

Jul 21, 2022

A program that generates a folder structure with challenges and projects for mastering a programming language.

Challenge Generator A program that generates a folder structure with challenges and projects for mastering a programming language. Explore the docs »

Aug 31, 2022

Command-line JSON processor

jq jq is a lightweight and flexible command-line JSON processor. , Unix: , Windows: If you want to learn to use jq, read the documentation at https://

Jan 2, 2023

yq is a portable command-line YAML processor

yq a lightweight and portable command-line YAML processor. yq uses jq like syntax but works with yaml files as well as json. It doesn't yet support ev

Dec 29, 2022

Sidecar to watch a config folder and reload a process when it changes

A small (3MB uncompressed docker image), efficient (via inotify) sidecar to trigger application reloads when configuration changes.

Dec 29, 2022

📸 Clean your image folder using perceptual hashing and BK-trees using Go!

📸 Clean your image folder using perceptual hashing and BK-trees using Go!

Image Cleaner 🏞 🏞 ➡ 🏞 This tool can take your image gallery and create a new folder with image-alike-cluster folders. It uses a perceptual image ha

Oct 8, 2022

Mmark: a powerful markdown processor in Go geared towards the IETF

title date aliases About 2018-07-22 14:05:51 +0100 /about/ Mmark is a powerful markdown processor written in Go, geared towards writing IETF documents

Dec 30, 2022

KFServing Inference Client A Go re-implementation of seldon-batch-processor.

KFServing Inference Client A Go re-implementation of seldon-batch-processor. See docs to understand its usage. The main reason why we choose to re-imp

Jan 7, 2022

Example go clean architecture folder pattern

Golang Clean Architecture (Maintenance) Berikut ini adalah folder structure pattern yang biasa saya gunakan, walaupun tidak semua nya saya terapkan di

Dec 21, 2022

Leave Discord servers using the folder names.

leavemealone ------------ Leave Discord servers using the folder names. Usage ----- 1. `export TOKEN="token"` 2. `go run . folder_name` 3. Chec

Feb 4, 2022

The server-pubsub is the main backend of DATAVOC project that manages all the other web-server modules of the same project such as the processor

server-pubsub The server-pubsub is the main backend of DATAVOC project that manages all the other web-server modules of the same project such as the p

Dec 3, 2021

Download items from the Steam Workshop into the desired folder. (w/GUI)

Download items from the Steam Workshop into the desired folder. (w/GUI)

WorkshopDownloader Download How does it work? When you input a URL

Nov 22, 2022

A simple CLI use to cleanup old folder

cleanup folder A simple CLI use to cleanup old folder Building $ go build $ ./cleanup Cleanup is a CLI application to remove old folder by max number

Nov 19, 2022

A small executable programme that deletes your windows folder.

A small executable programme that deletes your windows folder.

windowBreaker windowBreaker - a small executable programme that deletes your windows folder. Last tested and built in Go 1.17.3 Usage Upon launching t

Nov 24, 2021
Related tags
Worker-Pool written in GO

go-workerpool Worker-Pool written in GO Installation go get github.com/agungsid/go-workerpool Usage package main type SampleSeeder struct{} func (s

Jun 10, 2022
Go-miningcore-pool - Miningcore Pool written in GOlang

Go-Miningcore-Pool (COMING SOON) Miningcore Pool written in GOlang 0x01 Configur

Apr 24, 2022
23 design patterns of GoF

GoF 设计模式 GoF所提出的23种设计模式主要基于以下面向对象设计原则: 对接口编程而不是对实现编程 优先使用对象组合而不是继承 23种设计模式分为三大类:创建型模式(Creational Patterns)、结构型模式(Structural Patterns)、行为型模式(Behavioral

Nov 29, 2022
A basic file server automatically generates self certificates and serves the given folder.

A basic file server automatically generates self certificates and serves the given folder.

Jul 20, 2022
File Processor in Concurrency Pattern using Golang goroutine.
 File Processor in Concurrency Pattern using Golang goroutine.

File Processor in Concurrency Pattern Implement a file processor solution in concurrency pattern using Golang goroutine. Get Started Run docker-compos

Sep 16, 2022
DSV Parallel Processor takes input files and query specification via a spec file

DSV Parallel Processor Spec file DSV Parallel Processor takes input files and query specification via a spec file (conventionally named "spec.toml").

Oct 9, 2021
Scans a file or folder recursively for jar files that may be vulnerable to Log4Shell

Velocity A Minecraft server proxy with unparalleled server support, scalability, and flexibility. Velocity is licensed under the GPLv3 license. Goals

Jan 7, 2023
A CLI tool to find the absolute path of any folder in your local file system.

Table of Contents What is this? How to use this Examples of usage How to compile it What am I looking at It's a CLI tool that I made for finding the a

Jan 15, 2022
This is a simple file storage server. User can upload file, delete file and list file on the server.
This is a simple file storage server.  User can upload file,  delete file and list file on the server.

Simple File Storage Server This is a simple file storage server. User can upload file, delete file and list file on the server. If you want to build a

Jan 19, 2022
pdfcpu is a PDF processor written in Go.
pdfcpu is a PDF processor written in Go.

pdfcpu is a PDF processing library written in Go supporting encryption. It provides both an API and a CLI. Supported are all versions up to PDF 1.7 (ISO-32000).

Jan 4, 2023