Is it possible in Go to retrieve reflect.Type from structure itself?
pseudo:
type MyStruct struct {
Name string
}
type := reflect.TypeOf(MyStruct)
And is it possible to make slice of that type afterwards?
Update:
I am aware of reflect.TypeOf((*t1)(nil)).Elem()
solution for this problem. I am looking for a better solution to this, as this seems to me pretty unfriendly. I'll try to explain the situation.
While developing 'generic' dataservice above database model, I want to do something like:
ds := NewDataService(db.Collection("MyStruct"), MyStruct)
where DataService is able to do Find, Insert etc. using that model. Therefore I need to pass the structure so the model can be used correctly (for example with http server).
The second part is needed as Find
should return slice of found objects.
Because I am using Mongo, there is nothing like schema available within db.Collection