Actually type keyword is same with class topology in PHP.
With type keyword as though you create class in GO
Example type in struct
type Animal struct {
name string //this is like property
}
func (An Animal) PrintAnimal() {
fmt.Println(An.name) //print properties
}
func main() {
animal_cow := Animal{ name: "Cow"} // like initiate object
animal_cow.PrintAnimal() //access method
}
OK let's move with type string (is same for int or float)
type Animal string
// create method for class (type) animal
func (An Animal) PrintAnimal() {
fmt.Println(An) //print properties
}
func main(){
animal_cow := Animal("Cow") // like initiate object
animal_cow.PrintAnimal() //access method
//Cow
}
Difference between struct and string, int, float just in struct you can add more properties with any different data type
Opposite in string, int, float you can only have 1 properties, which created when you initiate your type (ex: animal_cow := Animal("Cow")
But, all type which build using type keyword can definitely have more than 1 method
Correct me if I am wrong