fake

package module
v0.0.0-...-ff4ab03 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 22, 2020 License: MIT Imports: 18 Imported by: 0

README

fake

Build Status Go Report Card

Fake data generator in Go; Fake number, string, sleep, time, etc.

fake.Bool()                                 // false
fake.Digit()                                // "3"
fake.Num(10, 20)                            // 18                                                                       
fake.UpperChar()                            // "A"
fake.UpperChars(5)                          // ALOHA
fake.LowerChar()                            // "a"                                                                   
fake.LowerChars(5)                          // "aloha"
fake.PickStr([]string{"Windows", "Linux"})  // "Linux"                                                                    
fake.IPv4(192, 168, 0))                     // "192.168.0.68"                                                             
fake.NumCode("4###-####-####-####")         // "4783-4279-7305-1400" (Credit-card)                                                      
fake.NumCode("+01-555-###-####")            // "+01-555-841-7622" (Phone)                                                         
fake.Mac()                                  // "f3:f3:a1:2f:b8:99"                                                        
fake.Now()                                  // "2020-05-14 16:46:54.3682151 +0900 KST m=-0.651090199"                     
fake.Phrase()                               // "dicta soluta tempore sapien" (Lorem Ipsum)                                              
fake.UUID()                                 // "5cab345e-1f78-4d07-9622-53f0a1d057fb" (version 4)

1. Normal works

Numeric
Num(min, max int) int 
Num64(min, max int64) int64
NumStr(min, max int) string // "123"
Digit() string // "1"
PicInt([]int) int
String
String(n int) string       // "a0B2c3", Alphanumeric  
Alpha(n int) string        // "aBc"
LowerChar() string         // "a"
LowerChars(n int) string   // "abc"
UpperChar() string         // "A"
UpperChars(n int) string   // "ABC"
PicStr([]string) string    // one of them
NumCode(str string) string // "555-###-####", "4###-####-####-####"
Network
IPv4() string               // "10.10.10.10"
IPv4(int) string            // "192.10.10.10"
IPv4(int, int) string       // "192.168.10.10"
IPv4(int, int, int) string  // "192.168.54.10"
IPv6() string               // "2001:0000:a423:5690:6d9f:b71d:b488:f758"
Mac() string                // "00:00:5e:00:53:01"
MacHalf() string            // "00:53:01"
Byte
Byte(n int) []byte
Date & time
Now() time.Time             // ± 3000 Milliseconds
Date(t time.Time) time.Time // ± 3000 Milliseconds
DateWithJitter(t time.Time, jitter time.Duration) time.Time // ± jitter
DateRange(min, max time.Time) time.Time
SleepMillis(min, max uint32)
TimeMillisAfter(min, max uint32) <-chan time.Time
Image
Jpeg(width int, height int) []byte
Png(width int, height int) []byte
Gif(width int, height int) []byte
Image(width, height int) *image.RGBA
Lorem ipsum
Word() string
Phrase() string
Sentence() string
Paragraph() string
Shuffling
ShuffleInts(arr []int)
ShuffleStr(arr []string)
Etc.
Hex() string // "ff"

2. Sensitive works

Number
Int8() int8 
Int16() int16 
Int32() int32 
Int64() int64 
Int8Range(min, max int8) int8 
Int16Range(min, max int16) int16 
Int32Range(min, max int32) int32 
Int64Range(min, max int64) int64 
Uint8() uint8 
Uint16() uint16 
Uint32() uint32 
Uint64() uint64 
Uint8Range(min, max uint8) uint8 
Uint16Range(min, max uint16) uint16 
Uint32Range(min, max uint32) uint32 
Uint64Range(min, max uint64) uint64 
Float32() float32 
Float32Range(min, max float32) float32 
Float64() float64 
Float64Range(min, max float64) float64
BigIntRange(min, max *big.Int) *big.Int // Big int

Benchmark

$ go test -bench=. -benchmem
goos: linux
goarch: amd64
pkg: github.com/devplayg/fake
BenchmarkInt8-2       	48413200	        23.9 ns/op	       0 B/op	       0 allocs/op
BenchmarkInt16-2      	50145693	        23.8 ns/op	       0 B/op	       0 allocs/op
BenchmarkInt32-2      	50781237	        24.2 ns/op	       0 B/op	       0 allocs/op
BenchmarkInt64-2      	 1000000	        1046 ns/op	     168 B/op	       8 allocs/op
BenchmarkUInt8-2      	50676717	        23.6 ns/op	       0 B/op	       0 allocs/op
BenchmarkUInt16-2     	50824243	        23.5 ns/op	       0 B/op	       0 allocs/op
BenchmarkUInt32-2     	50886445	        23.5 ns/op	       0 B/op	       0 allocs/op
BenchmarkUInt64-2     	 1252040	        979 ns/op	     120 B/op	       7 allocs/op
BenchmarkFloat32-2    	53117192	        22.6 ns/op	       0 B/op	       0 allocs/op
BenchmarkFloat642-2   	57842583	        20.7 ns/op	       0 B/op	       0 allocs/op
PASS
ok  	github.com/devplayg/fake	13.027s

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Alpha

