nomino/options.go

58 lines
1.2 KiB
Go
Raw Normal View History

2025-03-07 16:26:24 -06:00
package nomino
import "strings"
type config struct {
original string
prefix string
suffix string
extension string
generator Generator
2025-03-07 16:26:24 -06:00
}
func defaultConf() config {
return config{
extension: ".txt",
2025-03-07 17:00:38 -06:00
generator: uuidGen,
2025-03-07 16:26:24 -06:00
}
}
2025-03-10 13:46:13 -05:00
// Option is an option for nomino
2025-03-07 16:26:24 -06:00
type Option func(c *config)
2025-03-10 13:46:13 -05:00
// WithOriginal sets the original filename.
// This will be included in the generated name after the generated string and before the suffix.
2025-03-07 16:26:24 -06:00
func WithOriginal(o string) Option {
return func(c *config) {
c.original = "_" + o
}
}
2025-03-10 13:46:13 -05:00
// WithPrefix sets a prefix for the generated name.
2025-03-07 16:26:24 -06:00
func WithPrefix(p string) Option {
return func(c *config) {
c.prefix = p + "_"
}
}
2025-03-10 13:46:13 -05:00
// WithSuffix sets a suffix for the generated name. It will be included in the base name before the suffix.
2025-03-07 16:26:24 -06:00
func WithSuffix(s string) Option {
return func(c *config) {
c.suffix = "_" + s
}
}
2025-03-10 13:46:13 -05:00
// WithoutExtension sets no extension for the generated filename. By default, it will be txt
2025-03-07 16:26:24 -06:00
func WithoutExtension() Option {
return func(c *config) {
c.extension = ""
}
}
2025-03-10 13:46:13 -05:00
// WithExtension sets the extension for the generated filename.
2025-03-07 16:26:24 -06:00
func WithExtension(ext string) Option {
return func(c *config) {
c.extension = "." + strings.TrimPrefix(ext, ".")
}
}