import "github.com.docker.docker.reference" type MyFile struct { Name string Content string } func (f *MyFile) GetName() string { return f.Name } file := &MyFile{Name: "my_file.txt", Content: "Hello, world!"} fmt.Println(file.GetName()) // Output: "my_file.txt"
import "github.com.docker.docker.reference" type MyStruct struct { Name string Age int } func (s *MyStruct) GetName() string { return s.Name } structInstance := &MyStruct{Name: "John Doe", Age: 30} name := GetName(structInstance) // using helper function defined below fmt.Println(name) // Output: "John Doe" func GetName(n named) string { return n.GetName() }In this example, we define a struct (MyStruct) with a Name and Age field. MyStruct implements the Named interface by defining the GetName() method to return the Name field. We then create an instance of MyStruct and use a helper function (GetName) to retrieve the struct's name. The helper function takes a parameter of type named (the interface) to allow it to be called with any type that implements the Named interface.