All Projects → wawandco → Fako

wawandco / Fako

Licence: mit
Struct Faker for Go

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Fako

faker
Random fake data and struct generator for Go.
Stars: ✭ 67 (-79.64%)
Mutual labels:  faker, struct
Faker
Go (Golang) Fake Data Generator for Struct
Stars: ✭ 1,698 (+416.11%)
Mutual labels:  struct, faker
regenny
A reverse engineering tool to interactively reconstruct structures and generate header files
Stars: ✭ 58 (-82.37%)
Mutual labels:  struct
Dry Struct
Typed struct and value objects
Stars: ✭ 263 (-20.06%)
Mutual labels:  struct
faker
Faker is a Nim package that generates fake data for you.
Stars: ✭ 28 (-91.49%)
Mutual labels:  faker
SNAP
Easy data format saving and loading for GameMaker Studio 2.3.2
Stars: ✭ 49 (-85.11%)
Mutual labels:  struct
phake
PHP Mocking Framework
Stars: ✭ 464 (+41.03%)
Mutual labels:  stub
envy
envy: Deserialize environment variables into type-safe structs
Stars: ✭ 64 (-80.55%)
Mutual labels:  struct
Mimesis
Mimesis is a high-performance fake data generator for Python, which provides data for a variety of purposes in a variety of languages.
Stars: ✭ 3,439 (+945.29%)
Mutual labels:  faker
node-muk
Mock object methods and dependencies.
Stars: ✭ 57 (-82.67%)
Mutual labels:  stub
goverter
Generate type-safe Go converters by simply defining an interface
Stars: ✭ 100 (-69.6%)
Mutual labels:  struct
jsf
Creates fake JSON files from a JSON schema
Stars: ✭ 46 (-86.02%)
Mutual labels:  faker
fieldmask-utils
Protobuf Field Mask Go utils
Stars: ✭ 127 (-61.4%)
Mutual labels:  struct
Hippolyte
HTTP Stubbing in Swift
Stars: ✭ 109 (-66.87%)
Mutual labels:  stub
datafaker
Brings the popular ruby faker gem to Java and Kotlin
Stars: ✭ 138 (-58.05%)
Mutual labels:  faker
Defaults
Initialize structs with default values
Stars: ✭ 290 (-11.85%)
Mutual labels:  struct
php-rdkafka-stubs
Rdkafka extension stubs for your IDE. Always compatibile with the latest php-rdkafka version.
Stars: ✭ 125 (-62.01%)
Mutual labels:  stub
stub-server
Stub server for REST APIs
Stars: ✭ 14 (-95.74%)
Mutual labels:  stub
DeepfakeHTTP
DeepfakeHTTP is a web server that uses HTTP dumps as a source for responses.
Stars: ✭ 373 (+13.37%)
Mutual labels:  stub
Datafaker
Datafaker is a large-scale test data and flow test data generation tool. Datafaker fakes data and inserts to varied data sources. 测试数据生成工具
Stars: ✭ 327 (-0.61%)
Mutual labels:  faker

Fako

Circle CI Godoc Go Report Card

Fako is a library intended to fake Golang structs with fake but coherent data, Fako maps struct field tags and generates fake data accordingly.

We find it useful when writing specs to generate fake database data, hope you too.

Example

This is an example of how Fako works.

import(
  "fmt"
  "github.com/wawandco/fako"
)

type User struct {
    Name     string `fako:"full_name"`
  	Username string `fako:"user_name"`
  	Email    string `fako:"email_address"`//Notice the fako:"email_address" tag
  	Phone    string `fako:"phone"`
  	Password string `fako:"simple_password"`
  	Address  string `fako:"street_address"`
}

func main(){
  var user User
  fako.Fill(&user)

  fmt.Println(&user.Email)
  // This prints something like [email protected]
  // or another valid email

  var userWithOnlyEmail User
  fako.FillOnly(&userWithOnlyEmail, "Email")
  //This will fill all only the email

  var userWithoutEmail User
  fako.FillExcept(&userWithoutEmail, "Email")
  //This will fill all the fields except the email

}

Fako provides 3 built in functions Fill, FillOnly, and FillExcept, please go to godoc for details.

Fako support most of the fields on the fake library, below you can see a list of the field types you can use.

  • brand
  • character
  • characters
  • city
  • color
  • company
  • continent
  • country
  • credit_card_type
  • currency
  • currency_code
  • digits
  • domain_name
  • domain_zone
  • email_address
  • email_body
  • email_subject
  • female_first_name
  • female_full_name
  • female_full_name_with_prefix
  • female_full_name_with_suffix
  • female_last_name
  • female_patronymic
  • first_name
  • full_name
  • full_name_with_prefix
  • full_name_with_suffix
  • gender
  • gender_abbrev
  • hex_color
  • hex_color_short
  • ip_v4
  • industry
  • job_title
  • language
  • last_name
  • latitude_direction
  • longitude_direction
  • male_first_name
  • male_full_name
  • male_full_name_with_prefix
  • male_full_name_with_suffix
  • male_last_name
  • male_patronymic
  • model
  • month
  • month_short
  • paragraph
  • paragraphs
  • patronymic
  • phone
  • product
  • product_name
  • sentence
  • sentences
  • simple_password
  • state
  • state_abbrev
  • street
  • street_address
  • title
  • top_level_domain
  • user_name
  • week_day
  • week_day_short
  • word
  • words
  • zip

Custom Generators

Fako provides a function called Register to add custom data generators in case you need something that our provided generators cannot cover.

To add a custom generator simply call the Register function as in the following example:

import(
  "fmt"
  "github.com/wawandco/fako"
)

type User struct {
    Name     string `fako:"full_name"`
    Username string `fako:"user_name"`
    Email    string `fako:"email_address"`//Notice the fako:"email_address" tag
    Phone    string `fako:"phone"`
    Password string `fako:"simple_password"`
    Address  string `fako:"street_address"`

    AValue   string `fako:"a_gen"`
}

func main(){
  fako.Register("a_gen", func() string {
    return "My Value"
  })

  var user User
  fako.Fill(&user)
  fmt.Println(user.AValue) //should print My Value
}

When using custom generators please keep the following in mind:

  1. Call Register function before calling Fill and its brothers.
  2. Custom generators override base generators, if you pick the same name as one of the existing generators, we will override the existing generator with yours.

Fuzzing

Sometimes you just want to generate random data inside a struct, for those cases you wont want to fill fako types (yes, we understand that part). Fako provides you a Fuzz function you can use to fuzz your structs with random data that simply matches the struct's field types.

You can use it as in the following example:

import "fako"

type Instance struct {
   Name string
   Number int
}

func main(){
  instance := Instance{}
  fako.Fuzz(&instance) // This fills your instance variable
}

Note, Fuzz function works for the following types string, bool, int, int32, int64, float32, float64. other types like Array or Chan are out of our scope.

Credits

As you may have noticed this is based on fake library, which does all the work to generate data.

Copyright

Fako is Copyright © 2008-2015 Wawandco SAS. It is free software, and may be redistributed under the terms specified in the LICENSE file.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].