I have 2 packages, one runs the main program('A' or 'core'), the other is a
remote program that can send to the main program('B' or 'remote').
in A:
type SendFn func(string, interface{}) error
var (
send SendFn
NoSendError = xrr.Xrror("Send is not initialized!")
)
func Send(from string, data interface{}) error {
if send != nil {
return send(from, data)
}
return NoSendError
}
in B:
var sfn core.SendFn
func init() {
sfn = core.Send
}
func main() {
err := sfn("remote", "helloworld")
if err != nil {
os.Stdout.WriteString(err.Error())
os.Stdout.WriteString("\n")
os.Exit(-1)
}
os.Exit(0)
}
So I run A, which defines 'send' as part of an initialization, then run B
but this always returns NoSendError, presumably because B gets package A
before 'send' is initialized where the hope here was that I could just pull
'Send' in and have it work.
I've done something similar using Unix sockets buts it lot more code than I
want to do here and I thought I could work out a simpler process. How would
this work? Probably some channel of sorts but I am uncertain right now.
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.