https://github.com/bcongdon/fn
Golang library for generating (mostly) unique date-sortable filenames
https://github.com/bcongdon/fn
Last synced: 10 months ago
JSON representation
Golang library for generating (mostly) unique date-sortable filenames
- Host: GitHub
- URL: https://github.com/bcongdon/fn
- Owner: bcongdon
- License: mit
- Created: 2019-02-20T01:27:17.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-23T14:58:29.000Z (almost 7 years ago)
- Last Synced: 2025-01-17T07:41:10.379Z (12 months ago)
- Language: Go
- Size: 12.7 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fn
[](https://travis-ci.org/bcongdon/fn)
[](https://godoc.org/github.com/bcongdon/fn)
[](https://goreportcard.com/report/github.com/bcongdon/fn)
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](https://github.com/inconvergent/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.
```go
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](https://inconvergent.net/)'s [fn](https://github.com/inconvergent/fn) Python package.