package
0.0.0-20200526015148-b343531734ec
Repository: https://github.com/fakorede/learning-golang.git
Documentation: pkg.go.dev
# Packages
No description provided by the author
# README
Type Aliases are a reference to other types.
// TwitterHandler : type alias for twitterHandler
type TwitterHandler = string
// Person : Person struct
type Person struct {
...
twitterHandler TwitterHandler
}
Type Definition
// TwitterHandler : type definition for twitterHandler
type TwitterHandler string
Type Aliases copies the fields and the methods of a type to a new type,thereby becoming that exact type. We cannot extend and add new methods on them.
A Type Definition it only copies the fields of a type(underlying type) over to a new type, it does not copy the methods. We can add new methods. We have to use Explicit Type Conversion so it can access the method of the underlying type.
// TwitterHandler : type def for twitterHandler
type TwitterHandler string
// RedirectURL : RedirectURL
func (th TwitterHandler) RedirectURL() string {
cleanHandler := strings.TrimPrefix(string(th), "@")
return fmt.Sprintf("https://twitter.com/%s", cleanHandler)
}