Exercises & activities from the go workshop provided by Packt: https://courses.packtpub.com/courses/go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
751 B

  1. package main
  2. import "fmt"
  3. type name string
  4. type location struct {
  5. x int
  6. y int
  7. }
  8. type size struct {
  9. width int
  10. height int
  11. }
  12. type dot struct {
  13. name
  14. location
  15. size
  16. }
  17. func getDots() []dot {
  18. var dot1 dot
  19. dot2 := dot{}
  20. dot2.name = "A"
  21. dot2.x = 5
  22. dot2.y = 6
  23. dot2.width = 10
  24. dot2.height = 20
  25. dot3 := dot{
  26. name: "B",
  27. location: location{
  28. x: 13,
  29. y: 27,
  30. },
  31. size: size{
  32. width: 5,
  33. height: 7,
  34. },
  35. }
  36. dot4 := dot{}
  37. dot4.name = "C"
  38. dot4.x = 101
  39. dot4.location.y = 209
  40. dot4.width = 87
  41. dot4.size.height = 43
  42. return []dot{dot1, dot2, dot3, dot4}
  43. }
  44. func main() {
  45. dots := getDots()
  46. for i := 0; i < len(dots); i++ {
  47. fmt.Printf("dot%v: %#v\n", i+1, dots[i])
  48. }
  49. }