Documentation ¶
Overview ¶
Package namespace implements a namespace to solve name collision.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NumberSuffix ¶
NumberSuffix renames names by adding a numeric suffix.
func UnderscoreSuffix ¶
UnderscoreSuffix renames names by adding underscores as suffix.
Types ¶
type Namespace ¶
type Namespace interface { // Add tries to create a mapping from ID to name. If name // is used by other ID, then a renamed one will be returned. Add(name, id string) (result string) // Get returns the Added name of id. If none found, the result will // be an empty string. Get(id string) (name string) // ID is the reverse operation of Get. It returns the ID that maps // to the given name. ID(name string) (id string) // Reserve tries to create a mapping from ID to name without any // renaming. The result indicates whether it succeeds. Reserve(name, id string) (ok bool) // MustReserve tries to create a mapping from ID to name without any // renaming. If the name is occupied, this function will panic. MustReserve(name, id string) // Iterate passes each key and value in the namespace to f. // If f returns false, Iterate stops the iteration. Iterate(v func(name, id string) (shouldContinue bool)) }
Namespace is a container that maps IDs to names (both strings) while avoids collision between names by renaming.
func NewNamespace ¶
NewNamespace creates a namespace with the given rename function. The first parameter for the rename function is the preferred name which is not usable due to collision. The second parameter indicates how many different IDs has claimed the same name.
Click to show internal directories.
Click to hide internal directories.