https://github.com/homedepot/flop
Go file operations library chasing GNU APIs.
https://github.com/homedepot/flop
Last synced: 9 months ago
JSON representation
Go file operations library chasing GNU APIs.
- Host: GitHub
- URL: https://github.com/homedepot/flop
- Owner: homedepot
- License: mit
- Created: 2019-03-01T13:41:39.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-12-07T15:59:35.000Z (almost 4 years ago)
- Last Synced: 2024-07-31T20:51:26.066Z (over 1 year ago)
- Language: Go
- Homepage:
- Size: 20 MB
- Stars: 33
- Watchers: 21
- Forks: 12
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - flop - File operations library which aims to mirror feature parity with [GNU cp](https://www.gnu.org/software/coreutils/manual/html_node/cp-invocation.html). (File Handling / Search and Analytic Databases)
- awesome-go - flop - invocation.html). | - | - | - | (Files / Advanced Console UIs)
- awesome-go-plus - flop - File operations library which aims to mirror feature parity with [GNU cp](https://www.gnu.org/software/coreutils/manual/html_node/cp-invocation.html).  (File Handling / Search and Analytic Databases)
- awesome-go-cn - flop - invoc.html)的镜像。 [![近三年未更新][Y]](https://github.com/homedepot/flop) [![godoc][D]](https://godoc.org/github.com/homedepot/flop) (文件处理 / 检索及分析资料库)
- awesome-go - flop - File operations library which aims to mirror feature parity with [GNU cp](https://www.gnu.org/software/coreutils/manual/html_node/cp-invocation.html). (File Handling / Search and Analytic Databases)
- awesome-go-with-stars - flop - File operations library which aims to mirror feature parity with [GNU cp](https://www.gnu.org/software/coreutils/manual/html_node/cp-invocation.html). (File Handling / Search and Analytic Databases)
- fucking-awesome-go - flop - File operations library which aims to mirror feature parity with 🌎 [GNU cp](www.gnu.org/software/coreutils/manual/html_node/cp-invocation.html). (File Handling / Search and Analytic Databases)
- awesome-go-cn - flop - invocation.html)进行镜像。 (文件处理 / SQL 查询语句构建库)
- awesome-go-extra - flop - 03-01T13:41:39Z|2021-12-07T15:59:35Z| (File Handling / Advanced Console UIs)
- awesome-go - flop - File operations library which aims to mirror feature parity with [GNU cp](https://www.gnu.org/software/coreutils/manual/html_node/cp-invocation.html). (File Handling / Search and Analytic Databases)
- awesome-go - flop - File operations library which aims to mirror feature parity with [GNU cp](https://www.gnu.org/software/coreutils/manual/html_node/cp-invocation.html). (File Handling / Search and Analytic Databases)
- awesome-go - flop - File operations library which aims to mirror feature parity with [GNU cp](https://www.gnu.org/software/coreutils/manual/html_node/cp-invocation.html). (File Handling / Search and Analytic Databases)
- awesome-Char - flop - File operations library which aims to mirror feature parity with [GNU cp](https://www.gnu.org/software/coreutils/manual/html_node/cp-invocation.html). (File Handling / Advanced Console UIs)
- awesome-go-cn - flop - invoc.html)的镜像。 [![godoc][D]](https://godoc.org/github.com/homedepot/flop) (文件处理 / 检索及分析资料库)
- awesome-go - flop - File operations library which aims to mirror feature parity with [GNU cp](https://www.gnu.org/software/coreutils/manual/html_node/cp-invocation.html). (Files / Advanced Console UIs)
README
# flop
[](https://godoc.org/github.com/homedepot/flop)
[](LICENSE)
[](https://github.com/avelino/awesome-go)
[](https://goreportcard.com/report/github.com/homedepot/flop)

----
flop aims to make copying files easier in Go, and is modeled after
[GNU cp](https://www.gnu.org/software/coreutils/manual/html_node/cp-invocation.html).
Most administrators and engineers interact with GNU utilities every day, so it makes sense to utilize
that knowledge and expectations for a library that does the same operation in code.
flop strategically diverges from cp where it is advantageous for the programmer to explicitly define the
behavior, like cp assuming that copying from a file path to a directory path means the file should be
created inside the directory. This behavior must be explicitly defined in flop by passing the option
AppendNameToPath, otherwise an error will be returned.
```BASH
go get -u github.com/homedepot/flop
```
## Usage
Basic file copy.
```go
err := flop.SimpleCopy("src_path", "dst_path")
handle(err)
```
Advanced file copy with [options](https://pkg.go.dev/github.com/homedepot/flop?tab=doc#Options).
```go
options := flop.Options{
Recursive: true,
MkdirAll: true,
}
err := flop.Copy("src_path", "dst_path", options)
handle(err)
```
## Logging
flop won't throw logs at you for no reason, but if you want to follow along with what's going on giving it a logger
can help expose the behavior, or aid in debugging if you are generous enough to contribute.
```go
// the logger just takes a string so format your favorite logger to accept one
import (
"github.com/homedepot/flop"
"github.com/rs/zerolog"
zlog "github.com/rs/zerolog/log"
llog "github.com/sirupsen/logrus"
)
func logDebug(msg string) {
llog.WithFields(llog.Fields{
"application": "stuffcopy",
}).Info(msg)
}
func main() {
zlog.Logger = zlog.Output(zerolog.ConsoleWriter{Out: os.Stderr})
err := flop.Copy(src.Name(), dst.Name(), flop.Options{
InfoLogFunc: zlog.Info().Msg, // Msg already accepts a string so we can just pass it directly
DebugLogFunc: logDebug, // logrus Debug takes ...interface{} so we need to wrap it
})
handle(err)
}
```