8. Custom Package
5
Step: Create mystrings.go
// 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
}Your Directory Structure Now
~/workspace/
βββ hellogo/
β βββ go.mod
β βββ main.go
βββ mystrings/
βββ go.mod
βββ mystrings.goUnderstanding the Code
Package declaration
package mystrings