Two answer, depending on exactly what you want. (I wrote the second, then
realised I might have over-thought it.)
First answer: why aren't you just using maps? Why do you actually need a
proper 'struct'?
Second answer: Sorta.
Bear in mind that go is /not/ a dynamic language, so any code you write has to
compile. That means that any method you call has to actually exist, and be a
method of the type of the variable you're calling it on.
But what you should be able to do is have something like
type Happy interface {
Celebrate()
}
type DynamicHappy struct {
CelebrateFunc func()
}
func (dh DynamicHappy) Celebrate() {
dh.CelebrateFunc()
}
I don't think anything "more dynamic" than that would make sense within the
context of a statically compiled language. This gives you the ability to
construct arbitrary dynamic implementations of interfaces - I think that's the
best you can do. If you wanted to actually dynamically create an explicit
struct type, you wouldn't be able to use it anywhere, since none of the
(static) uses would compile!
--
Scott Lawrence
go version go1.0.3
Linux baidar 3.8.5-1-ARCH #1 SMP PREEMPT Fri Mar 29 19:18:14 CET 2013 x86_64 GNU/Linux