We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Custom Package

Let's write a package to import and use in hellogo.

Assignment

cd ..
mkdir mystrings
cd mystrings
go mod init {REMOTE}/{USERNAME}/mystrings
// by convention, we name our package the same as the directory
package mystrings

// Reverse reverses a string left to right
// Notice that we need to capitalize the first letter of the function
// If we don't then we won't be able to access this function outside of the
// mystrings package
func Reverse(s string) string {
  result := ""
  for _, v := range s {
    result = string(v) + result
  }
  return result
}

Only capitalized names are exported, meaning they can be accessed by other packages. Uncapitalized names are private.

Run and submit the CLI tests from the root of the mystrings package.