Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

fn

Build Status GoDoc Go Report Card

Golang library for generating (mostly) unique date-sortable filenames

Installation

Via go get:

go get github.com/bcongdon/fn

Via Go modules: Add the following to your go.mod file

github.com/bcongdon/fn v0.0.1

Usage

As per inconvergent's fn, the formatting of file names is as follows:

yyyymmdd-hhmmss-gitsha-procdatetimesha

The first 2 chunks are the current date (day and time), the 3rd chunk is the hash of the current git commit, and the 4th chunk is the hash of the current process ID and time.

Optionally, a prefix/postfix can be added to the names by setting the Prefix and Postfix fields of Fn, respectively.

fNamer := fn.New()

// Basic Name
fmt.Println(fNamer.Name())
// "200260220-072532-392d644-6193ecb1"

// Name w/ Prefix
fNamer.Prefix = "foo"
fmt.Println(fNamer.Name())
// "foo-200260220-072532-392d644-4dffcc5b"

// Name w/ Postfix
fNamer.Postfix = "bar"
fNamer.Prefix = ""
fmt.Println(fNamer.Name())
// "200260220-072532-392d644-c25334f9-bar"

// Name w/ file extension
fNamer.Postfix = ""
fmt.Println(fNamer.NameWithFileType("png"))
// "200260220-072532-392d644-a165c554.png"

A full example lives in the examples/ directory.

Attribution

This library is more-or-less a direct port of inconvergent's fn Python package.

About

Golang library for generating (mostly) unique date-sortable filenames

Resources

License

Packages

No packages published

Languages

You can’t perform that action at this time.