• Stars
    star
    34
  • Rank 740,732 (Top 16 %)
  • Language
    Go
  • License
    MIT License
  • Created about 5 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Go file operations library chasing GNU APIs.

flop

GoDoc MIT license Mentioned in Awesome Go Go Report Card


flop aims to make copying files easier in Go, and is modeled after GNU cp. 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.

go get -u github.com/homedepot/flop

Usage

Basic file copy.

err := flop.SimpleCopy("src_path", "dst_path")
handle(err)

Advanced file copy with options.

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.

// 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)
}

More Repositories

1

spingo

A collection of Terraform and bash scripts to setup an enterprise-grade Spinnaker deployment on Google Cloud Platform
Shell
36
star
2

flow

Python
30
star
3

go-clouddriver

A rewrite of Spinnaker's Clouddriver microservice in Go
Go
27
star
4

infinite-wish-board

A platform for kids to make wishes at Make-A-Wish, GA.
JavaScript
27
star
5

github-webhook

GitHub WebHook deployable on CloudFoundry
Go
21
star
6

k8s-global-objects

Make kubernetes objects for each namespace
Go
13
star
7

github-webhook-resource

Concourse resource for remotely managing GitHub webhooks
JavaScript
11
star
8

hackathon-starter

Hackathon starter repository which provides a baseline react/node/mongo app with integrations
JavaScript
9
star
9

metREx

SQL query and monitoring system metrics exporter for Prometheus
Python
9
star
10

cf-rolling-restart

Perform a rolling restart of cloud foundry application instances.
Go
7
star
11

rspec_knees_and_toes

Ruby
4
star
12

newrelic-deploy-resource

A Concourse CI resource to mark a deploy in New Relic
Shell
4
star
13

simple_cups-handler

This is a basic node js app to monitor CUPS activity via an RSS subscription.
JavaScript
3
star
14

hubot-book-list

Book list manager for hubot
CoffeeScript
3
star
15

goel

A expression language parser supporting a subset of Go expressions.
Go
3
star
16

ScriptPortal

A web app to host command line scripts for the non-command line inclined
Go
3
star
17

cloud-runner

Service to Deploy to GCP Cloud Run
Go
3
star
18

trainer

An integration testing application with built-in mocking capability.
Go
2
star
19

react-component-grid

JavaScript
2
star
20

techtalkws

Groovy
1
star
21

opensource-corebeliefs

CSS
1
star
22

techtalk-ui

JavaScript
1
star
23

apialchemy

API toolkit for Python, modeled after SQLAlchemy
Python
1
star
24

homedepot.github.io

CSS
1
star
25

GoogleCloudLoggingPlugin

Jenkins plugin which can log job or pipeline statuses to Google BigQuery and/or Datastore
Java
1
star
26

cryptofy

Simple encryption/decryption functions for Python
Python
1
star
27

spin-observatory-plugin

TypeScript
1
star