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
- func CamelCase(name string, firstUpper, acronym bool) string
- func EscapeNonASCII(name string) string
- func Goify(str string, firstUpper bool) string
- func GoifyAttribute(name string, metadata map[string][]string, firstUpper bool) string
- func ImportName(path, explicit string) string
- func KebabCase(name string) string
- func ServerDir(name string) string
- func ServiceDir(name string) string
- func SnakeCase(name string) string
- func Title(s string) string
- func TransportServiceDirs(transport string) []string
Constants ¶
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 ¶
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 ¶
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 ¶
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 GoifyAttribute ¶
GoifyAttribute applies the first struct:field:name override, when present, before deriving the Go identifier used for a design attribute.
func ImportName ¶
ImportName returns the explicit import alias, or the conventional package name inferred from the last path component and its version suffix. It does not discover package declarations; imports whose declared name differs from that convention must provide an explicit name. Blank and dot aliases are returned unchanged and do not reserve a package identifier.
func ServerDir ¶
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 ¶
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 ¶
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 ¶
Title returns s with the first letter of each word in upper case and the other letters unchanged.
func TransportServiceDirs ¶
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.