gofakeit

repository·master·Indexed 26 days ago

https://github.com/brianvoe/gofakeit

A random data generator for Go providing over 310 functions to generate realistic fake data for testing and development. It includes a CLI tool, an HTTP server (gofakeitserver), and support for populating structs via tags, implementing the Fakeable interface, and using Go's text/template engine. The library supports various data categories including person, address, internet, financial, and more, and allows for custom random sources and deterministic seeding.

Tokens
24.7K
Snippets
52
Records
249
Agent score
86%

What's inside gofakeit

  1. Run gofakeitserver

    master

    Start the gofakeitserver on its default port (8080) by running the command in your terminal. Once running, all gofakeit functions are accessible via HTTP. Use the lowercase function name as the first path segment, and pass any required arguments as query parameters.

    gofakeitserver // default port is 8080
  2. Use the gofakeit CLI

    master

    The gofakeit CLI allows you to generate fake data directly from your terminal. You can call specific data functions, list available categories, or generate multiple outputs using the generate command with a loop flag.

    Common Commands

    • Generate a single value: Pass the function name as an argument (e.g., lastname).
    • Generate multiple values: Use the generate command followed by the function name and the -loop flag.
    • List categories: Use list to see top-level categories (like person, word, address) or list <category> to see specific sub-functions.
    • Help: Use help to view the command synopsis and description.
  3. Generate Minecraft-themed data

    master

    The gofakeit library provides a suite of functions to generate random Minecraft-themed strings. You can use the package-level functions (which use GlobalFaker) or call methods on a specific *Faker instance for controlled randomness.

    Available categories include:

    • Items & Materials: Ores, Wood, Dyes, Food, Weapons, and Tools.
    • Armor: Armor Tiers and Armor Parts.
    • Mobs & Entities: Animals, Villager Jobs, Villager Stations, Villager Levels, and Mob types (Passive, Neutral, Hostile, and Bosses).
    • Environment: Biomes and Weather.
  4. Use gofakeit for simple random data generation

    master

    You can call global functions directly from the gofakeit package to generate various types of random data such as names, emails, phone numbers, and more.

    import "github.com/brianvoe/gofakeit/v7"
    
    gofakeit.Name()                // Markus Moen
    gofakeit.Email()               // alaynawuckert@kozey.biz
    gofakeit.Phone()               // (570)245-7485
    gofakeit.BS()                  // front-end
    gofakeit.BeerName()            // Duvel
    gofakeit.Color()               // MediumOrchid
    gofakeit.Company()             // Moen, Pagac and Wuckert
    gofakeit.CreditCardNumber(nil) // 4287271570245748
    gofakeit.HackerPhrase()        // Connecting the array won't do anything, we need to generate the haptic COM driver!
    gofakeit.JobTitle()            // Director
    gofakeit.CurrencyShort()       // USD
  5. Use the Crypto source for secure random numbers

    master

    The Crypto source utilizes Go's crypto/rand package. Use this source for security-sensitive applications that require cryptographically secure random numbers.

    source := NewCryptoSource()
    number := source.Uint64()
  6. Generate random Address and Location data

    master

    Generate physical addresses, city, country, and geographic coordinates.

    Address() *AddressInfo
    City() string
    Country() string
    State() string
    Street() string
    Zip() string
    Latitude() float64
    Longitude() float64
  7. Use the Dumb source for deterministic testing

    master

    The Dumb source is a deterministic generator designed for testing environments. It provides predictable output, which is useful when consistent results are more important than high-quality randomness.

    source := NewDumb(seed)
    number := source.Uint64()