Skip to content

Instantly share code, notes, and snippets.

@jony4
Last active January 3, 2019 09:04
Show Gist options
  • Save jony4/776af05cbbf480d010ed21bd29a20e83 to your computer and use it in GitHub Desktop.
Save jony4/776af05cbbf480d010ed21bd29a20e83 to your computer and use it in GitHub Desktop.
go ToUpperCamelCase
var camelre = regexp.MustCompile(`_([a-z])`)
// ToUpperCamelCase is an NameFunc that converts strings from snake case to upper camel case.
func ToUpperCamelCase(s string) string {
return strings.ToUpper(string(s[0])) + camelre.ReplaceAllStringFunc(s[1:len(s)], func(s string) string {
return strings.ToUpper(s[1:len(s)])
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment