✨ Add time-based generators
This commit is contained in:
parent
0fc4369679
commit
ee627547a8
3 changed files with 45 additions and 2 deletions
|
|
@ -1,9 +1,13 @@
|
|||
package nomino
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type generator func() (string, error)
|
||||
|
||||
func setGenerator(c *config, g generator) {
|
||||
c.generator = g
|
||||
}
|
||||
|
|
@ -21,3 +25,25 @@ func WithUUID() Option {
|
|||
setGenerator(c, uuidGen)
|
||||
}
|
||||
}
|
||||
|
||||
const FileTimestamp string = "2006-01-02_03-05-06-0700"
|
||||
|
||||
func WithTimestamp() Option {
|
||||
return WithTimestampFormat(FileTimestamp)
|
||||
}
|
||||
|
||||
func WithTimestampFormat(f string) Option {
|
||||
return WithFormattedTime(time.Now(), f)
|
||||
}
|
||||
|
||||
func WithTime(t time.Time) Option {
|
||||
return WithFormattedTime(t, FileTimestamp)
|
||||
}
|
||||
|
||||
func WithFormattedTime(t time.Time, f string) Option {
|
||||
return func(c *config) {
|
||||
setGenerator(c, func() (string, error) {
|
||||
return t.Format(f), nil
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue