Documentation
¶
Overview ¶
Package naming converts between the three casings rig deals with: the snake_case of Postgres, the PascalCase of Go and TypeScript identifiers, and the camelCase of JSON keys.
The conversions are deliberately asymmetric. A Go identifier uppercases known initialisms, so fixture_id becomes FixtureID; a JSON key does not, so the same column becomes fixtureId. Applying Go's initialism convention to wire formats produces keys like fixtureID that no other language's client would generate.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultInitialisms = []string{
"ACL", "API", "ASCII", "CIDR", "CPU", "CSS", "CSV", "DB", "DNS", "EOF",
"GUID", "HTML", "HTTP", "HTTPS", "ID", "IP", "JSON", "JWT", "LHS", "MIME",
"QPS", "RAM", "RHS", "RPC", "SLA", "SMTP", "SQL", "SSH", "SSL", "TCP",
"TLS", "TTL", "UDP", "UI", "UID", "URI", "URL", "UTF8", "UUID", "VM",
"XML", "XSS", "YAML",
}
DefaultInitialisms are the acronyms that stay fully uppercase in Go identifiers. A project adds its own through Config.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// Initialisms replaces [DefaultInitialisms] when non-empty.
Initialisms []string
// ExtraInitialisms are added to whichever base list is in use. This is the
// usual knob: a project adds its own acronyms without restating Go's.
ExtraInitialisms []string
// Plurals overrides the derived plural for specific singular names, keyed
// by the singular form as written in the database.
Plurals map[string]string
// JSONCase is the shape of generated JSON keys. Defaults to camel.
JSONCase Case
}
Config configures a Namer.
type Namer ¶
type Namer struct {
// contains filtered or unexported fields
}
Namer performs the conversions. The zero value is not usable; call New.
func (*Namer) Go ¶
Go converts an identifier to an exported Go name, uppercasing initialisms.
email_address -> EmailAddress fixture_id -> FixtureID api_key -> APIKey
func (*Namer) GoUnexported ¶
GoUnexported is Namer.Go with a lowercase first word, for local variables and unexported fields. An initialism at the start is lowercased whole, so "id_token" becomes "idToken" rather than "iDToken".
func (*Namer) JSON ¶
JSON converts an identifier to a JSON key in the configured case. Initialisms are not uppercased: fixture_id becomes fixtureId, because that is what a client generator in any other language would produce.
func (*Namer) PathSegment ¶
PathSegment converts a plural resource name into a URL path segment.
LessonTimes -> lesson-times