name

package
v1.14.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2026 License: GPL-3.0 Imports: 3 Imported by: 0

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

View Source
var ErrPath = errors.New("releaser name: path has invalid characters")

Functions

func Clean added in v1.14.0

func Clean(s string, f func(byte) bool) string

Clean is a more performant replace all for complex expressions.

The f func can be [obfuscate], [valid], or a custom validator.

func Humanize

func Humanize(p Path) (string, error)

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

func String(p Path) string

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

func Valid(p Path) bool

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

type List map[Path]string

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

func Lower

func Lower() List

Lower returns a copy of the [lowerIndex].

func Upper

func Upper() List

Upper returns a copy of the [upperIndex].

Example
package main

import (
	"fmt"

	"github.com/Defacto2/server/handler/releaser/name"
)

func main() {
	uri := "beer"
	for key, val := range name.Upper() {
		if key == name.Path(uri) {
			fmt.Println(val)
		}
	}
}
Output:
BEER

type Path

type Path string

Path is the partial URL path of the releaser.

func Find added in v1.14.0

func Find(name string) Path

Find returns the uri Path of a special named value.

Example:

Find("Oldskool") = "oldskool"
Find("Defacto2") = "" // not listed

func Obfuscate

func Obfuscate(name string) Path

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL