bxcodec / faker

Go (Golang) Fake Data Generator for Struct. [Notes]This repository is archived, moved to the new repository https://github.com/go-faker/faker

Home Page:https://pkg.go.dev/github.com/bxcodec/faker/v4

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Arrays or Slices of Public structs not supported when tag is `faker:"len=?"`

michaelairola opened this issue · comments

Adding the tag faker:"len=1" on a slice of a Public struct returns the error "Unknown Type". Without tag, faker generates the slice perfectly fine.

I get the same problem

Hey guys, I will look into this soon, so busy lately 🙏

But if you have time, mind submitting the PR?

Hey @bxcodec thanks for responding!

So when I look back at this issue, I think I was looking for the wrong feature. It looks like the "len" tag establishes a desired length for strings in the tagged field (the field types that are currently effected by this tag are string, []string, and map[string]string).

I didn't realize this at the time of writing this issue. My desired result was to control the length of the array, and it looks like the "boundary" tag has that purpose.

It is interesting to note that this throws the exact same error as the issue discussed currently, so I'll go ahead and try to put together a PR that will fix this error for the "boundary" tag.

As a side question, are there any tags that establish a desired exact length for an array instead of a boundary? This would be a neat feature to have :)

I needed the feature and didn't see a pr, so added the tag.
slice_len=5 should do the trick