Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DupName ¶
type DupName struct {
// contains filtered or unexported fields
}
func NewDupName ¶
func NewDupName[T any]( newNamer func(string) Namer, entries []T, freeze bool, pickName func(T) string, ) *DupName
The entries parameter exists to ensure that the non-duplicative values contained in entries are not changed.
Example:
// If a directory contains "foo.txt" ... path := "path/to/the/directory" entries, _ := os.ReadDir(path) pick: = func(x os.DirEntry) string { return x.Name() } // freeze parameter is set to 'false', nameA is "foo.txt" and nameB is "foo(2).txt". dupName := NewDupName(NewNumberedName, entries, false, pick) nameA, _ := dupName.Rename("foo.txt") nameB, _ := dupName.Rename("foo.txt") // freeze parameter is set to 'true', nameC is "foo(2).txt" and nameD is "foo(3).txt". dupName = NewDupName(NewNumberedName, entries, true, pick) nameC, _ := dupName.Rename("foo.txt") nameD, _ := dupName.Rename("foo.txt") // In the above case, it would be more suitable to set freeze parameter to 'true'.
func (*DupName) MustRename ¶
type Namer ¶
func NewNumberedName ¶
type NumberedName ¶
type NumberedName struct {
// contains filtered or unexported fields
}
NumberdName is an example of implementation of Namer. PackName() function will change the 'name' to numbered one.
Example:
NewNumberedName("foo.txt").PackName(1) // "foo(1).txt"
func (NumberedName) PackName ¶
func (n NumberedName) PackName(num int64) string
Click to show internal directories.
Click to hide internal directories.