Find a file
2025-03-31 15:56:49 -05:00
.gitignore 🛠 Add Taskfile 2025-03-07 16:25:40 -06:00
.golangci.yaml 🛠 Replace all linting with golangci-lint 2025-03-19 17:48:23 -05:00
CHANGELOG.md 📝 Update CHANGELOG 2025-03-31 15:56:34 -05:00
config.go 💡 Fix a few go doc comments 2025-03-31 15:46:48 -05:00
config_test.go Config.AddOptions and Generator.MakeWithConfig 2025-03-18 09:22:30 -05:00
examples_test.go 💡 Add some helpful comments in example 2025-03-23 10:52:54 -05:00
gen_file.go 💡 Improve go doc comments with internal links 2025-03-31 12:10:05 -05:00
gen_file_examples_test.go ♻️ Replace HashType with Hasher 2025-03-15 20:09:38 -05:00
gen_file_test.go ♻️ Replace HashType with Hasher 2025-03-15 20:09:38 -05:00
gen_int.go 💡 Improve go doc comments with internal links 2025-03-31 12:10:05 -05:00
gen_int_examples_test.go ♻️ Refactor Incremental Generator to single function with options 2025-03-14 19:03:22 -05:00
gen_rand.go 💡 Fix a few go doc comments 2025-03-31 15:46:48 -05:00
gen_rand_examples_test.go ♻️ Modify UUID to allow for other versions. 2025-03-16 12:38:36 -05:00
gen_rand_test.go 🚨 A bunch of small improvements from linter 2025-03-19 18:05:16 -05:00
gen_ts.go 💡 Improve go doc comments with internal links 2025-03-31 12:10:05 -05:00
gen_ts_examples_test.go 📝 Redo ts examples to use gen.Make 2025-03-16 15:56:31 -05:00
gen_ts_test.go ♻️ Refactor Timestamp Generator to single function with options 2025-03-14 17:39:42 -05:00
generators.go 💡 Fix a few go doc comments 2025-03-31 15:46:48 -05:00
generators_examples_test.go 🚨 A bunch of small improvements from linter 2025-03-19 18:05:16 -05:00
generators_test.go 🚨 A bunch of small improvements from linter 2025-03-19 18:05:16 -05:00
go.mod Add Random Generator 2025-03-15 15:36:43 -05:00
go.sum Add Random Generator 2025-03-15 15:36:43 -05:00
LICENSE 🔖 Version 0.0.1 2025-03-10 17:03:52 -05:00
make.go 💡 Fix some doc blocks 2025-03-15 15:35:40 -05:00
make_examples_test.go Add extra Options to Make 2025-03-14 21:46:30 -05:00
make_test.go 🚨 A bunch of small improvements from linter 2025-03-19 18:05:16 -05:00
nomino.go 💡 Improve go doc comments with internal links 2025-03-31 12:10:05 -05:00
options.go 💡 Improve go doc comments with internal links 2025-03-31 12:10:05 -05:00
options_examples_test.go Examples for everything 2025-03-14 21:22:29 -05:00
README.md 📝 Add one more link to README 2025-03-31 15:52:10 -05:00
Taskfile.yml 🛠 Replace all linting with golangci-lint 2025-03-19 17:48:23 -05:00

nomino - A filename generator

The purpose of nomino is to generate (probably random) filenames, for example, if you want to save an uploaded file to storage under a new name.

It takes a lot of inspiration (although no actual code) from Onym.

Make sure to check out the official documentation.

Installation

Add codeberg.org/danjones000/nomino to your project. You can do go get codeberg.org/danjones000/nomino, or simply add it to an import and run go mod tidy.

But, you probably already know this.

Usage

There are a lot of examples in the official documentation. Take a look through these to get an idea.

The main concept in nomino is the Generator. The simplest way to generate a random filename, is to use the Generator directly, in this way:

import (
    "fmt"
    "codeberg.org/danjones000/nomino"
)

func main() {
    name, _ := nomino.Random().Make()
    fmt.Println(name) // Du3Sfh8p.txt
}

The second argument is an error. Most of the generators are always successful, and that error will be nil, but you should check the errors if you're not sure.

The second way to generate a new filename is using the Make function.

import (
    "fmt"
    "codeberg.org/danjones000/nomino"
)

func main() {
    config := nomino.NewConfig(nomino.WithGenerator(nomino.Random()))
    name, _ := nomino.Make(config)
    fmt.Println(name) // Du3Sfh8p.txt
}

Although in these examples, nomino.Make is more verbose, it can be beneficial to using that function if you have some customizations to how you generate the filenames.

Configuration

The Config allows you to customize how the generated filename works with various Options. The options allows you to customize things like adding a prefix, or changing the extension of the generated filename (by default, it uses .txt).

Have a look at all the Options.

Generator

The Generator is the piece that returns the "random" portion of the generated filename, although, it doesn't actually have to be random.

Here are the built-in Generators:

  • UUID generates a UUID. This is the default if none is specified.
  • Random generates a random string. By default, it's 8 characters long, but can be whatever length you provide.
  • Incremental will generate just a series of integers, starting at 0.
  • Timestamp generates a string from the current time. It will look like "2009-11-10T23-00-00+0000.txt", although this can be customized.
  • Both Slug and Hash work on the original name provided by WithOriginal. Slug generats a slug from the name, while Hash hashes it. By default, it uses MD5.

You can also use multiple generators, either in order, or in a random order.

Finally, you can create a custom generator as well.

RTFM (Read the fabulous manual)

Official docs, especially the examples. Especially check out the full example, which includes how to use a global configuration.