Go Golang Stringer interface example implement String method
package main
/* https://golang.org/pkg/fmt/ */
import (
"fmt"
)
/*A struct is a type which contains named fields.
Define new type named 'Person'*/
type Person struct {
Name string
Age int
Hobbies []string
}
/**Person type implements the method "String" of "Stringer" interface.*/
func (p Person) String() string {
return p.Name
}
func main() {
/*initialize a struct.
Create an instance of type 'Person'*/
p1 := Person{"Sam", 20, []string{"cricket", "football"}}
/*p1 := &Person{name: "Sam", age: 20, hobbies: []string{"cricket", "football"}}*/
fmt.Println("==p1==", p1)
}
On this page of the site you can watch the video online Go Golang Stringer interface example implement String method with a duration of hours minute second in good quality, which was uploaded by the user OSPY 18 February 2018, share the link with friends and acquaintances, this video has already been watched 1,691 times on youtube and it was liked by 14 viewers. Enjoy your viewing!