Documentation
¶
Overview ¶
Package name provides functionality for handling the URL path of a releaser. It contains a type Path that represents the URL path of a releaser and methods to validate and retrieve the well-known styled name of the releaser. It also contains a map of releasers and their well-known styled names.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrPath = errors.New("releaser name: path has invalid characters")
Functions ¶
func Clean ¶ added in v1.14.0
Clean is a more performant replace all for complex expressions.
The f func can be [obfuscate], [valid], or a custom validator.
func Humanize ¶
Humanize deobfuscates the URL path and returns the formatted, human-readable group name. If the URL path contains invalid characters then an error is returned.
Example:
Humanize("path-ampersand-path") = "path & path"
Humanize("path*with*asterisk") = "path, with, asterisk"
Humanize("path/to/file") = ErrPath
Example ¶
package main
import (
"fmt"
"github.com/Defacto2/server/handler/releaser/name"
)
func main() {
s, _ := name.Humanize("defacto2")
fmt.Println(s)
s, _ = name.Humanize("razor-1911-demo")
fmt.Println(s)
s, _ = name.Humanize("razor-1911-demo*trsi")
fmt.Println(s)
}
Output: defacto2 razor 1911 demo razor 1911 demo, trsi
Example (Error) ¶
package main
import (
"fmt"
"github.com/Defacto2/server/handler/releaser/name"
)
func main() {
_, err := name.Humanize("razor-1911-demo#trsi")
if err != nil {
fmt.Println(err)
}
}
Output: releaser name: path has invalid characters
func String ¶ added in v1.14.0
String returns the well-known styled name of the releaser if it exists in the names, lowercase or uppercase lists. Otherwise it returns an empty string.
Example:
name.String("acid-productions") = "ACiD Productions"
name.String("razor-1911") = "" // unlisted
Example ¶
package main
import (
"fmt"
"github.com/Defacto2/server/handler/releaser/name"
)
func main() {
fmt.Println(name.String("acid-productions"))
}
Output: ACiD Productions
Example (Unlisted) ¶
package main
import (
"fmt"
"github.com/Defacto2/server/handler/releaser/name"
)
func main() {
s := name.String("defacto2")
fmt.Println(len(s))
}
Output: 0
func Valid ¶ added in v1.14.0
Valid returns true if the URL path uses valid characters. Valid URL paths are all lowercase and contain only alphanumeric characters, dashes, underscores, ampersands and asterisks.
Example:
name.Valid("acid-productions") = true
name.Valid("acid-productions!") = false
Example ¶
package main
import (
"fmt"
"github.com/Defacto2/server/handler/releaser/name"
)
func main() {
fmt.Println(name.Valid("defacto2"))
fmt.Println(name.Valid("Defacto2"))
}
Output: true false
Types ¶
type List ¶
List maps the releasers and their well-known styled names.
Example ¶
package main
import (
"fmt"
"github.com/Defacto2/server/handler/releaser/name"
)
func main() {
uri := "defacto2net"
for key, val := range name.Copy() {
if key == name.Path(uri) {
fmt.Println(val)
}
}
}
Output: Defacto2 website
func All ¶ added in v1.14.0
func All() List
All returns a copy of the [allIndex] that includes [names], [lowerIndex], [upperIndex].
func Copy ¶ added in v1.14.0
func Copy() List
Copy returns a copy of the [names].
Example ¶
package main
import (
"fmt"
"github.com/Defacto2/server/handler/releaser/name"
)
func main() {
find := name.Path("surprise-productions")
for key, val := range name.Copy() {
if key == find {
fmt.Println(val)
}
}
}
Output: Surprise! Productions
type Path ¶
type Path string
Path is the partial URL path of the releaser.
func Find ¶ added in v1.14.0
Find returns the uri Path of a special named value.
Example:
Find("Oldskool") = "oldskool"
Find("Defacto2") = "" // not listed
func Obfuscate ¶
Obfuscate formats the named string to be used as a URL path.
Example:
string(Obfuscate("ACiD Productions")) = "acid-productions"
string(Obfuscate("Razor 1911 Demo & Skillion")) = "razor-1911-demo-ampersand-skillion"
string(Obfuscate("TDU-Jam!")) = "tdu_jam"
Example ¶
package main
import (
"fmt"
"github.com/Defacto2/server/handler/releaser/name"
)
func main() {
obf := name.Obfuscate("ACiD Productions")
if !name.Valid(obf) {
fmt.Println("invalid")
} else {
fmt.Println(string(obf))
}
}
Output: acid-productions