lorem

package module
v0.0.0-...-81f702e Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2023 License: MIT Imports: 14 Imported by: 0

README

go-lorem

A golang library for generating mock data

codecov GitHub

install

go get github.com/CiroLee/go-lorem

usage

import 
  (
    "github.com/CiroLee/go-lorem"
  )

func main() {
  // generate a Chinese word with two characters
  t := lorem.Word(2, "zh")
  // 汉啊 
}

Docs

detail apis see docs

Documentation

Index

Constants

View Source
const (
	Visa       = "visa"
	Amex       = "amex"
	Jcb        = "jcb"
	MasterCard = "mastercard"
	UnionPay   = "unionpay"
)

Variables

This section is empty.

Functions

func Address

func Address() string

return a random Chinese Mainland address string that include province, city and county, separated by space

func Amount

func Amount(min, max float64, decimal uint, prefix string) string

return a random amount with special prefix

func BankCardNumber

func BankCardNumber(issuer string) string

return a random bank card number. support Visa, Amex, Jcb, MasterCard and UnionPay card issuer

func Classify

func Classify(option ClassifyOption) string

return a random image classified image

func Date

func Date(from, to time.Time) time.Time

return a random UTC date

func Domain

func Domain(level uint) string

return a random domain at special level

func Elements

func Elements[T any](arr []T, num uint) []T

return random elements of the array at special num

func Email

func Email() string

return a random email

func Float32

func Float32(min, max float32, decimal uint) (float32, error)

return a random float32 number between min and max.And include max

func Float64

func Float64(min, max float64, decimal uint) (float64, error)

return a random float64 number between min and max.Note: not include max

func FormatDate

func FormatDate(from, to time.Time, layout string) string

return a format date via layout

func GitBranch

func GitBranch() string

return a random git branch

func GitCommitSha

func GitCommitSha() string

return a random git commit sha

func GitCommitShortSha

func GitCommitShortSha() string

return a random git commit short sha

func Hex

func Hex(alpha bool) string

return a random hex color. set alpha true,will return a hex with alpha channel

func HslArray

func HslArray() [3]float32

return a random hsl color array. saturation and lightness will be decimal between 0 and 1(present percent)

func HslStr

func HslStr(style string) string

return a random hsl color string. support legacy and modern style

func HslaArray

func HslaArray() [4]float32

return a random hsla color array. saturation and lightness will be decimal between 0 and 1(present percent)

func HslaStr

func HslaStr(style string) string

return a random hsla color string. support legacy and modern style

func HttpMethod

func HttpMethod() string

return a random http method

func HttpStatusCode

func HttpStatusCode() int

return a random http status code

func Id

func Id() string

return a random Chinese Mainland ID

func Int

func Int(min, max int) (int, error)

return a random int

func IntBy

func IntBy(digit uint, positive bool) (int, error)

return a random int via special digit

func Ipv4

func Ipv4() string

return a random ipv4 address

func Ipv6

func Ipv6() string

return a random ipv6 address

func Landline

func Landline() string

return a random Chinese Mainland landline number

func Letter

func Letter(lang string) string

return a random letter

func LongAndLat

func LongAndLat(format string) [2]string

return a random longitude and latitude array. support deg format and dms format

func MD5

func MD5() string

return a random md5

func Mobile

func Mobile() string

return 11-digit Mainland China mobile number

func MobileHideMiddle

func MobileHideMiddle() string

return a 11-digit Mainland China hidden middle 4-digit mobile number

func Month

func Month(lang string, abbr bool) string

func Name

func Name(lang string, upper bool) string

return a name

func Paragraph

func Paragraph(num uint, lang string) string

return a random paragraph. At lease contains one sentence

func Password

func Password(length uint, strength string) string

return a random password. support specified length and strength

func Picsum

func Picsum(option PicsumOption) string

return a random image from unSplash by special param struct

func Placeholder

func Placeholder(option PlaceholderOption) (string, error)

return a random placeholder image with pure color background with special struct

func Protocol

func Protocol() string

return a random web protocol

func RgbArray

func RgbArray() [3]int

return a random rgb color array

func RgbStr

func RgbStr(style string) string

return a random rgb color string. support legacy and modern style

func RgbaArray

func RgbaArray() [4]float32

return a random rgba color array

func RgbaStr

func RgbaStr(style string) string

return a random rgba color string. support legacy and modern style

func Sentence

func Sentence(num uint, lang string) string

return a random sentence. At least consists one word

func SimpleClassify

func SimpleClassify() string

simple use of Classify without params

func SimplePicsum

func SimplePicsum() string

return a random image. simple use of Picsum without params

func SimplePlaceholder

func SimplePlaceholder() string

return a random placeholder image without params

func SimpleUrl

func SimpleUrl() string

return a random url without params. if you want to set please use Url

func Str

func Str(length uint) string

return a random string

func StrBy

func StrBy(length uint, source string) string

return a random string using special source

func Timestamp

func Timestamp(from, to time.Time, format string) int

return a random timestamp support second millisecond and nanosecond via format param

func Tld

func Tld() (tld, tldType string)

return a random top-level-domain

func UUID

func UUID() string

return a random uuid that conforms to the RFC 4122

func Uint

func Uint(min, max uint) (uint, error)

return a random unit

func Url

func Url(option UrlOption) string

return a random url via the option struct

 type UrlOption struct {
	SubDir       uint      layers of sub-directory,default is between [1,4]
	Protocol     string    protocol of url,default is random
	Suffix       string    suffix of the url, such as .com, .org,default is random
	DomainLevel  uint      level of sub domain, default is between [1,3]
 }

func Version

func Version() string

return a random software version

func Vin

func Vin() string

return a random vehicle identification number

func Vrm

func Vrm() string

return a random Chinese vehicle registration mark

func Week

func Week(lang string, abbr bool) string

return a random week support Chinese and English

func Word

func Word(num uint, lang string) string

return a random word. At least consists two letters

func ZipCode

func ZipCode() int

return a random Chinese Mainland zip code

Types

type AddressBase

type AddressBase struct {
	Code string
	Name string
}

func City

func City() AddressBase

return a random Chinese Mainland city name and code

func County

func County() AddressBase

return a random Chinese Mainland county name and code

func Province

func Province() AddressBase

return a random Chinese Mainland province name and code

type ClassifyOption

type ClassifyOption struct {
	Type   string
	Width  uint
	Height uint
	Lock   bool
}

type Hsl

type Hsl = [3]float32

type PicsumOption

type PicsumOption struct {
	Width     uint
	Height    uint
	Grayscale bool
	Blur      uint
}

type PlaceholderOption

type PlaceholderOption struct {
	Width     uint
	Height    uint
	Text      string
	BgColor   string
	FontColor string
}

type Size

type Size struct {
	Width  uint
	Height uint
}

type UrlOption

type UrlOption struct {
	SubDir      uint
	Protocol    string
	Suffix      string
	DomainLevel uint
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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