embed_func2.go 539 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package main
  2. import (
  3. "fmt"
  4. )
  5. type Log struct {
  6. msg string
  7. }
  8. type Customer struct {
  9. Name string
  10. Log
  11. }
  12. func main() {
  13. c := &Customer{"Barak Obama", Log{"1 - Yes we can!"}}
  14. c.Add("2 - After me the world will be a better place!")
  15. fmt.Println(c)
  16. }
  17. func (l *Log) Add(s string) {
  18. l.msg += "\n" + s
  19. }
  20. func (c *Customer) String() string {
  21. return c.Name + "\nLog:" + fmt.Sprintln(c.Log)
  22. }
  23. func (l *Log) String() string {
  24. return l.msg
  25. }
  26. /* Output:
  27. Barak Obama
  28. Log:{1 - Yes we can!
  29. 2 - After me the world will be a better place!}
  30. */