• This repository has been archived on 08/Dec/2022
  • Stars
    star
    2,077
  • Rank 21,425 (Top 0.5 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 7 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

Important Notes

This repository has been archived, and moved to the new repository here https://github.com/go-faker/faker Further development and fixing will be happening in the new repository.


Docs

faker

Struct Data Fake Generator

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

Build Status 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/bxcodec/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 Only For :

  • int, int8, int16, int32 & int64
  • []int, []int8, []int16, []int32 & []int64
  • bool & []bool
  • string & []string
  • float32, float64, []float32 &[]float64
  • time.Time & []time.Time
  • Nested Struct Field

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 interface{} data type. How could we generate anything without knowing its data type?
  • It does not support the map[interface{}]interface{}, map[any_type]interface{} & map[interface{}]any_type data types. Once again, we cannot generate values for an unknown data type.
  • Custom types are not fully supported. However some custom types are already supported: we are still investigating how to do this the correct way. For now, if you use faker, it's safer not to use any custom types in order to avoid panics.
  • 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.

Contribution


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

More Repositories

1

go-clean-arch

Go (Golang) Clean Architecture based on Reading Uncle Bob's Clean Architecture
Go
7,739
star
2

dbresolver

Golang Database Resolver and Wrapper for any multiple database connections topology, e.g. master-slave replication database, cross-region application, and for separated ReadWrite (RW) and ReadOnly (RO) database connections
Go
124
star
3

go-clean-arch-grpc

Go clean Architecture with GRPC
Go
106
star
4

go-postgres-pagination-example

An example project for pagination in Postgres with Golang
PLpgSQL
57
star
5

httpcache

Get a working HTTP Cache in Go (Golang) with only 3 lines of code!!!!
Go
55
star
6

github-readme-medium-recent-article

Add Your Recently Published Medium Articles to Your GitHub Readme
TypeScript
54
star
7

gotcha

gotcha: inmemory-cache in Go (Golang) with customizable algorithm
Go
20
star
8

integration-testing

Go
18
star
9

simpleshell

Read about this repository here
Go
15
star
10

Article-Management-REST-API

Articles Management API
Go
8
star
11

saint

Go (Golang) Math Library for Integer Operations
Go
7
star
12

sample-client-grpc

Client GRPC
Go
7
star
13

goson

⚑️[WIP] Golang JSON Schema extractor from raw-json string
Go
7
star
14

tweetor

This project is a simple tutorial how to deploy golang application to Kubernetes
Go
4
star
15

Go-Simple-Flatbuffer

Read post about this project here:
Go
4
star
16

AndroidPagination-ListView-Next-prev-

Example of pagination in ListView
Java
1
star
17

images_hosting

My Personal Image Hosting
1
star
18

SMS-Gateway-Android

Sender-receiver of SMS using android Apps
Java
1
star
19

gomodtrial

Trying Go Module - new feature in Go 1.11
Go
1
star
20

gomodmultiplies

Go
1
star