Documentation
¶
Overview ¶
Package naming provides naming conventions used to convert Go struct field names to database columns.
Example ¶
type convention interface { Convert(string) string Join([]string) string } conventions := []convention{SnakeCase, SameCase, LowerCase} names := []string{"snake case", "same case", "lower case"} for i, convention := range conventions { fmt.Printf("\n%s:\n\n", names[i]) fmt.Println(convention.Convert("UserID")) fmt.Println(convention.Convert("HomeAddress")) fmt.Println(convention.Convert("StreetName")) fmt.Println(convention.Join([]string{ convention.Convert("HomeAddress"), convention.Convert("StreetName"), })) fmt.Println(convention.Convert("HTMLElement")) }
Output: snake case: user_id home_address street_name home_address_street_name html_element same case: UserID HomeAddress StreetName HomeAddressStreetName HTMLElement lower case: userid homeaddress streetname homeaddressstreetname htmlelement
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( SnakeCase SnakeCaseConvention LowerCase LowerCaseConvention SameCase SameCaseConvention )
Instances of the different naming conventions
Functions ¶
This section is empty.
Types ¶
type LowerCaseConvention ¶
type LowerCaseConvention struct{}
LowerCaseConvention implements NamingConvention, by converting to lower case.
func (LowerCaseConvention) Convert ¶
func (lc LowerCaseConvention) Convert(fieldName string) string
Convert converts the field name to lower case.
func (LowerCaseConvention) Join ¶
func (lc LowerCaseConvention) Join(names []string) string
Join joins together the names with no separating characters between them.
func (LowerCaseConvention) TableName ¶
func (lc LowerCaseConvention) TableName(typeName string) string
TableName converts a type name into a table name.
type SameCaseConvention ¶
type SameCaseConvention struct{}
SameCaseConvention implements NamingConvention. It does not alter field names.
func (SameCaseConvention) Convert ¶
func (sc SameCaseConvention) Convert(fieldName string) string
Convert returns fieldName unchanged.
func (SameCaseConvention) Join ¶
func (sc SameCaseConvention) Join(names []string) string
Join joins together the names with no separating characters between them.
func (SameCaseConvention) TableName ¶
func (sc SameCaseConvention) TableName(typeName string) string
TableName converts a type name into a table name.
type SnakeCaseConvention ¶
type SnakeCaseConvention struct{}
SnakeCaseConvention converts Go struct fields into "snake_case". So the field name "UserID" would be converted to "user_id".
func (SnakeCaseConvention) Convert ¶
func (sc SnakeCaseConvention) Convert(name string) string
Convert converts fieldName into snake_case.
func (SnakeCaseConvention) Join ¶
func (sc SnakeCaseConvention) Join(names []string) string
Join joins together the names with underscores.
func (SnakeCaseConvention) TableName ¶
func (sc SnakeCaseConvention) TableName(typeName string) string
TableName converts a type name into a table name.