naming

package
v1.10.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package naming derives the Go identifiers, file names and directory names that Loom generates from design names. It depends on no other Loom package, so the expr package can validate designs with the same names that code generation uses.

Index

Constants

View Source
const CLIDir = "cli"

CLIDir is the name of the directory of gen/<transport> that holds the client CLI support package of each server, gen/<transport>/cli/<ServerDir>. The transport packages of a service whose ServiceDir is CLIDir are in the same directory.

Variables

This section is empty.

Functions

func CamelCase

func CamelCase(name string, firstUpper, acronym bool) string

CamelCase produces the CamelCase version of the given string. It removes any non letter and non digit character.

If firstUpper is true the first letter of the string is capitalized else the first letter is in lowercase.

If acronym is true and a part of the string is a common acronym then it keeps the part capitalized (firstUpper = true) (e.g. APIVersion) or lowercase (firstUpper = false) (e.g. apiVersion).

func EscapeNonASCII

func EscapeNonASCII(name string) string

EscapeNonASCII escapes every non-ASCII rune of name so that the result can serve where only ASCII is valid, such as protocol buffer package names and Go import paths. A rune in the Basic Multilingual Plane becomes "u" and four lower case hex digits; any other rune becomes "U" and eight. The fixed widths keep distinct names distinct, and ASCII names are returned unchanged.

func Goify

func Goify(str string, firstUpper bool) string

Goify makes a valid Go identifier out of any string. It does that by removing any non letter and non digit character and by making sure the first character is a letter or "_". Goify produces a "CamelCase" version of the string, if firstUpper is true the first character of the identifier is uppercase otherwise it's lowercase. Identifiers that would start with a digit receive the Val or val prefix. When firstUpper is true the result is always an exported Go identifier: a first letter without an upper case form, such as one from a caseless script, also receives the Val prefix.

func KebabCase

func KebabCase(name string) string

KebabCase produces the kebab-case version of the given CamelCase string.

func ServerDir

func ServerDir(name string) string

ServerDir returns the name of the directories and packages generated for the server with the given design name: the example commands under cmd and the client CLI support packages under gen/<transport>/cli. Go import paths are ASCII only, so ServerDir escapes the non-ASCII runes of the snake_case name with EscapeNonASCII.

func ServiceDir

func ServiceDir(name string) string

ServiceDir returns the directory name of the generated packages of the service with the given design name, such as gen/<name> and gen/http/<name>/server. Go import paths are ASCII only, so ServiceDir escapes the non-ASCII runes of the snake_case name with EscapeNonASCII: the packages of a "Café" service are under gen/cafu00e9.

func SnakeCase

func SnakeCase(name string) string

SnakeCase produces the snake_case version of the given CamelCase string. News => news OldNews => old_news CNNNews => cnn_news ÉtéFoo => été_foo

SnakeCase processes runes, not bytes. Letters without case, such as CJK ideographs, continue the current word like lower case letters do. Upper and title case letters that have a lower case form start a new word. Combining marks stay attached to the rune they follow. Invalid UTF-8 bytes become the Unicode replacement character, so the result is always valid UTF-8.

func Title

func Title(s string) string

Title returns s with the first letter of each word in upper case and the other letters unchanged.

func TransportServiceDirs

func TransportServiceDirs(transport string) []string

TransportServiceDirs returns the names of the directories of the packages that the generators create in gen/<transport>/<ServiceDir> for a service exposed over transport, one of "http", "grpc" and "jsonrpc".

Types

This section is empty.

Jump to

Keyboard shortcuts

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