Closed mark-ross closed 6 months ago
So your issue I dont think would even be solved even if you put a limit of 1 on it cause as soon as you run the one it calls the other once and keeps cyclicly calling just once. I wouldnt use Gofakeit for a struct like that. Just fill it up yourself with what you want. Not everything needs to be solved in a one liner.
Hello! I love this tool, but recently encountered an issue that I was hoping to discuss.
In a codebase I work with, I have structs which have a cyclic reference from some Gorm definitions. It's a many-to-many case where each of the structs have slices of the other struct. This is leading to a stack overflow when trying to generate the data directly from either of the structures.
Example:
When calling
gofakeit.Struct(&blog)
that triggers the stack overflow since the fake generator goes through each structure, which populates the other, which populates the other, etc. To further throw a wrench in my problem, I have to consider that the field tags cannot be modified on the base structure.So my initial thought was if we could add an optional argument into the
gofakeit.Struct
function wherein we could specify a certain recursion depth or whether or not to populate any/all structs that are in the given structure. Thoughts?Thanks for your time!