You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi Chris,
thanx a lot for this book. I love it with Passion!
I'm working through it already the second time and probably it has to do with my missunderstanding, how modules work in go, but I ran into the same error even the second time: I started to create a new module for each chapter since my impression was that each chapter must not correlate with the other. (In your reference implementation, everything is just part of the main module). As a result, when I try to compile this code in my hello.go main module (since I run into errors when I try to create several main functions)
package main
...funcmain () {
sleeper:=&mocking.ConfigurableSleeper{1*time.Second, time.Sleep}
mocking.Countdown(os.Stdout, sleeper)
}
I run into this error:
hello_world\hello.go:62:42: implicit assignment to unexported field duration in struct literal of type mocking.ConfigurableSleeper
hello_world\hello.go:62:59: implicit assignment to unexported field snooze in struct literal of type mocking.ConfigurableSleeper
This was quite iterating for me at first, because in the tests it was possible to set those fields directly but not from the main module. I solved the issue by this
package main
...funcmain() {
sleeper:=&mocking.ConfigurableSleeper{}
sleeper.New(1*time.Second, time.Sleep)
mocking.Countdown(os.Stdout, sleeper)
}
What do you think? Would it be helpful to mention that you can not access private struct memebers accross module borders and therefore have to implement something like a constructor? Or was I completely wrong in setting up every chapter as a module on its own and explain how to work with more then one main module in the modules-chapter? Maybe it would also make sense to explain when to split a project into several modules?
Thanx a lot for your Feedback
Fonzy
The text was updated successfully, but these errors were encountered:
Hi Chris,
thanx a lot for this book. I love it with Passion!
I'm working through it already the second time and probably it has to do with my missunderstanding, how modules work in go, but I ran into the same error even the second time: I started to create a new module for each chapter since my impression was that each chapter must not correlate with the other. (In your reference implementation, everything is just part of the main module). As a result, when I try to compile this code in my hello.go main module (since I run into errors when I try to create several main functions)
I run into this error:
This was quite iterating for me at first, because in the tests it was possible to set those fields directly but not from the main module. I solved the issue by this
in mocking.go
and in hello.go
What do you think? Would it be helpful to mention that you can not access private struct memebers accross module borders and therefore have to implement something like a constructor? Or was I completely wrong in setting up every chapter as a module on its own and explain how to work with more then one main module in the modules-chapter? Maybe it would also make sense to explain when to split a project into several modules?
Thanx a lot for your Feedback
Fonzy
The text was updated successfully, but these errors were encountered: