github.com/saymoon/flop@v0.1.6-0.20201205092451-00912199cc96/README.md (about) 1 # flop 2 3 [![GoDoc](https://godoc.org/github.com/homedepot/flop?status.svg)](https://godoc.org/github.com/homedepot/flop) 4 [![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE) 5 [![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go) 6 [![Go Report Card](https://goreportcard.com/badge/github.com/homedepot/flop)](https://goreportcard.com/report/github.com/homedepot/flop) 7 8 <img src="https://github.com/homedepot/flop/raw/master/doc/logo.png" width="200" title="design based on original gopher by Renee French"> 9 10 ---- 11 12 flop is a Golang file operations library concentrating on safety and feature parity with 13 [GNU cp](https://www.gnu.org/software/coreutils/manual/html_node/cp-invocation.html). 14 Most administrators and engineers interact with GNU utilities every day, so it makes sense to utilize 15 that knowledge and expectations for a library that does the same operation in code. flop strategically 16 diverges from cp where it is advantageous for the programmer to explicitly define the behavior, like 17 cp assuming that copying from a file path to a directory path means the file should be created inside the directory. 18 This behavior must be explicitly defined in flop by passing the option AppendNameToPath, otherwise 19 an error will be returned. 20 21 ``` 22 go get -u github.com/homedepot/flop 23 ``` 24 25 ### Usage 26 Basic file copy. 27 ```go 28 err := flop.SimpleCopy("src_path", "dst_path") 29 handle(err) 30 ``` 31 32 Advanced file copy with [options](https://pkg.go.dev/github.com/homedepot/flop?tab=doc#Options). 33 ```go 34 options := flop.Options{ 35 Recursive: true, 36 MkdirAll: true, 37 } 38 err := flop.Copy("src_path", "dst_path", options) 39 handle(err) 40 ``` 41 42 ### Logging 43 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 44 can help expose the behavior, or aid in debugging if you are generous enough to contribute. 45 ```go 46 // the logger just takes a string so format your favorite logger to accept one 47 import ( 48 "github.com/homedepot/flop" 49 "github.com/rs/zerolog" 50 zlog "github.com/rs/zerolog/log" 51 llog "github.com/sirupsen/logrus" 52 ) 53 54 func logDebug(msg string) { 55 llog.WithFields(llog.Fields{ 56 "application": "stuffcopy", 57 }).Info(msg) 58 } 59 60 func main() { 61 zlog.Logger = zlog.Output(zerolog.ConsoleWriter{Out: os.Stderr}) 62 err := flop.Copy(src.Name(), dst.Name(), flop.Options{ 63 InfoLogFunc: zlog.Info().Msg, // Msg already accepts a string so we can just pass it directly 64 DebugLogFunc: logDebug, // logrus Debug takes ...interface{} so we need to wrap it 65 }) 66 handle(err) 67 } 68 ```