brianvoe / gofakeit

Random fake data generator written in go
MIT License
4.49k stars 263 forks source link

Documents for struct tag syntax and parameters? #363

Closed ttc0419 closed 2 weeks ago

ttc0419 commented 3 weeks ago

The README.md only has an example of struct tags, any chance to have a list of all struct tags with parameters and the description of its syntax, like how to only specify fields field using csv?

brianvoe commented 2 weeks ago

Sorry i dont follow what your talking about. Can you send me an example of what your talking about?

ttc0419 commented 2 weeks ago

@brianvoe

name   string    `json:"name" fake:"{csv:?}"` 

According to the source code, "fields" is the only required parameter (i.e. does not have a default value) for csv function:

        Display:     "CSV",
        Category:    "file",
        Description: "Individual lines or data entries within a CSV (Comma-Separated Values) format",
        Example: `id,first_name,last_name,password
1,Markus,Moen,Dc0VYXjkWABx
2,Osborne,Hilll,XPJ9OVNbs5lm`,
        Output:      "[]byte",
        ContentType: "text/csv",
        Params: []Param{
            {Field: "delimiter", Display: "Delimiter", Type: "string", Default: ",", Description: "Separator in between row values"},
            {Field: "rowcount", Display: "Row Count", Type: "int", Default: "100", Description: "Number of rows"},
            {Field: "fields", Display: "Fields", Type: "[]Field", Description: "Fields containing key name and function"},
        },

How to only pass it to the function? And is there a better way to generate delimited string like "xxx-yyyy-zzz" with each substring being a valid word?

brianvoe commented 2 weeks ago

I mean technically you could put all the params needed for a csv or sql but I wouldn't recommend it for struct tags.