Skip to content

Instantly share code, notes, and snippets.

@kanapuli
Created September 10, 2017 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kanapuli/7d9446a0fb70dc4c12675969cdfb4644 to your computer and use it in GitHub Desktop.
Save kanapuli/7d9446a0fb70dc4c12675969cdfb4644 to your computer and use it in GitHub Desktop.
Types in Go
package main
import "fmt"
type cat string
//String from type cat always meows
func (c cat) String() string {
return fmt.Sprintln("A Cat always Meows")
}
type tiger cat
func main() {
tom := cat("Tommy")
fmt.Printf("%s\n", tom)
kan := tiger("Kan")
fmt.Printf("%s\n", kan)
}
//Output
//go run main.go
//A Cat always Meows
//Kan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment