Skip to content

Commit fa919b2

Browse files
authored
initial push from internal repo (#1)
1 parent c79c711 commit fa919b2

14 files changed

+1545
-0
lines changed

README.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# flop
2+
flop is a Golang file operations library concentrating on safety and feature parity with
3+
[GNU cp](https://www.gnu.org/software/coreutils/manual/html_node/cp-invocation.html).
4+
Most administrators and engineers interact with GNU utilities every day, so it makes sense to utilize
5+
that knowledge and expectations for a library that does the same operation in code. flop strategically
6+
diverges from cp where it is advantageous for the programmer to explicitly define the behavior, like
7+
cp assuming that copying from a file path to a directory path means the file should be created inside the directory.
8+
This behavior must be explicitly defined in flop by passing the option AppendNameToPath, otherwise
9+
an error will be returned.
10+
11+
### Usage
12+
Basic file copy.
13+
```go
14+
err := flop.SimpleCopy("src_path", "dst_path")
15+
handle(err)
16+
```
17+
18+
Advanced file copy with options.
19+
```go
20+
options := flop.Options{
21+
Recursive: true,
22+
MkdirAll: true,
23+
}
24+
err := flop.Copy("src_path", "dst_path", options)
25+
handle(err)
26+
```
27+
28+
### Logging
29+
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
30+
can help expose the behavior, or aid in debugging if you are generous enough to contribute.
31+
```go
32+
// the logger just takes a string so format your favorite logger to accept one
33+
import (
34+
"flop"
35+
"github.com/rs/zerolog"
36+
zlog "github.com/rs/zerolog/log"
37+
llog "github.com/sirupsen/logrus"
38+
)
39+
40+
func logDebug(msg string) {
41+
llog.WithFields(llog.Fields{
42+
"application": "stuffcopy",
43+
}).Info(msg)
44+
}
45+
46+
func main() {
47+
zlog.Logger = zlog.Output(zerolog.ConsoleWriter{Out: os.Stderr})
48+
err := flop.Copy(src.Name(), dst.Name(), flop.Options{
49+
InfoLogFunc: zlog.Info().Msg, // Msg already accepts a string so we can just pass it directly
50+
DebugLogFunc: logDebug, // logrus Debug takes ...interface{} so we need to wrap it
51+
})
52+
handle(err)
53+
}
54+
```

VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v0.1.3

0 commit comments

Comments
 (0)