fn

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2019 License: MIT Imports: 6 Imported by: 1

README

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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fn

type Fn struct {
	Prefix      string
	Postfix     string
	Delimiter   string
	GitShaSize  int
	ProcShaSize int
}

Fn in a file namer

func New

func New() *Fn

New creates a new Fn with default settings.

func (*Fn) Name

func (fn *Fn) Name() string

Name generates a file name (without file extension) based on the current settings

func (*Fn) NameWithFileType

func (fn *Fn) NameWithFileType(fType string) string

NameWithFileType is identical to `Name()`, except that it appends a file extension

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL