Documentation ¶
Index ¶
- Variables
- func Camelize(term string) string
- func ClearCache()
- func Dasherize(term string) string
- func ForeignKey(term string) string
- func Ordinal(number int64) string
- func Ordinalize(number int64) string
- func Pluralize(singular string) string
- func Singularize(plural string) string
- func Tableize(term string) string
- func ToSnakeCase(str string) string
- func Underscorize(term string) string
- type Table
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ShouldCache = false
ShouldCache set if the inflector should (or not) cache the inflections
Functions ¶
func Camelize ¶
Camelize converts strings to UpperCamelCase.
Example ¶
fmt.Println(Camelize("my_account")) fmt.Println(Camelize("user-profile")) fmt.Println(Camelize("ssl_error")) fmt.Println(Camelize("http_connection_timeout")) fmt.Println(Camelize("restful_controller")) fmt.Println(Camelize("multiple_http_calls"))
Output: MyAccount UserProfile SSLError HTTPConnectionTimeout RESTfulController MultipleHTTPCalls
func ClearCache ¶
func ClearCache()
ClearCache clear the inflection cache. Both for singulars and plurals.
func Dasherize ¶
Dasherize converts strings to dashed, lowercase form.
Example ¶
fmt.Println(Dasherize("MyAccount")) fmt.Println(Dasherize("user_profile"))
Output: my-account user-profile
func ForeignKey ¶
ForeignKey creates a foreign key name from an ORM model name.
Example ¶
fmt.Println(ForeignKey("Message")) fmt.Println(ForeignKey("AdminPost"))
Output: message_id admin_post_id
func Ordinal ¶
Ordinal returns the suffix that should be added to a number to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
Example ¶
fmt.Println(Ordinal(1)) fmt.Println(Ordinal(2)) fmt.Println(Ordinal(14)) fmt.Println(Ordinal(1002)) fmt.Println(Ordinal(1003)) fmt.Println(Ordinal(-11)) fmt.Println(Ordinal(-1021))
Output: st nd th nd rd th st
func Ordinalize ¶
Ordinalize turns a number into an ordinal string used to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
Example ¶
fmt.Println(Ordinalize(1)) fmt.Println(Ordinalize(2)) fmt.Println(Ordinalize(14)) fmt.Println(Ordinalize(1002)) fmt.Println(Ordinalize(1003)) fmt.Println(Ordinalize(-11)) fmt.Println(Ordinalize(-1021))
Output: 1st 2nd 14th 1002nd 1003rd -11th -1021st
func Pluralize ¶
Pluralize returns the plural form of the word in the string.
Example ¶
fmt.Println(Pluralize("post")) fmt.Println(Pluralize("octopus")) fmt.Println(Pluralize("sheep")) fmt.Println(Pluralize("words")) fmt.Println(Pluralize("CamelOctopus"))
Output: posts octopi sheep words CamelOctopi
func Singularize ¶
Singularize returns the singular form of a word in a string.
Example ¶
fmt.Println(Singularize("posts")) fmt.Println(Singularize("octopi")) fmt.Println(Singularize("sheep")) fmt.Println(Singularize("word")) fmt.Println(Singularize("CamelOctopi"))
Output: post octopus sheep word CamelOctopus
func Tableize ¶
Tableize creates the name of a table for an ORM model.
Example ¶
fmt.Println(Tableize("RawScaledScorer")) fmt.Println(Tableize("ham_and_egg")) fmt.Println(Tableize("fancyCategory"))
Output: raw_scaled_scorers ham_and_eggs fancy_categories
func ToSnakeCase ¶
func Underscorize ¶
Underscorize converts strings to underscored, lowercase form.
Example ¶
fmt.Println(Underscorize("MyAccount")) fmt.Println(Underscorize("user-profile")) fmt.Println(Underscorize("SSLError")) fmt.Println(Underscorize("HTTPConnectionTimeout")) fmt.Println(Underscorize("RESTfulController")) fmt.Println(Underscorize("MultipleHTTPCalls"))
Output: my_account user_profile ssl_error http_connection_timeout restful_controller multiple_http_calls