func Alpha(n int) string

Alpha returns random alphabetical characters

func BigIntRange

func BigIntRange(min, max *big.Int) *big.Int

BigIntRange returns *big.Int between min and max

func Bool

func Bool() bool

Bool returns a random bool

func Byte

func Byte(n int) []byte

Byte returns n size of byte slice

func Date

func Date(t time.Time) time.Time

Date returns time around 3000ms based on specified time

func DateRange

func DateRange(min, max time.Time) time.Time

DateRange returns time between min and max

func DateWithJitter

func DateWithJitter(t time.Time, jitter time.Duration) time.Time

DateWithJitter returns time around 'jitter' based on specified time

func Digit

func Digit() string

Digit returns a number string

func Float32

func Float32() float32

Float32 returns a random float32

func Float32Range

func Float32Range(min, max float32) float32

Float32Range returns a float32 between min and max

func Float64

func Float64() float64

Float64 returns a random float64

func Float64Range

func Float64Range(min, max float64) float64

Float64Range returns a float64 between min and max

func Gif

func Gif(width int, height int) []byte

Png returns a random PNG in []byte

func Hex

func Hex() string

Hex returns a random hex string

func IPv4

func IPv4(prefix ...int) string

IPv4 returns a random IPv4 address

func IPv6

func IPv6() string

IPv6 returns a random IPv6 address

func Image

func Image(width int, height int) *image.RGBA

Image returns a *image.RGBA

func Int16

func Int16() int16

Int16 returns a random int16

func Int16Range

func Int16Range(min, max int16) int16

Int16Range returns a int16 between min and max

func Int32

func Int32() int32

Int32 returns a random int32

func Int32Range

func Int32Range(min, max int32) int32

Int32Range returns a int32 between min and max

func Int64

func Int64() int64

Int64 returns a random int64

func Int64Range

func Int64Range(min, max int64) int64

Int64Range returns a int64 between min and max

func Int8

func Int8() int8

Int8 returns a random int8

func Int8Range

func Int8Range(min, max int8) int8

Int8Range returns a int8 between min and max

func Jpeg

func Jpeg(width int, height int) []byte

Jpeg returns a random JPEG in []byte

func LowerChar

func LowerChar() string

LowerChar returns a random lowercase alphabet

func LowerChars

func LowerChars(n int) string

LowerChars returns random lowercase alphabets

func Mac

func Mac() string

Mac returns a random mac address

func MacHalf

func MacHalf() string

MacHalf returns a random half-mac address

func Now

func Now() time.Time

Now returns time around 3000ms based on the current time

func Num

func Num(min, max int) int

Num returns a int between min and max

func Num64

func Num64(min, max int64) int64

Num returns a int64 between min and max

func NumCode

func NumCode(str string) string

NumCode returns a string with '#' converted to a number

func NumStr

func NumStr(min, max int) string

NumStr returns a number between min and max as a string.

func Paragraph

func Paragraph() string

Word returns a random paragraph

func Phrase

func Phrase() string

Word returns a random phrase

func PickInt

func PickInt(arr []int) int

PickInt returns one of the slice of ints

func PickStr

func PickStr(arr []string) string

PicStr returns one of string in slice

func Png

func Png(width int, height int) []byte

Png returns a random PNG in []byte

func Sentence

func Sentence() string

Word returns a random sentence

func ShuffleInts

func ShuffleInts(arr []int)

ShuffleInts shuffles a slice of ints

func ShuffleStr

func ShuffleStr(arr []string)

ShuffleStr shuffles a slice of strings

func SleepMillis

func SleepMillis(min, max uint32)

SleepMillis sleeps at random times.

func String

func String(n int) string

String returns random characters

func TimeMillisAfter

func TimeMillisAfter(min, max uint32) <-chan time.Time

TimeMillisAfter waits for the duration between min and max to elapse and then sends the current time on the returned channel.

func UUID

func UUID() string

UUID returns a random (Version 4) UUID, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

func Uint16

func Uint16() uint16

Uint16 returns a random uint16

func Uint16Range

func Uint16Range(min, max uint16) uint16

Uint16Range returns a uint16 between min and max

func Uint32

func Uint32() uint32

Uint32 returns a random uint32

func Uint32Range

func Uint32Range(min, max uint32) uint32

Uint32Range returns a uint32 between min and max

func Uint64

func Uint64() uint64

Uint64 returns a random uint64

func Uint64Range

func Uint64Range(min, max uint64) uint64

Uint64Range returns a uint64 between min and max

func Uint8

func Uint8() uint8

Uint8 returns a random uint8

func Uint8Range

func Uint8Range(min, max uint8) uint8

Uint8Range returns a uint8 between min and max

func UpperChar

func UpperChar() string

UpperChar returns a random uppercase alphabet

func UpperChars

func UpperChars(n int) string

UpperChars returns random uppercase alphabets

func Word

func Word() string

Word returns a random word

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL