Go MIT

faker

Go (Golang) Fake Data Generator for Struct, previously https://github.com/bxcodec/faker

G

go-faker

Dernière activité 14 sept. 2026
go-faker/faker

867

étoiles

46

forks

18

issues ouvertes

fake-datafakergolanggolang-librarytesting-librarytesting-tools

Ce README est souvent en anglais.

Docs

Struct Data Fake Generator

Faker will generate you a fake data based on your Struct.

Go Test codecov Go Report Card License Go.Dev

Index

Support

You can file an Issue. See documentation in Go.Dev

Getting Started

Download

go get -u github.com/go-faker/faker/v4

Example


DEMO


Example to use Faker

Benchmark


Bench To Generate Fake Data

Without Tag

BenchmarkFakerDataNOTTagged-4             500000              3049 ns/op             488 B/op         20 allocs/op

Using Tag

 BenchmarkFakerDataTagged-4                100000             17470 ns/op             380 B/op         26 allocs/op

MUST KNOW


The Struct Field must be PUBLIC.
Support For :

  • pointer fields of any type
  • int, int8, int16, int32 & int64
  • uint, uint8, uint16, uint32 & uint64
  • bool
  • string
  • float32, float64
  • struct & nested struct
  • slice / array of any type
  • map of any key/value of supported types
  • custom struct types by registering a StructTypeProvider & implementing your own generator function. This can be used for redefined time, big.Rat, etc. See example for usage.
    • default time.Time provider is registered, you can override it by registering your own provider.

Limitation


Unfortunately this library has some limitation

  • It does not support private fields. Make sure your structs fields you intend to generate fake data for are public, it would otherwise trigger a panic. You can however omit fields using a tag skip faker:"-" on your private fields.
  • It does not support the any (empty interface) data type. How could we generate anything without knowing its data type?
  • It does not support the map[any]any, map[T]any & map[any]T data types (where T is any concrete type). Once again, we cannot generate values for an unknown data type.
  • Some extra custom types can be supported IF AND ONLY IF extended with AddProvider() please see example
  • The oneof tag currently only supports string, the int types, and both float32 & float64. Further support is coming soon (i.e. hex numbers, etc). See example for usage.
  • The template tag currently only supports string, named string types & *string, and can only reference the fields of the struct that declares it. See example for usage.

Contribution


To contrib to this project, you can open a PR or an issue.

Projets similaires

Random fake data generator written in go

Godatafakegenerator
Bbrianvoe
5,4 k étoiles296

Faker is a Python package that generates fake data for you.

Pythondatasetfakefake-data
Jjoke2k
19,4 k étoiles2,1 k

Ultimate fake data generator for Go with zero dependencies

Gocontributions-welcomefakefake-data
Jjaswdr
644 étoiles71