From abe7acffd453eb312613d8611780ae7a37c9d5f9 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Mon, 10 Mar 2025 13:46:13 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=A1=20Document=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- generators.go | 11 +++++++++++ options.go | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/generators.go b/generators.go index db2bce1..682c405 100644 --- a/generators.go +++ b/generators.go @@ -20,26 +20,34 @@ func uuidGen() (string, error) { return u.String(), nil } +// WithUUID sets a generator that creates a UUIDv4 func WithUUID() Option { return func(c *config) { setGenerator(c, uuidGen) } } +// FileTimestamp is the default format for WithTimestamp and WithTime const FileTimestamp string = "2006-01-02_03-05-06-0700" +// WithTimestamp sets a generator that creates a date and time for the current time. +// The format is FileStamp func WithTimestamp() Option { return WithTimestampFormat(FileTimestamp) } +// WithTimestampFormat sets a generator the creates a date and time for the current time with the supplied format. func WithTimestampFormat(f string) Option { return WithFormattedTime(time.Now(), f) } +// WithTime sets a generator that creates a date and time for the supplied time. +// The format is FileStamp func WithTime(t time.Time) Option { return WithFormattedTime(t, FileTimestamp) } +// WithFormattedTime sets a generator that creates a date and time for the supplied time with the supplied format. func WithFormattedTime(t time.Time, f string) Option { return func(c *config) { setGenerator(c, func() (string, error) { @@ -48,12 +56,15 @@ func WithFormattedTime(t time.Time, f string) Option { } } +// FileTimestamp is the default format for WithTimestampUTC and WithTimeUTC const FileTimestampNoTZ string = "2006-01-02_03-05-06" +// WithTimestampUTC sets a generator the creates a date and time for the current time in UTC without a timezone in the format. func WithTimestampUTC() Option { return WithTimeUTC(time.Now()) } +// WithTimeUTC sets a generate that creates a date and time for the supplied time in UTC without a timezone in the format. func WithTimeUTC(t time.Time) Option { return WithFormattedTime(t.UTC(), FileTimestampNoTZ) } diff --git a/options.go b/options.go index 6f122ce..e318446 100644 --- a/options.go +++ b/options.go @@ -17,32 +17,39 @@ func defaultConf() config { } } +// Option is an option for nomino type Option func(c *config) +// WithOriginal sets the original filename. +// This will be included in the generated name after the generated string and before the suffix. func WithOriginal(o string) Option { return func(c *config) { c.original = "_" + o } } +// WithPrefix sets a prefix for the generated name. func WithPrefix(p string) Option { return func(c *config) { c.prefix = p + "_" } } +// WithSuffix sets a suffix for the generated name. It will be included in the base name before the suffix. func WithSuffix(s string) Option { return func(c *config) { c.suffix = "_" + s } } +// WithoutExtension sets no extension for the generated filename. By default, it will be txt func WithoutExtension() Option { return func(c *config) { c.extension = "" } } +// WithExtension sets the extension for the generated filename. func WithExtension(ext string) Option { return func(c *config) { c.extension = "." + strings.TrimPrefix(ext, ".")