forked from ebhomengo/niki
Merge pull request 'feat(admin): generate and store fake data(#215)' (#216) from stage/hamed/seed into develop
Reviewed-on: ebhomengo/niki#216
This commit is contained in:
commit
5359a0746f
|
|
@ -29,6 +29,7 @@ kavenegar_sms_provider:
|
||||||
|
|
||||||
admin_auth:
|
admin_auth:
|
||||||
sign_key: admin-jwt_secret_test_nik
|
sign_key: admin-jwt_secret_test_nik
|
||||||
|
token: "e18Ef8EAf2116e09A737c0b23B2Bd08D"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
package adminseedhandler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
|
adminseedparam "git.gocasts.ir/ebhomengo/niki/param/admin/seed"
|
||||||
|
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
|
||||||
|
echo "github.com/labstack/echo/v4"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (h Handler) Call(c echo.Context) error {
|
||||||
|
var req adminseedparam.CallSeedRequest
|
||||||
|
if err := c.Bind(&req); err != nil {
|
||||||
|
return echo.NewHTTPError(http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
|
||||||
|
switch req.Action {
|
||||||
|
case adminseedparam.ActionAddBenefactor:
|
||||||
|
_, err = h.adminSeedSvc.AddBenefactor(c.Request().Context())
|
||||||
|
case adminseedparam.AddKindBoxReq:
|
||||||
|
_, err = h.adminSeedSvc.AddKindBoxReq(c.Request().Context(), entity.KindBoxReqAcceptedStatus)
|
||||||
|
case adminseedparam.AssignSenderToKindBoxReq:
|
||||||
|
_, err = h.adminSeedSvc.AssignSenderToKindBoxReq(c.Request().Context(), req.UserId)
|
||||||
|
case adminseedparam.AddKindBox:
|
||||||
|
_, err = h.adminSeedSvc.AddKindBox(c.Request().Context(), req.UserId, entity.KindBoxDeliveredStatus)
|
||||||
|
case adminseedparam.AssignReceiverAgentKindBox:
|
||||||
|
_, err = h.adminSeedSvc.AssignReceiverAgentKindBox(c.Request().Context(), req.UserId)
|
||||||
|
default:
|
||||||
|
err = errors.New(errmsg.ErrorMsgInvalidAction)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
msg, code := httpmsg.Error(err)
|
||||||
|
|
||||||
|
return echo.NewHTTPError(code, msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(http.StatusNoContent, "success!")
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
package adminseedhandler
|
||||||
|
|
||||||
|
import (
|
||||||
|
authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
|
||||||
|
adminseederservice "git.gocasts.ir/ebhomengo/niki/service/seeder"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Handler struct {
|
||||||
|
authSvc authservice.Service
|
||||||
|
adminSeedSvc adminseederservice.Service
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(authSvc authservice.Service,
|
||||||
|
adminSeedSvc adminseederservice.Service,
|
||||||
|
) Handler {
|
||||||
|
return Handler{
|
||||||
|
authSvc: authSvc,
|
||||||
|
adminSeedSvc: adminSeedSvc,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
package adminseedhandler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.gocasts.ir/ebhomengo/niki/delivery/http_server/middleware"
|
||||||
|
echo "github.com/labstack/echo/v4"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (h Handler) SetRoutes(e *echo.Echo) {
|
||||||
|
r := e.Group("/admins/seed")
|
||||||
|
|
||||||
|
r.Use(middleware.Auth(h.authSvc), middleware.TokenSeed(h.authSvc))
|
||||||
|
|
||||||
|
r.POST("", h.Call)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
package middleware
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||||
|
authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
|
)
|
||||||
|
|
||||||
|
// nolint
|
||||||
|
func TokenSeed(cfg authservice.Service) echo.MiddlewareFunc {
|
||||||
|
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||||
|
return func(c echo.Context) error {
|
||||||
|
token := c.Request().Header.Get("token")
|
||||||
|
if token != cfg.Config.SeedToken {
|
||||||
|
return c.JSON(http.StatusForbidden, echo.Map{"message": errmsg.ErrorMsgUserNotAllowed})
|
||||||
|
}
|
||||||
|
|
||||||
|
return next(c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -10,6 +10,7 @@ import (
|
||||||
adminKindBoxHandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/kind_box"
|
adminKindBoxHandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/kind_box"
|
||||||
adminkindboxreqhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/kind_box_req"
|
adminkindboxreqhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/kind_box_req"
|
||||||
adminrefertimehandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/refer_time"
|
adminrefertimehandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/refer_time"
|
||||||
|
adminseedhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/seed"
|
||||||
agentkindboxhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/agent/kind_box"
|
agentkindboxhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/agent/kind_box"
|
||||||
agentkindboxreqhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/agent/kind_box_req"
|
agentkindboxreqhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/agent/kind_box_req"
|
||||||
benefactoraddresshandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/benefactor/address"
|
benefactoraddresshandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/benefactor/address"
|
||||||
|
|
@ -40,6 +41,7 @@ type Server struct {
|
||||||
benefactorAddressHandler benefactoraddresshandler.Handler
|
benefactorAddressHandler benefactoraddresshandler.Handler
|
||||||
benefactorKindBoxHandler benefactorkindboxhandler.Handler
|
benefactorKindBoxHandler benefactorkindboxhandler.Handler
|
||||||
benefactorReferTimeHandler benefactorrefertimehandler.Handler
|
benefactorReferTimeHandler benefactorrefertimehandler.Handler
|
||||||
|
adminSeedHandler adminseedhandler.Handler
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(
|
func New(
|
||||||
|
|
@ -55,6 +57,7 @@ func New(
|
||||||
adminAgentHandler: adminagenthandler.New(svc.AdminAuthSvc, svc.AdminAgentSvc, svc.AdminAuthorizeSvc),
|
adminAgentHandler: adminagenthandler.New(svc.AdminAuthSvc, svc.AdminAgentSvc, svc.AdminAuthorizeSvc),
|
||||||
adminBenefactorHandler: adminbenefactorhandler.New(svc.AdminAuthSvc, svc.AdminAuthorizeSvc, svc.AdminBenefactorSvc, svc.AdminAddressSvc, svc.AdminKindBoxSvc, svc.AdminKindBoxReqSvc),
|
adminBenefactorHandler: adminbenefactorhandler.New(svc.AdminAuthSvc, svc.AdminAuthorizeSvc, svc.AdminBenefactorSvc, svc.AdminAddressSvc, svc.AdminKindBoxSvc, svc.AdminKindBoxReqSvc),
|
||||||
adminReferTimeHandler: adminrefertimehandler.New(svc.AdminAuthSvc, svc.AdminReferTimeSvc, svc.AdminAuthorizeSvc),
|
adminReferTimeHandler: adminrefertimehandler.New(svc.AdminAuthSvc, svc.AdminReferTimeSvc, svc.AdminAuthorizeSvc),
|
||||||
|
adminSeedHandler: adminseedhandler.New(svc.AdminAuthSvc, svc.AdminSeedSvc),
|
||||||
agentKindBoxHandler: agentkindboxhandler.New(svc.AdminAuthSvc, svc.AgentKindBoxSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
|
agentKindBoxHandler: agentkindboxhandler.New(svc.AdminAuthSvc, svc.AgentKindBoxSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
|
||||||
agentKindBoxReqHandler: agentkindboxreqhandler.New(svc.AdminAuthSvc, svc.AgentKindBoxReqSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
|
agentKindBoxReqHandler: agentkindboxreqhandler.New(svc.AdminAuthSvc, svc.AgentKindBoxReqSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
|
||||||
benefactorHandler: benefactorhandler.New(svc.BenefactorAuthSvc, svc.BenefactorSvc),
|
benefactorHandler: benefactorhandler.New(svc.BenefactorAuthSvc, svc.BenefactorSvc),
|
||||||
|
|
@ -99,6 +102,7 @@ func (s Server) RegisterRoutes() {
|
||||||
s.adminBenefactorHandler.SetRoutes(s.Router)
|
s.adminBenefactorHandler.SetRoutes(s.Router)
|
||||||
s.agentKindBoxHandler.SetRoutes(s.Router)
|
s.agentKindBoxHandler.SetRoutes(s.Router)
|
||||||
s.agentKindBoxReqHandler.SetRoutes(s.Router)
|
s.agentKindBoxReqHandler.SetRoutes(s.Router)
|
||||||
|
s.adminSeedHandler.SetRoutes(s.Router)
|
||||||
}
|
}
|
||||||
|
|
||||||
func registerSwagger(s *echo.Echo) {
|
func registerSwagger(s *echo.Echo) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package entity
|
package entity
|
||||||
|
|
||||||
|
import "math/rand"
|
||||||
|
|
||||||
type KindBoxStatus string
|
type KindBoxStatus string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -9,3 +11,15 @@ const (
|
||||||
KindBoxReturnedStatus = KindBoxStatus("returned")
|
KindBoxReturnedStatus = KindBoxStatus("returned")
|
||||||
KindBoxEnumeratedStatus = KindBoxStatus("enumerated")
|
KindBoxEnumeratedStatus = KindBoxStatus("enumerated")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (s KindBoxStatus) GetRandom() KindBoxStatus {
|
||||||
|
var values []KindBoxStatus
|
||||||
|
|
||||||
|
for _, v := range KindBoxTypeStrings {
|
||||||
|
values = append(values, KindBoxStatus(v))
|
||||||
|
}
|
||||||
|
if len(values) > 0 {
|
||||||
|
return values[rand.Intn(len(values))]
|
||||||
|
}
|
||||||
|
return KindBoxDeliveredStatus
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package entity
|
package entity
|
||||||
|
|
||||||
|
import "math/rand"
|
||||||
|
|
||||||
type KindBoxType string
|
type KindBoxType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -19,3 +21,15 @@ func (s KindBoxType) IsValid() bool {
|
||||||
|
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s KindBoxType) GetRandom() KindBoxType {
|
||||||
|
var values []KindBoxType
|
||||||
|
|
||||||
|
for _, v := range KindBoxTypeStrings {
|
||||||
|
values = append(values, KindBoxType(v))
|
||||||
|
}
|
||||||
|
if len(values) > 0 {
|
||||||
|
return values[rand.Intn(len(values))]
|
||||||
|
}
|
||||||
|
return KindBoxOnTable
|
||||||
|
}
|
||||||
|
|
|
||||||
1
go.mod
1
go.mod
|
|
@ -3,6 +3,7 @@ module git.gocasts.ir/ebhomengo/niki
|
||||||
go 1.23
|
go 1.23
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/brianvoe/gofakeit/v7 v7.1.2
|
||||||
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible
|
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible
|
||||||
github.com/go-ozzo/ozzo-validation/v4 v4.3.0
|
github.com/go-ozzo/ozzo-validation/v4 v4.3.0
|
||||||
github.com/go-sql-driver/mysql v1.8.1
|
github.com/go-sql-driver/mysql v1.8.1
|
||||||
|
|
|
||||||
2
go.sum
2
go.sum
|
|
@ -39,6 +39,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
|
||||||
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
|
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
|
||||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||||
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
|
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
|
||||||
|
github.com/brianvoe/gofakeit/v7 v7.1.2 h1:vSKaVScNhWVpf1rlyEKSvO8zKZfuDtGqoIHT//iNNb8=
|
||||||
|
github.com/brianvoe/gofakeit/v7 v7.1.2/go.mod h1:QXuPeBw164PJCzCUZVmgpgHJ3Llj49jSLVkKPMtxtxA=
|
||||||
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
|
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
|
||||||
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
|
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
|
||||||
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
|
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
package adminseedparam
|
||||||
|
|
||||||
|
type Action string
|
||||||
|
|
||||||
|
const (
|
||||||
|
ActionAddBenefactor = Action("addBenefactor")
|
||||||
|
AddKindBoxReq = Action("addKindBoxReq")
|
||||||
|
AddKindBox = Action("addKindBox")
|
||||||
|
AssignSenderToKindBoxReq = Action("assignSenderToKindBoxReq")
|
||||||
|
AssignReceiverAgentKindBox = Action("assignReceiverAgentKindBox")
|
||||||
|
)
|
||||||
|
|
||||||
|
type CallSeedRequest struct {
|
||||||
|
Action Action `json:"action"`
|
||||||
|
UserId uint `json:"user_id"`
|
||||||
|
}
|
||||||
|
|
@ -40,4 +40,5 @@ const (
|
||||||
ErrorMsgInvalidOrExpiredJwt = "invalid or expired jwt"
|
ErrorMsgInvalidOrExpiredJwt = "invalid or expired jwt"
|
||||||
ErrorMsgInvalidRefreshToken = "invalid refresh token"
|
ErrorMsgInvalidRefreshToken = "invalid refresh token"
|
||||||
ErrorMsgInvalidBenefactorStatus = "invalid benefactor status"
|
ErrorMsgInvalidBenefactorStatus = "invalid benefactor status"
|
||||||
|
ErrorMsgInvalidAction = "action invalid"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import (
|
||||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||||
querytransaction "git.gocasts.ir/ebhomengo/niki/pkg/query_transaction/sql"
|
querytransaction "git.gocasts.ir/ebhomengo/niki/pkg/query_transaction/sql"
|
||||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
|
"git.gocasts.ir/ebhomengo/niki/repository/mysql"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (d *DB) AddBatchKindBox(ctx context.Context, kindBoxes []entity.KindBox) error {
|
func (d *DB) AddBatchKindBox(ctx context.Context, kindBoxes []entity.KindBox) error {
|
||||||
|
|
@ -39,3 +40,28 @@ func (d *DB) AddBatchKindBox(ctx context.Context, kindBoxes []entity.KindBox) er
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *DB) AddKindBox(ctx context.Context, kindBox entity.KindBox) (entity.KindBox, error) {
|
||||||
|
const op = "mysqlkindbox.AddKindBox"
|
||||||
|
|
||||||
|
query := `INSERT INTO kind_boxes (kind_box_req_id, benefactor_id, type, status ,deliver_refer_time_id,deliver_refer_date,deliver_address_id,sender_agent_id,delivered_at) VALUES (?,?,?,?,?,?,?,?,?)`
|
||||||
|
//nolint
|
||||||
|
stmt, err := d.conn.PrepareStatement(ctx, mysql.StatementKeyKindBoxAdd, query)
|
||||||
|
if err != nil {
|
||||||
|
return entity.KindBox{}, richerror.New(op).WithErr(err).
|
||||||
|
WithMessage(errmsg.ErrorMsgCantPrepareStatement).WithKind(richerror.KindUnexpected)
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := stmt.ExecContext(ctx, kindBox.KindBoxReqID, kindBox.BenefactorID, kindBox.KindBoxType,
|
||||||
|
kindBox.Status, kindBox.DeliverReferTimeID, kindBox.DeliverReferDate, kindBox.DeliverAddressID,
|
||||||
|
kindBox.SenderAgentID, kindBox.DeliveredAt)
|
||||||
|
if err != nil {
|
||||||
|
return entity.KindBox{}, richerror.New(op).WithErr(err).
|
||||||
|
WithKind(richerror.KindUnexpected)
|
||||||
|
}
|
||||||
|
|
||||||
|
id, _ := res.LastInsertId()
|
||||||
|
kindBox.ID = uint(id)
|
||||||
|
|
||||||
|
return kindBox, nil
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ type Config struct {
|
||||||
RefreshExpirationTime time.Duration `koanf:"refresh_expiration_time"`
|
RefreshExpirationTime time.Duration `koanf:"refresh_expiration_time"`
|
||||||
AccessSubject string `koanf:"access_subject"`
|
AccessSubject string `koanf:"access_subject"`
|
||||||
RefreshSubject string `koanf:"refresh_subject"`
|
RefreshSubject string `koanf:"refresh_subject"`
|
||||||
|
SeedToken string `koanf:"token"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Service struct {
|
type Service struct {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,65 @@
|
||||||
|
package adminseederservice
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
|
"github.com/brianvoe/gofakeit/v7"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s Service) AddBenefactor(ctx context.Context) (entity.Benefactor, error) {
|
||||||
|
const op = "adminseederservice.AddBenefactor"
|
||||||
|
phoneNumber, pErr := s.getPhoneNumber(ctx)
|
||||||
|
if pErr != nil {
|
||||||
|
return entity.Benefactor{}, richerror.New(op).WithErr(pErr).WithKind(richerror.KindUnexpected)
|
||||||
|
}
|
||||||
|
|
||||||
|
benefactor, cErr := s.benefactorRepo.CreateBenefactor(ctx, entity.Benefactor{
|
||||||
|
FirstName: gofakeit.FirstName(),
|
||||||
|
LastName: gofakeit.LastName(),
|
||||||
|
PhoneNumber: phoneNumber,
|
||||||
|
})
|
||||||
|
if cErr != nil {
|
||||||
|
return entity.Benefactor{}, richerror.New(op).WithErr(cErr).WithKind(richerror.KindUnexpected)
|
||||||
|
}
|
||||||
|
|
||||||
|
return benefactor, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s Service) getPhoneNumber(ctx context.Context) (string, error) {
|
||||||
|
minNum := 111111111
|
||||||
|
maxNum := 999999999
|
||||||
|
phoneNumber := "09" + strconv.Itoa(gofakeit.Number(minNum, maxNum))
|
||||||
|
|
||||||
|
_, _, err := s.benefactorRepo.IsExistBenefactorByPhoneNumber(ctx, phoneNumber)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return phoneNumber, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s Service) getAddress(ctx context.Context, benefactorID uint) (entity.Address, error) {
|
||||||
|
cities, cErr := s.addressRepo.GetAllCities(ctx)
|
||||||
|
if cErr != nil {
|
||||||
|
return entity.Address{}, cErr
|
||||||
|
}
|
||||||
|
|
||||||
|
city := cities[gofakeit.Number(1, 470)]
|
||||||
|
address, aErr := s.addressRepo.CreateBenefactorAddress(ctx, entity.Address{
|
||||||
|
PostalCode: gofakeit.Zip(),
|
||||||
|
Address: gofakeit.Address().Address,
|
||||||
|
Name: gofakeit.Name(),
|
||||||
|
Lat: gofakeit.Latitude(),
|
||||||
|
Lon: gofakeit.Longitude(),
|
||||||
|
CityID: city.ID,
|
||||||
|
ProvinceID: city.ProvinceID,
|
||||||
|
BenefactorID: benefactorID,
|
||||||
|
})
|
||||||
|
if aErr != nil {
|
||||||
|
return entity.Address{}, aErr
|
||||||
|
}
|
||||||
|
|
||||||
|
return address, nil
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
package adminseederservice
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
|
"github.com/brianvoe/gofakeit/v7"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s Service) AddKindBox(ctx context.Context, agentId uint, status entity.KindBoxStatus) (entity.KindBox, error) {
|
||||||
|
const op = "adminseederservice.AddKindBox"
|
||||||
|
|
||||||
|
kindBoxReq, cErr := s.AddKindBoxReq(ctx, entity.KindBoxReqAcceptedStatus)
|
||||||
|
if cErr != nil {
|
||||||
|
return entity.KindBox{}, richerror.New(op).WithErr(cErr).WithKind(richerror.KindUnexpected)
|
||||||
|
}
|
||||||
|
|
||||||
|
address, aErr := s.getAddress(ctx, kindBoxReq.BenefactorID)
|
||||||
|
if aErr != nil {
|
||||||
|
return entity.KindBox{}, richerror.New(op).WithErr(aErr).WithKind(richerror.KindUnexpected)
|
||||||
|
}
|
||||||
|
|
||||||
|
kindBox, kErr := s.kindBoxRepo.AddKindBox(ctx, entity.KindBox{
|
||||||
|
KindBoxReqID: kindBoxReq.ID,
|
||||||
|
BenefactorID: kindBoxReq.BenefactorID,
|
||||||
|
KindBoxType: new(entity.KindBoxType).GetRandom(),
|
||||||
|
Status: status,
|
||||||
|
DeliverReferTimeID: uint(gofakeit.IntRange(1, 7)),
|
||||||
|
DeliverReferDate: gofakeit.Date(),
|
||||||
|
DeliverAddressID: address.ID,
|
||||||
|
SenderAgentID: agentId,
|
||||||
|
DeliveredAt: gofakeit.Date(),
|
||||||
|
})
|
||||||
|
if kErr != nil {
|
||||||
|
return entity.KindBox{}, richerror.New(op).WithErr(kErr).WithKind(richerror.KindUnexpected)
|
||||||
|
}
|
||||||
|
|
||||||
|
return kindBox, nil
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
package adminseederservice
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
|
"github.com/brianvoe/gofakeit/v7"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s Service) AddKindBoxReq(ctx context.Context, status entity.KindBoxReqStatus) (entity.KindBoxReq, error) {
|
||||||
|
const op = "adminseederservice.AddKindBoxReq"
|
||||||
|
|
||||||
|
benefactor, bErr := s.AddBenefactor(ctx)
|
||||||
|
if bErr != nil {
|
||||||
|
return entity.KindBoxReq{}, richerror.New(op).WithErr(bErr).WithKind(richerror.KindUnexpected)
|
||||||
|
}
|
||||||
|
|
||||||
|
address, aErr := s.getAddress(ctx, benefactor.ID)
|
||||||
|
if aErr != nil {
|
||||||
|
return entity.KindBoxReq{}, richerror.New(op).WithErr(aErr).WithKind(richerror.KindUnexpected)
|
||||||
|
}
|
||||||
|
|
||||||
|
kindBoxReq, kErr := s.kindBoxReqRepo.AddKindBoxReq(ctx, entity.KindBoxReq{
|
||||||
|
BenefactorID: benefactor.ID,
|
||||||
|
KindBoxType: new(entity.KindBoxType).GetRandom(),
|
||||||
|
DeliverAddressID: address.ID,
|
||||||
|
DeliverReferDate: gofakeit.Date(),
|
||||||
|
DeliverReferTimeID: uint(gofakeit.IntRange(1, 7)),
|
||||||
|
Status: status,
|
||||||
|
})
|
||||||
|
if kErr != nil {
|
||||||
|
return entity.KindBoxReq{}, richerror.New(op).WithErr(kErr).WithKind(richerror.KindUnexpected)
|
||||||
|
}
|
||||||
|
|
||||||
|
return kindBoxReq, nil
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
package adminseederservice
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s Service) AssignReceiverAgentKindBox(ctx context.Context, agentId uint) (entity.KindBox, error) {
|
||||||
|
const op = "adminseederservice.AssignReceiverAgentKindBox"
|
||||||
|
|
||||||
|
kindBox, kErr := s.AddKindBox(ctx, agentId, entity.KindBoxReadyToReturnStatus)
|
||||||
|
if kErr != nil {
|
||||||
|
return entity.KindBox{}, richerror.New(op).WithErr(kErr).WithKind(richerror.KindUnexpected)
|
||||||
|
}
|
||||||
|
|
||||||
|
aErr := s.kindBoxRepo.AssignReceiverAgent(ctx, entity.KindBox{
|
||||||
|
ID: kindBox.ID,
|
||||||
|
ReceiverAgentID: agentId,
|
||||||
|
})
|
||||||
|
if aErr != nil {
|
||||||
|
return entity.KindBox{}, richerror.New(op).WithErr(aErr).WithKind(richerror.KindUnexpected)
|
||||||
|
}
|
||||||
|
|
||||||
|
return kindBox, nil
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
package adminseederservice
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s Service) AssignSenderToKindBoxReq(ctx context.Context, agentId uint) (entity.KindBoxReq, error) {
|
||||||
|
const op = "adminseederservice.AssignSenderToKindBoxReq"
|
||||||
|
|
||||||
|
kindBoxReq, kErr := s.AddKindBoxReq(ctx, entity.KindBoxReqAssignedSenderAgentStatus)
|
||||||
|
if kErr != nil {
|
||||||
|
return entity.KindBoxReq{}, richerror.New(op).WithErr(kErr).WithKind(richerror.KindUnexpected)
|
||||||
|
}
|
||||||
|
|
||||||
|
aErr := s.kindBoxReqRepo.AssignSenderAgentToKindBoxReq(ctx, kindBoxReq.ID, agentId)
|
||||||
|
if aErr != nil {
|
||||||
|
return entity.KindBoxReq{}, richerror.New(op).WithErr(aErr).WithKind(richerror.KindUnexpected)
|
||||||
|
}
|
||||||
|
|
||||||
|
return kindBoxReq, nil
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
package adminseederservice
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
|
)
|
||||||
|
|
||||||
|
type BenefactorRepo interface {
|
||||||
|
CreateBenefactor(ctx context.Context, benefactor entity.Benefactor) (entity.Benefactor, error)
|
||||||
|
IsExistBenefactorByPhoneNumber(ctx context.Context, phoneNumber string) (bool, entity.Benefactor, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type KindBoxRepo interface {
|
||||||
|
AddKindBox(ctx context.Context, kindBox entity.KindBox) (entity.KindBox, error)
|
||||||
|
AssignReceiverAgent(ctx context.Context, kindBox entity.KindBox) error
|
||||||
|
}
|
||||||
|
|
||||||
|
type KindBoxReqRepo interface {
|
||||||
|
AddKindBoxReq(ctx context.Context, kindBoxReq entity.KindBoxReq) (entity.KindBoxReq, error)
|
||||||
|
AssignSenderAgentToKindBoxReq(ctx context.Context, kindBoxReqID, senderAgentID uint) error
|
||||||
|
}
|
||||||
|
|
||||||
|
type AddressRepo interface {
|
||||||
|
GetAllCities(ctx context.Context) ([]entity.City, error)
|
||||||
|
CreateBenefactorAddress(ctx context.Context, address entity.Address) (entity.Address, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Service struct {
|
||||||
|
benefactorRepo BenefactorRepo
|
||||||
|
kindBoxRepo KindBoxRepo
|
||||||
|
kindBoxReqRepo KindBoxReqRepo
|
||||||
|
addressRepo AddressRepo
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(benefactorRepo BenefactorRepo, kindBoxRepo KindBoxRepo, kindBoxReqRepo KindBoxReqRepo, addressRepo AddressRepo) Service {
|
||||||
|
return Service{
|
||||||
|
benefactorRepo: benefactorRepo,
|
||||||
|
kindBoxRepo: kindBoxRepo,
|
||||||
|
kindBoxReqRepo: kindBoxReqRepo,
|
||||||
|
addressRepo: addressRepo,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -33,6 +33,7 @@ import (
|
||||||
benefactorkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/kind_box_req"
|
benefactorkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/kind_box_req"
|
||||||
benefactorrefertimeservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/refer_time"
|
benefactorrefertimeservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/refer_time"
|
||||||
"git.gocasts.ir/ebhomengo/niki/service/notification"
|
"git.gocasts.ir/ebhomengo/niki/service/notification"
|
||||||
|
adminseederservice "git.gocasts.ir/ebhomengo/niki/service/seeder"
|
||||||
adminvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/admin"
|
adminvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/admin"
|
||||||
adminbenefactorvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/benefactor"
|
adminbenefactorvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/benefactor"
|
||||||
adminkindboxvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box"
|
adminkindboxvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box"
|
||||||
|
|
@ -68,6 +69,7 @@ type Service struct {
|
||||||
AdminBenefactorAggSvc adminbenefactoraggsvc.Service
|
AdminBenefactorAggSvc adminbenefactoraggsvc.Service
|
||||||
AdminAddressAggSvc adminaddressaggservice.Service
|
AdminAddressAggSvc adminaddressaggservice.Service
|
||||||
AdminReferTimeAggSvc adminrefertimeaggservice.Service
|
AdminReferTimeAggSvc adminrefertimeaggservice.Service
|
||||||
|
AdminSeedSvc adminseederservice.Service
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(cfg config.Config, db *mysql.DB, rds *redis.Adapter, smsAdapter smscontract.SmsAdapter) *Service {
|
func New(cfg config.Config, db *mysql.DB, rds *redis.Adapter, smsAdapter smscontract.SmsAdapter) *Service {
|
||||||
|
|
@ -91,6 +93,8 @@ func New(cfg config.Config, db *mysql.DB, rds *redis.Adapter, smsAdapter smscont
|
||||||
AdminBenefactorSvc = adminbenefactorservice.New(benefactorRepo, AdminAddressSvc, AdminBenefactorVld)
|
AdminBenefactorSvc = adminbenefactorservice.New(benefactorRepo, AdminAddressSvc, AdminBenefactorVld)
|
||||||
AdminAgentSvc = adminagentservice.New(agentRepo)
|
AdminAgentSvc = adminagentservice.New(agentRepo)
|
||||||
|
|
||||||
|
AdminSeedSvc = adminseederservice.New(benefactorRepo, kindBoxRepo, kindBoxReqRepo, addressRepo)
|
||||||
|
|
||||||
AdminBenefactorAggSvc = adminbenefactoraggsvc.New(benefactorRepo)
|
AdminBenefactorAggSvc = adminbenefactoraggsvc.New(benefactorRepo)
|
||||||
AdminAddressAggSvc = adminaddressaggservice.New(addressRepo)
|
AdminAddressAggSvc = adminaddressaggservice.New(addressRepo)
|
||||||
AdminReferTimeAggSvc = adminrefertimeaggservice.New(referTimeRepo)
|
AdminReferTimeAggSvc = adminrefertimeaggservice.New(referTimeRepo)
|
||||||
|
|
@ -145,5 +149,6 @@ func New(cfg config.Config, db *mysql.DB, rds *redis.Adapter, smsAdapter smscont
|
||||||
AdminBenefactorAggSvc: AdminBenefactorAggSvc,
|
AdminBenefactorAggSvc: AdminBenefactorAggSvc,
|
||||||
AdminAddressAggSvc: AdminAddressAggSvc,
|
AdminAddressAggSvc: AdminAddressAggSvc,
|
||||||
AdminReferTimeAggSvc: AdminReferTimeAggSvc,
|
AdminReferTimeAggSvc: AdminReferTimeAggSvc,
|
||||||
|
AdminSeedSvc: AdminSeedSvc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,323 @@
|
||||||
|
go test -bench=. -benchmem \
|
||||||
|
goos: darwin \
|
||||||
|
goarch: amd64 \
|
||||||
|
pkg: github.com/brianvoe/gofakeit/v7 \
|
||||||
|
cpu: Apple M1 Max \
|
||||||
|
Table generated with tablesgenerator.com/markdown_tables File->Paste table data
|
||||||
|
|
||||||
|
| Benchmark | Ops | CPU | MEM | MEM alloc |
|
||||||
|
|---------------------------------------|----------|----------------|--------------|------------------|
|
||||||
|
| BenchmarkAddress-10 | 1369538 | 874.7 ns/op | 195 B/op | 5 allocs/op |
|
||||||
|
| BenchmarkStreet-10 | 3438403 | 347.9 ns/op | 25 B/op | 2 allocs/op |
|
||||||
|
| BenchmarkStreetNumber-10 | 8601847 | 138.2 ns/op | 4 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkStreetPrefix-10 | 19814623 | 60.26 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkStreetName-10 | 19633909 | 60.78 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkStreetSuffix-10 | 19717612 | 60.19 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkCity-10 | 20219280 | 58.88 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkState-10 | 19526760 | 60.85 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkStateAbr-10 | 19634631 | 60.79 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkZip-10 | 7521580 | 157.7 ns/op | 5 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkCountry-10 | 19451166 | 61.29 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkCountryAbr-10 | 19585867 | 60.82 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkLatitude-10 | 72309668 | 16.22 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkLongitude-10 | 72334910 | 16.23 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkLatitudeInRange-10 | 65830375 | 17.77 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkLongitudeInRange-10 | 66400602 | 17.77 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkPetName-10 | 30391768 | 39.19 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkAnimal-10 | 28761544 | 41.22 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkAnimalType-10 | 26955640 | 44.13 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkFarmAnimal-10 | 22307872 | 53.39 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkCat-10 | 24226416 | 49.13 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkDog-10 | 19702195 | 60.53 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkBird-10 | 17095884 | 70.22 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkAppName-10 | 3805696 | 314.4 ns/op | 25 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkAppVersion-10 | 10250247 | 116.4 ns/op | 7 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkAppAuthor-10 | 11592895 | 101.2 ns/op | 8 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkUsername-10 | 8975020 | 132.9 ns/op | 16 B/op | 2 allocs/op |
|
||||||
|
| BenchmarkPassword-10 | 322147 | 3647 ns/op | 1656 B/op | 60 allocs/op |
|
||||||
|
| BenchmarkBeerName-10 | 27986706 | 42.27 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkBeerStyle-10 | 19460616 | 60.99 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkBeerHop-10 | 26915132 | 44.35 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkBeerYeast-10 | 24840991 | 47.98 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkBeerMalt-10 | 20806075 | 57.18 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkBeerIbu-10 | 41349307 | 28.99 ns/op | 8 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkBeerAlcohol-10 | 6054163 | 197.8 ns/op | 28 B/op | 2 allocs/op |
|
||||||
|
| BenchmarkBeerBlg-10 | 5825622 | 205.6 ns/op | 37 B/op | 2 allocs/op |
|
||||||
|
| BenchmarkBook-10 | 6927696 | 171.9 ns/op | 48 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkBookTitle-10 | 31594431 | 37.36 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkBookAuthor-10 | 29969000 | 39.91 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkBookGenre-10 | 24269676 | 48.77 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkCar-10 | 3795943 | 316.3 ns/op | 96 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkCarType-10 | 26309082 | 43.81 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkCarFuelType-10 | 26414821 | 45.18 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkCarTransmissionType-10 | 24309171 | 48.83 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkCarMaker-10 | 23505099 | 51.01 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkCarModel-10 | 19055469 | 62.82 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkCelebrityActor-10 | 19915483 | 57.84 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkCelebrityBusiness-10 | 20186090 | 67.55 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkCelebritySport-10 | 14223360 | 84.47 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkColor-10 | 21535978 | 54.16 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkNiceColors-10 | 71414755 | 16.16 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkSafeColor-10 | 24683570 | 46.53 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkHexColor-10 | 4815675 | 250.3 ns/op | 24 B/op | 3 allocs/op |
|
||||||
|
| BenchmarkRGBColor-10 | 19453399 | 61.67 ns/op | 24 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkCompany-10 | 25604892 | 46.66 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkCompanySuffix-10 | 24647574 | 48.83 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkBlurb-10 | 20634126 | 58.88 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkBuzzWord-10 | 23034157 | 51.84 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkBS-10 | 21803314 | 55.08 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkJob-10 | 4121804 | 292.0 ns/op | 64 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkJobTitle-10 | 24344308 | 47.51 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkJobDescriptor-10 | 24049240 | 50.12 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkJobLevel-10 | 19349389 | 62.45 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkSlogan-10 | 4499653 | 263.1 ns/op | 41 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkCSVLookup100-10 | 1184 | 1014597 ns/op | 713620 B/op | 9923 allocs/op |
|
||||||
|
| BenchmarkEmoji-10 | 24200866 | 49.72 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkEmojiDescription-10 | 22978600 | 52.18 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkEmojiCategory-10 | 21228057 | 56.57 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkEmojiAlias-10 | 17616240 | 68.45 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkEmojiTag-10 | 19253190 | 62.21 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkError-10 | 1637725 | 736.5 ns/op | 288 B/op | 8 allocs/op |
|
||||||
|
| BenchmarkErrorObject-10 | 6755540 | 177.7 ns/op | 32 B/op | 3 allocs/op |
|
||||||
|
| BenchmarkErrorDatabase-10 | 5794706 | 200.2 ns/op | 63 B/op | 3 allocs/op |
|
||||||
|
| BenchmarkErrorGRPC-10 | 6063802 | 196.8 ns/op | 64 B/op | 3 allocs/op |
|
||||||
|
| BenchmarkErrorHTTP-10 | 3956130 | 302.2 ns/op | 158 B/op | 4 allocs/op |
|
||||||
|
| BenchmarkErrorHTTPClient-10 | 6025258 | 196.4 ns/op | 52 B/op | 3 allocs/op |
|
||||||
|
| BenchmarkErrorHTTPServer-10 | 5969395 | 202.1 ns/op | 59 B/op | 3 allocs/op |
|
||||||
|
| BenchmarkErrorRuntime-10 | 4786108 | 248.3 ns/op | 150 B/op | 3 allocs/op |
|
||||||
|
| BenchmarkErrorValidation-10 | 1811821 | 667.8 ns/op | 277 B/op | 7 allocs/op |
|
||||||
|
| BenchmarkFileMimeType-10 | 26273320 | 45.47 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkFileExtension-10 | 22216770 | 53.94 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkCusip-10 | 6778542 | 176.4 ns/op | 16 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkIsin-10 | 1844566 | 652.1 ns/op | 525 B/op | 7 allocs/op |
|
||||||
|
| BenchmarkFruit-10 | 20381516 | 58.81 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkVegetable-10 | 19638996 | 61.11 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkBreakfast-10 | 9425649 | 127.2 ns/op | 32 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkLunch-10 | 8996594 | 133.6 ns/op | 34 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkDinner-10 | 9427389 | 126.6 ns/op | 36 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkDrink-10 | 8552294 | 140.4 ns/op | 7 B/op | 2 allocs/op |
|
||||||
|
| BenchmarkSnack-10 | 7678719 | 156.7 ns/op | 32 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkDessert-10 | 8907098 | 134.0 ns/op | 31 B/op | 2 allocs/op |
|
||||||
|
| BenchmarkGamertag-10 | 2474312 | 483.9 ns/op | 83 B/op | 5 allocs/op |
|
||||||
|
| BenchmarkDice-10 | 47727080 | 25.22 ns/op | 8 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkGenerate/package-10 | 423741 | 2822 ns/op | 1187 B/op | 29 allocs/op |
|
||||||
|
| BenchmarkGenerate/Complex-10 | 138112 | 8653 ns/op | 4553 B/op | 80 allocs/op |
|
||||||
|
| BenchmarkFixedWidthLookup100-10 | 2072 | 583512 ns/op | 489975 B/op | 8701 allocs/op |
|
||||||
|
| BenchmarkRegex-10 | 633699 | 1914 ns/op | 1632 B/op | 27 allocs/op |
|
||||||
|
| BenchmarkRegexEmail-10 | 205447 | 5893 ns/op | 4084 B/op | 90 allocs/op |
|
||||||
|
| BenchmarkMap-10 | 337576 | 3596 ns/op | 1111 B/op | 16 allocs/op |
|
||||||
|
| BenchmarkHackerPhrase-10 | 166683 | 7209 ns/op | 3107 B/op | 50 allocs/op |
|
||||||
|
| BenchmarkHackerAbbreviation-10 | 25295019 | 47.33 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkHackerAdjective-10 | 24022460 | 49.76 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkHackerNoun-10 | 22496308 | 53.31 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkHackerVerb-10 | 18546052 | 64.53 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkHackeringVerb-10 | 20298242 | 59.05 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkReplaceWithNumbers-10 | 1402717 | 852.8 ns/op | 296 B/op | 10 allocs/op |
|
||||||
|
| BenchmarkHipsterWord-10 | 25151432 | 47.83 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkHipsterSentence-10 | 1314279 | 907.8 ns/op | 288 B/op | 3 allocs/op |
|
||||||
|
| BenchmarkHipsterParagraph-10 | 67437 | 17682 ns/op | 10521 B/op | 48 allocs/op |
|
||||||
|
| BenchmarkInputName-10 | 20759898 | 57.98 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkSvg-10 | 225738 | 5181 ns/op | 8876 B/op | 52 allocs/op |
|
||||||
|
| BenchmarkImageURL-10 | 15524359 | 77.15 ns/op | 38 B/op | 3 allocs/op |
|
||||||
|
| BenchmarkImage-10 | 63 | 18773091 ns/op | 2457691 B/op | 307202 allocs/op |
|
||||||
|
| BenchmarkImageJpeg-10 | 39 | 29498291 ns/op | 2982478 B/op | 307217 allocs/op |
|
||||||
|
| BenchmarkImagePng-10 | 16 | 68552771 ns/op | 5899010 B/op | 307270 allocs/op |
|
||||||
|
| BenchmarkDomainName-10 | 3001479 | 402.2 ns/op | 95 B/op | 5 allocs/op |
|
||||||
|
| BenchmarkDomainSuffix-10 | 21476332 | 56.03 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkURL-10 | 1289262 | 934.6 ns/op | 277 B/op | 10 allocs/op |
|
||||||
|
| BenchmarkHTTPMethod-10 | 19895946 | 60.56 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkIPv4Address-10 | 6088518 | 196.5 ns/op | 16 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkIPv6Address-10 | 2580320 | 462.0 ns/op | 111 B/op | 8 allocs/op |
|
||||||
|
| BenchmarkMacAddress-10 | 3281300 | 364.7 ns/op | 24 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkHTTPStatusCode-10 | 16597051 | 72.18 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkHTTPStatusCodeSimple-10 | 17250238 | 69.52 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkLogLevel-10 | 20608036 | 58.20 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkUserAgent-10 | 1946059 | 615.5 ns/op | 298 B/op | 5 allocs/op |
|
||||||
|
| BenchmarkChromeUserAgent-10 | 2619324 | 458.2 ns/op | 184 B/op | 5 allocs/op |
|
||||||
|
| BenchmarkFirefoxUserAgent-10 | 1601706 | 753.8 ns/op | 362 B/op | 6 allocs/op |
|
||||||
|
| BenchmarkSafariUserAgent-10 | 1569805 | 764.4 ns/op | 551 B/op | 7 allocs/op |
|
||||||
|
| BenchmarkOperaUserAgent-10 | 2378972 | 504.7 ns/op | 212 B/op | 5 allocs/op |
|
||||||
|
| BenchmarkJSONLookup100-10 | 928 | 1276230 ns/op | 813725 B/op | 12134 allocs/op |
|
||||||
|
| BenchmarkLanguage-10 | 23873984 | 50.34 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkLanguageAbbreviation-10 | 25025524 | 47.93 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkLanguageBCP-10 | 21895112 | 54.74 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkProgrammingLanguage-10 | 21169636 | 56.70 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkLoremIpsumWord-10 | 23980356 | 49.92 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkLoremIpsumSentence-10 | 1344384 | 894.8 ns/op | 219 B/op | 2 allocs/op |
|
||||||
|
| BenchmarkLoremIpsumParagraph-10 | 66643 | 17916 ns/op | 8483 B/op | 40 allocs/op |
|
||||||
|
| BenchmarkMinecraftOre-10 | 15077451 | 79.85 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkMinecraftWood-10 | 14422303 | 83.44 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkMinecraftArmorTier-10 | 15262417 | 78.70 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkMinecraftArmorPart-10 | 15340200 | 78.11 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkMinecraftWeapon-10 | 15107792 | 79.78 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkMinecraftTool-10 | 14428170 | 83.15 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkMinecraftDye-10 | 14657188 | 81.95 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkMinecraftFood-10 | 14860236 | 81.01 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkMinecraftAnimal-10 | 15281302 | 78.35 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkMinecraftVillagerJob-10 | 14586627 | 82.14 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkMinecraftVillagerStation-10 | 14678592 | 81.82 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkMinecraftVillagerLevel-10 | 14314164 | 83.76 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkMinecraftMobPassive-10 | 15132750 | 79.32 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkMinecraftMobNeutral-10 | 13802880 | 87.23 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkMinecraftMobHostile-10 | 13141233 | 91.06 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkMinecraftMobBoss-10 | 15245322 | 78.79 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkMinecraftBiome-10 | 14943789 | 79.86 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkMinecraftWeather-10 | 12681386 | 94.55 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkBool-10 | 73596490 | 16.18 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkUUID-10 | 4128735 | 288.7 ns/op | 48 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkShuffleAnySlice-10 | 3149857 | 380.0 ns/op | 24 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkFlipACoin-10 | 74457853 | 16.17 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkMovie-10 | 9234234 | 129.3 ns/op | 32 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkMovieName-10 | 25314163 | 47.82 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkMovieGenre-10 | 24570799 | 48.81 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkNumber-10 | 74087221 | 16.21 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkUint8-10 | 73790145 | 16.35 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkUint16-10 | 74334474 | 16.27 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkUint32-10 | 71804154 | 16.72 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkUint64-10 | 71385904 | 16.64 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkUintRange-10 | 73982353 | 16.13 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkInt8-10 | 73927286 | 16.14 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkInt16-10 | 74022668 | 16.19 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkInt32-10 | 72009002 | 16.64 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkInt64-10 | 72375081 | 16.59 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkIntRange-10 | 74396306 | 16.20 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkFloat32-10 | 73950822 | 16.20 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkFloat32Range-10 | 73622833 | 16.18 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkFloat64-10 | 73076970 | 16.31 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkFloat64Range-10 | 73385329 | 16.33 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkShuffleInts-10 | 9151563 | 131.8 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkRandomInt-10 | 72188592 | 16.63 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkRandomUint-10 | 72293332 | 16.64 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkHexUint-10 | 14888452 | 80.93 ns/op | 16 B/op | 2 allocs/op |
|
||||||
|
| BenchmarkCurrency-10 | 14366668 | 83.15 ns/op | 32 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkCurrencyShort-10 | 24445954 | 48.68 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkCurrencyLong-10 | 23560556 | 50.65 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkPrice-10 | 73693664 | 16.33 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkCreditCard-10 | 1000000 | 1153 ns/op | 264 B/op | 15 allocs/op |
|
||||||
|
| BenchmarkCreditCardType-10 | 32410167 | 36.93 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkCreditCardNumber-10 | 1511084 | 799.1 ns/op | 183 B/op | 10 allocs/op |
|
||||||
|
| BenchmarkCreditCardExp-10 | 11014600 | 108.5 ns/op | 5 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkCreditCardCvv-10 | 20325733 | 59.31 ns/op | 3 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkAchRouting-10 | 7338657 | 164.0 ns/op | 16 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkAchAccount-10 | 5646235 | 212.0 ns/op | 16 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkBitcoinAddress-10 | 517399 | 2306 ns/op | 715 B/op | 37 allocs/op |
|
||||||
|
| BenchmarkBitcoinPrivateKey-10 | 1276884 | 943.2 ns/op | 184 B/op | 5 allocs/op |
|
||||||
|
| BenchmarkName-10 | 7771977 | 152.6 ns/op | 16 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkFirstName-10 | 23523357 | 50.98 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkMiddleName-10 | 17589612 | 68.17 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkLastName-10 | 20825980 | 57.63 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkNamePrefix-10 | 25542308 | 46.65 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkNameSuffix-10 | 21972974 | 54.56 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkSSN-10 | 31829850 | 37.71 ns/op | 16 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkGender-10 | 73621140 | 16.25 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkHobby-10 | 17347129 | 69.06 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkPerson-10 | 317911 | 3693 ns/op | 837 B/op | 33 allocs/op |
|
||||||
|
| BenchmarkContact-10 | 1843221 | 650.8 ns/op | 136 B/op | 6 allocs/op |
|
||||||
|
| BenchmarkPhone-10 | 6786794 | 176.2 ns/op | 16 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkPhoneFormatted-10 | 4674930 | 256.2 ns/op | 16 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkEmail-10 | 2794358 | 431.1 ns/op | 88 B/op | 4 allocs/op |
|
||||||
|
| BenchmarkTeams-10 | 1576238 | 763.8 ns/op | 672 B/op | 10 allocs/op |
|
||||||
|
| BenchmarkProduct-10 | 206918 | 5813 ns/op | 1069 B/op | 31 allocs/op |
|
||||||
|
| BenchmarkProductName-10 | 2313364 | 517.4 ns/op | 103 B/op | 5 allocs/op |
|
||||||
|
| BenchmarkProductDescription-10 | 348346 | 3434 ns/op | 549 B/op | 8 allocs/op |
|
||||||
|
| BenchmarkProductCategory-10 | 25139860 | 47.73 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkProductFeature-10 | 21264922 | 56.46 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkProductMaterial-10 | 18142828 | 66.24 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkProductUPC-10 | 1399148 | 859.1 ns/op | 96 B/op | 11 allocs/op |
|
||||||
|
| BenchmarkSchool-10 | 4161710 | 287.6 ns/op | 34 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkLetter-10 | 73457020 | 16.29 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkLetterN-10 | 5060271 | 238.8 ns/op | 64 B/op | 2 allocs/op |
|
||||||
|
| BenchmarkVowel-10 | 58685206 | 20.87 ns/op | 4 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkDigit-10 | 73944177 | 16.20 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkDigitN-10 | 5051070 | 236.6 ns/op | 64 B/op | 2 allocs/op |
|
||||||
|
| BenchmarkNumerify-10 | 6794545 | 176.4 ns/op | 16 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkLexify-10 | 11113212 | 108.3 ns/op | 8 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkShuffleStrings-10 | 9924429 | 121.0 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkRandomString-10 | 73420688 | 16.34 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkTemplate-10 | 2488 | 477349 ns/op | 280877 B/op | 4611 allocs/op |
|
||||||
|
| BenchmarkDate-10 | 10292476 | 116.2 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkPastDate-10 | 18285830 | 65.48 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkFutureDate-10 | 18399240 | 65.13 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkDateRange-10 | 8406979 | 142.7 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkMonth-10 | 74105902 | 16.26 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkMonthString-10 | 73647870 | 16.26 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkWeekDay-10 | 73990911 | 16.24 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkDay-10 | 73435291 | 16.21 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkYear-10 | 73950066 | 16.21 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkHour-10 | 74219916 | 16.21 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkMinute-10 | 74349634 | 16.21 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkSecond-10 | 73787313 | 16.29 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkNanoSecond-10 | 74299380 | 16.15 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkTimeZone-10 | 19105237 | 62.83 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkTimeZoneFull-10 | 16170054 | 74.27 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkTimeZoneAbv-10 | 20725029 | 58.23 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkTimeZoneOffset-10 | 14597666 | 81.13 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkTimeZoneRegion-10 | 15733551 | 76.25 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkWeighted-10 | 28507484 | 40.42 ns/op | 16 B/op | 1 allocs/op |
|
||||||
|
| BenchmarkAdjective-10 | 6726474 | 178.3 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkAdjectiveDescriptive-10 | 16486224 | 73.39 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkAdjectiveQuantitative-10 | 15290762 | 78.51 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkAdjectiveProper-10 | 16535046 | 72.42 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkAdjectiveDemonstrative-10 | 16448917 | 73.41 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkAdjectivePossessive-10 | 15715839 | 73.22 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkAdjectiveInterrogative-10 | 15543478 | 77.43 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkAdjectiveIndefinite-10 | 16306894 | 73.50 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkAdverb-10 | 7139924 | 168.7 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkAdverbManner-10 | 17139112 | 70.37 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkAdverbDegree-10 | 16213138 | 73.70 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkAdverbPlace-10 | 17268267 | 69.67 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkAdverbTimeDefinite-10 | 16273309 | 73.70 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkAdverbTimeIndefinite-10 | 15822297 | 74.26 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkAdverbFrequencyDefinite-10 | 16344181 | 73.30 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkAdverbFrequencyIndefinite-10 | 16118569 | 74.27 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkComment-10 | 1000000 | 1146 ns/op | 258 B/op | 6 allocs/op |
|
||||||
|
| BenchmarkConnective-10 | 7132710 | 168.3 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkConnectiveTime-10 | 15339457 | 78.08 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkConnectiveComparative-10 | 16188842 | 74.04 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkConnectiveComplaint-10 | 14127903 | 85.00 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkConnectiveListing-10 | 16073437 | 74.65 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkConnectiveCasual-10 | 13771904 | 87.06 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkConnectiveExamplify-10 | 15763296 | 76.03 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkWord-10 | 8047610 | 148.5 ns/op | 3 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkSentenceSimple-10 | 682924 | 1707 ns/op | 590 B/op | 11 allocs/op |
|
||||||
|
| BenchmarkInterjection-10 | 16295702 | 73.50 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkNoun-10 | 6711976 | 179.3 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkNounCommon-10 | 17117466 | 69.83 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkNounConcrete-10 | 17144979 | 69.81 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkNounAbstract-10 | 16839790 | 71.16 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkNounCollectivePeople-10 | 16360652 | 73.24 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkNounCollectiveAnimal-10 | 16453287 | 72.79 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkNounCollectiveThing-10 | 16397232 | 72.97 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkNounCountable-10 | 17171895 | 69.78 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkNounUncountable-10 | 17193412 | 69.75 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkNounProper-10 | 10644372 | 112.0 ns/op | 7 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkNounDeterminer-10 | 17003730 | 70.44 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkPhrase-10 | 23481584 | 51.12 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkPhraseNoun-10 | 2961691 | 405.1 ns/op | 104 B/op | 2 allocs/op |
|
||||||
|
| BenchmarkPhraseVerb-10 | 1422132 | 845.1 ns/op | 232 B/op | 6 allocs/op |
|
||||||
|
| BenchmarkPhraseAdverb-10 | 7617193 | 153.3 ns/op | 9 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkPhrasePreposition-10 | 2336155 | 513.3 ns/op | 123 B/op | 3 allocs/op |
|
||||||
|
| BenchmarkPreposition-10 | 9244665 | 129.9 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkPrepositionSimple-10 | 16397623 | 73.11 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkPrepositionDouble-10 | 16107751 | 74.19 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkPrepositionCompound-10 | 16364900 | 73.10 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkPronoun-10 | 6436707 | 186.4 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkPronounPersonal-10 | 16997427 | 70.53 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkPronounObject-10 | 15303380 | 78.27 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkPronounPossessive-10 | 15323908 | 78.10 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkPronounReflective-10 | 15258552 | 78.45 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkPronounIndefinite-10 | 16053780 | 74.69 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkPronounDemonstrative-10 | 16476726 | 72.73 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkPronounInterrogative-10 | 15526576 | 77.15 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkPronounRelative-10 | 14159284 | 84.64 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkSentence-10 | 721934 | 1642 ns/op | 219 B/op | 3 allocs/op |
|
||||||
|
| BenchmarkParagraph-10 | 39356 | 30481 ns/op | 6687 B/op | 53 allocs/op |
|
||||||
|
| BenchmarkQuestion-10 | 1757269 | 683.1 ns/op | 243 B/op | 3 allocs/op |
|
||||||
|
| BenchmarkQuote-10 | 1522988 | 787.2 ns/op | 261 B/op | 3 allocs/op |
|
||||||
|
| BenchmarkVerb-10 | 8924802 | 127.6 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkVerbAction-10 | 17150564 | 69.83 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkVerbTransitive-10 | 17328488 | 69.21 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkVerbIntransitive-10 | 16427985 | 72.98 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkVerbLinking-10 | 17754280 | 67.52 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkVerbHelping-10 | 17118238 | 70.31 ns/op | 0 B/op | 0 allocs/op |
|
||||||
|
| BenchmarkXMLLookup100-10 | 937 | 1279022 ns/op | 862536 B/op | 11370 allocs/op |
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
# Contributor Covenant Code of Conduct
|
||||||
|
|
||||||
|
## Our Pledge
|
||||||
|
|
||||||
|
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
||||||
|
|
||||||
|
## Our Standards
|
||||||
|
|
||||||
|
Examples of behavior that contributes to creating a positive environment include:
|
||||||
|
|
||||||
|
* Using welcoming and inclusive language
|
||||||
|
* Being respectful of differing viewpoints and experiences
|
||||||
|
* Gracefully accepting constructive criticism
|
||||||
|
* Focusing on what is best for the community
|
||||||
|
* Showing empathy towards other community members
|
||||||
|
|
||||||
|
Examples of unacceptable behavior by participants include:
|
||||||
|
|
||||||
|
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
||||||
|
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||||
|
* Public or private harassment
|
||||||
|
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
||||||
|
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
||||||
|
|
||||||
|
## Our Responsibilities
|
||||||
|
|
||||||
|
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
||||||
|
|
||||||
|
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
||||||
|
|
||||||
|
## Scope
|
||||||
|
|
||||||
|
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
||||||
|
|
||||||
|
## Enforcement
|
||||||
|
|
||||||
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at brian@webiswhatido.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
||||||
|
|
||||||
|
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
||||||
|
|
||||||
|
## Attribution
|
||||||
|
|
||||||
|
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
||||||
|
|
||||||
|
[homepage]: http://contributor-covenant.org
|
||||||
|
[version]: http://contributor-covenant.org/version/1/4/
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
# Make a pull request and submit it and ill take a look at it. Thanks!
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) [year] [fullname]
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
@ -0,0 +1,868 @@
|
||||||
|

|
||||||
|
|
||||||
|
# Gofakeit [](https://goreportcard.com/report/github.com/brianvoe/gofakeit)  [](https://godoc.org/github.com/brianvoe/gofakeit/v7) [](https://raw.githubusercontent.com/brianvoe/gofakeit/master/LICENSE.txt)
|
||||||
|
|
||||||
|
Random data generator written in go
|
||||||
|
|
||||||
|
[](https://ko-fi.com/G2G0R5EJT)
|
||||||
|
|
||||||
|
<a href="https://www.buymeacoffee.com/brianvoe" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: auto !important;width: auto !important;" ></a>
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- [310+ Functions!!!](#functions)
|
||||||
|
- [Random Sources](#random-sources)
|
||||||
|
- [Global Rand](#global-rand-set)
|
||||||
|
- [Struct Generator](#struct)
|
||||||
|
- [Custom Functions](#custom-functions)
|
||||||
|
- [Templates](#templates)
|
||||||
|
- [Http Server](https://github.com/brianvoe/gofakeit/tree/master/cmd/gofakeitserver)
|
||||||
|
- [Command Line Tool](https://github.com/brianvoe/gofakeit/tree/master/cmd/gofakeit)
|
||||||
|
- Zero dependencies
|
||||||
|
- [Benchmarks](https://github.com/brianvoe/gofakeit/blob/master/BENCHMARKS.md)
|
||||||
|
- [Issue](https://github.com/brianvoe/gofakeit/issues)
|
||||||
|
|
||||||
|
## Contributors
|
||||||
|
|
||||||
|
Thank you to all our Gofakeit contributors!
|
||||||
|
|
||||||
|
<a href="https://github.com/brianvoe/gofakeit/graphs/contributors">
|
||||||
|
<img src="https://contrib.rocks/image?repo=brianvoe/gofakeit" />
|
||||||
|
</a>
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
```go
|
||||||
|
go get github.com/brianvoe/gofakeit/v7
|
||||||
|
```
|
||||||
|
|
||||||
|
## Simple Usage
|
||||||
|
|
||||||
|
```go
|
||||||
|
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() // 4287271570245748
|
||||||
|
gofakeit.HackerPhrase() // Connecting the array won't do anything, we need to generate the haptic COM driver!
|
||||||
|
gofakeit.JobTitle() // Director
|
||||||
|
gofakeit.CurrencyShort() // USD
|
||||||
|
```
|
||||||
|
|
||||||
|
[See full list of functions](#functions)
|
||||||
|
|
||||||
|
## Seed
|
||||||
|
|
||||||
|
If you are using the default global usage and dont care about seeding no need to set anything.
|
||||||
|
Gofakeit will seed it with a cryptographically secure number.
|
||||||
|
|
||||||
|
If you need a reproducible outcome you can set it via the Seed function call. Every example in
|
||||||
|
this repo sets it for testing purposes.
|
||||||
|
|
||||||
|
```go
|
||||||
|
import "github.com/brianvoe/gofakeit/v7"
|
||||||
|
|
||||||
|
gofakeit.Seed(0) // If 0 will use crypto/rand to generate a number
|
||||||
|
|
||||||
|
// or
|
||||||
|
|
||||||
|
gofakeit.Seed(8675309) // Set it to whatever number you want
|
||||||
|
```
|
||||||
|
|
||||||
|
## Random Sources
|
||||||
|
|
||||||
|
Gofakeit has a few rand sources, by default it uses math/rand/v2 PCG which is a pseudo random number generator and is thread locked.
|
||||||
|
|
||||||
|
If you want to see other potential sources you can see the sub package [Source](https://github.com/brianvoe/gofakeit/tree/master/source) for more information.
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"github.com/brianvoe/gofakeit/v7"
|
||||||
|
"github.com/brianvoe/gofakeit/v7/source"
|
||||||
|
"math/rand/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Uses math/rand/v2(PCG Pseudo) with mutex locking
|
||||||
|
faker := gofakeit.New(0)
|
||||||
|
|
||||||
|
// NewFaker takes in a source and whether or not it should be thread safe
|
||||||
|
faker := gofakeit.NewFaker(source rand.Source, threadSafe bool)
|
||||||
|
|
||||||
|
// PCG Pseudo
|
||||||
|
faker := gofakeit.NewFaker(rand.NewPCG(11, 11), true)
|
||||||
|
|
||||||
|
// ChaCha8
|
||||||
|
faker := gofakeit.NewFaker(rand.NewChaCha8([32]byte{0, 1, 2, 3, 4, 5}), true)
|
||||||
|
|
||||||
|
|
||||||
|
// Additional from Gofakeit sub package source
|
||||||
|
|
||||||
|
// JSF(Jenkins Small Fast)
|
||||||
|
faker := gofakeit.NewFaker(source.NewJSF(11), true)
|
||||||
|
|
||||||
|
// SFC(Simple Fast Counter)
|
||||||
|
faker := gofakeit.NewFaker(source.NewSFC(11), true)
|
||||||
|
|
||||||
|
// Crypto - Uses crypto/rand
|
||||||
|
faker := gofakeit.NewFaker(source.NewCrypto(), true)
|
||||||
|
|
||||||
|
// Dumb - simple incrementing number
|
||||||
|
faker := gofakeit.NewFaker(source.NewDumb(11), true)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Global Rand Set
|
||||||
|
|
||||||
|
If you would like to use the simple function calls but need to use something like
|
||||||
|
crypto/rand you can override the default global with the random source that you want.
|
||||||
|
|
||||||
|
```go
|
||||||
|
import "github.com/brianvoe/gofakeit/v7"
|
||||||
|
|
||||||
|
gofakeit.GlobalFaker = gofakeit.New(0)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Struct
|
||||||
|
|
||||||
|
Gofakeit can generate random data for struct fields. For the most part it covers all the basic type
|
||||||
|
as well as some non-basic like time.Time.
|
||||||
|
|
||||||
|
Struct fields can also use tags to more specifically generate data for that field type.
|
||||||
|
|
||||||
|
```go
|
||||||
|
import "github.com/brianvoe/gofakeit/v7"
|
||||||
|
|
||||||
|
// Create structs with random injected data
|
||||||
|
type Foo struct {
|
||||||
|
Str string
|
||||||
|
Int int
|
||||||
|
Pointer *int
|
||||||
|
Name string `fake:"{firstname}"` // Any available function all lowercase
|
||||||
|
Sentence string `fake:"{sentence:3}"` // Can call with parameters
|
||||||
|
RandStr string `fake:"{randomstring:[hello,world]}"`
|
||||||
|
Number string `fake:"{number:1,10}"` // Comma separated for multiple values
|
||||||
|
Regex string `fake:"{regex:[abcdef]{5}}"` // Generate string from regex
|
||||||
|
Map map[string]int `fakesize:"2"`
|
||||||
|
Array []string `fakesize:"2"`
|
||||||
|
ArrayRange []string `fakesize:"2,6"`
|
||||||
|
Bar Bar
|
||||||
|
Skip *string `fake:"skip"` // Set to "skip" to not generate data for
|
||||||
|
SkipAlt *string `fake:"-"` // Set to "-" to not generate data for
|
||||||
|
Created time.Time // Can take in a fake tag as well as a format tag
|
||||||
|
CreatedFormat time.Time `fake:"{year}-{month}-{day}" format:"2006-01-02"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Bar struct {
|
||||||
|
Name string
|
||||||
|
Number int
|
||||||
|
Float float32
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pass your struct as a pointer
|
||||||
|
var f Foo
|
||||||
|
err := gofakeit.Struct(&f)
|
||||||
|
|
||||||
|
fmt.Println(f.Str) // hrukpttuezptneuvunh
|
||||||
|
fmt.Println(f.Int) // -7825289004089916589
|
||||||
|
fmt.Println(*f.Pointer) // -343806609094473732
|
||||||
|
fmt.Println(f.Name) // fred
|
||||||
|
fmt.Println(f.Sentence) // Record river mind.
|
||||||
|
fmt.Println(fStr) // world
|
||||||
|
fmt.Println(f.Number) // 4
|
||||||
|
fmt.Println(f.Regex) // cbdfc
|
||||||
|
fmt.Println(f.Map) // map[PxLIo:52 lxwnqhqc:846]
|
||||||
|
fmt.Println(f.Array) // cbdfc
|
||||||
|
fmt.Printf("%+v", f.Bar) // {Name:QFpZ Number:-2882647639396178786 Float:1.7636692e+37}
|
||||||
|
fmt.Println(f.Skip) // <nil>
|
||||||
|
fmt.Println(f.Created.String()) // 1908-12-07 04:14:25.685339029 +0000 UTC
|
||||||
|
|
||||||
|
// Supported formats
|
||||||
|
// int, int8, int16, int32, int64,
|
||||||
|
// uint, uint8, uint16, uint32, uint64,
|
||||||
|
// float32, float64,
|
||||||
|
// bool, string,
|
||||||
|
// array, pointers, map
|
||||||
|
// time.Time // If setting time you can also set a format tag
|
||||||
|
// Nested Struct Fields and Embedded Fields
|
||||||
|
```
|
||||||
|
|
||||||
|
## Fakeable types
|
||||||
|
|
||||||
|
It is possible to extend a struct by implementing the `Fakeable` interface
|
||||||
|
in order to control the generation.
|
||||||
|
|
||||||
|
For example, this is useful when it is not possible to modify the struct that you want to fake by adding struct tags to a field but you still need to be able to control the generation process.
|
||||||
|
|
||||||
|
```go
|
||||||
|
// Custom string that you want to generate your own data for
|
||||||
|
type Friend string
|
||||||
|
|
||||||
|
func (c *Friend) Fake(f *gofakeit.Faker) (any, error) {
|
||||||
|
// Can call any other faker methods
|
||||||
|
return f.RandomString([]string{"billy", "fred", "susan"}), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Custom time that you want to generate your own data for
|
||||||
|
type Age time.Time
|
||||||
|
|
||||||
|
func (c *Age) Fake(f *gofakeit.Faker) (any, error) {
|
||||||
|
return f.DateRange(time.Now().AddDate(-100, 0, 0), time.Now().AddDate(-18, 0, 0)), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is the struct that we cannot modify to add struct tags
|
||||||
|
type User struct {
|
||||||
|
Name Friend
|
||||||
|
Age *Age
|
||||||
|
}
|
||||||
|
|
||||||
|
var u User
|
||||||
|
gofakeit.Struct(&u)
|
||||||
|
fmt.Printf("%s", f.Name) // billy
|
||||||
|
fmt.Printf("%s", f.Age) // 1990-12-07 04:14:25.685339029 +0000 UTC
|
||||||
|
```
|
||||||
|
|
||||||
|
## Custom Functions
|
||||||
|
|
||||||
|
In a lot of situations you may need to use your own random function usage for your specific needs.
|
||||||
|
|
||||||
|
If you would like to extend the usage of struct tags, generate function, available usages in the gofakeit server
|
||||||
|
or gofakeit command sub packages. You can do so via the AddFuncLookup. Each function has their own lookup, if
|
||||||
|
you need more reference examples you can look at each files lookups.
|
||||||
|
|
||||||
|
```go
|
||||||
|
// Simple
|
||||||
|
gofakeit.AddFuncLookup("friendname", gofakeit.Info{
|
||||||
|
Category: "custom",
|
||||||
|
Description: "Random friend name",
|
||||||
|
Example: "bill",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *gofakeit.MapParams, info *gofakeit.Info) (any, error) {
|
||||||
|
return f.RandomString([]string{"bill", "bob", "sally"}), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
// With Params
|
||||||
|
gofakeit.AddFuncLookup("jumbleword", gofakeit.Info{
|
||||||
|
Category: "jumbleword",
|
||||||
|
Description: "Take a word and jumble it up",
|
||||||
|
Example: "loredlowlh",
|
||||||
|
Output: "string",
|
||||||
|
Params: []gofakeit.Param{
|
||||||
|
{Field: "word", Type: "string", Description: "Word you want to jumble"},
|
||||||
|
},
|
||||||
|
Generate: func(f *Faker, m *gofakeit.MapParams, info *gofakeit.Info) (any, error) {
|
||||||
|
word, err := info.GetString(m, "word")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
split := strings.Split(word, "")
|
||||||
|
f.ShuffleStrings(split)
|
||||||
|
return strings.Join(split, ""), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
type Foo struct {
|
||||||
|
FriendName string `fake:"{friendname}"`
|
||||||
|
JumbleWord string `fake:"{jumbleword:helloworld}"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var f Foo
|
||||||
|
gofakeit.Struct(&f)
|
||||||
|
fmt.Printf("%s", f.FriendName) // bill
|
||||||
|
fmt.Printf("%s", f.JumbleWord) // loredlowlh
|
||||||
|
```
|
||||||
|
|
||||||
|
## Templates
|
||||||
|
|
||||||
|
Generate custom outputs using golang's template engine [https://pkg.go.dev/text/template](https://pkg.go.dev/text/template).
|
||||||
|
|
||||||
|
We have added all the available functions to the template engine as well as some additional ones that are useful for template building.
|
||||||
|
|
||||||
|
Additional Available Functions
|
||||||
|
```go
|
||||||
|
- ToUpper(s string) string // Make string upper case
|
||||||
|
- ToLower(s string) string // Make string lower case
|
||||||
|
- ToString(s any) // Convert to string
|
||||||
|
- ToDate(s string) time.Time // Convert string to date
|
||||||
|
- SpliceAny(args ...any) []any // Build a slice of anys, used with Weighted
|
||||||
|
- SpliceString(args ...string) []string // Build a slice of strings, used with Teams and RandomString
|
||||||
|
- SpliceUInt(args ...uint) []uint // Build a slice of uint, used with Dice and RandomUint
|
||||||
|
- SpliceInt(args ...int) []int // Build a slice of int, used with RandomInt
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Unavailable Gofakeit functions</summary>
|
||||||
|
|
||||||
|
```go
|
||||||
|
// Any functions that dont have a return value
|
||||||
|
- AnythingThatReturnsVoid(): void
|
||||||
|
|
||||||
|
// Not available to use in templates
|
||||||
|
- Template(co *TemplateOptions) ([]byte, error)
|
||||||
|
- RandomMapKey(mapI any) any
|
||||||
|
```
|
||||||
|
</details>
|
||||||
|
|
||||||
|
|
||||||
|
### Example Usages
|
||||||
|
|
||||||
|
```go
|
||||||
|
import "github.com/brianvoe/gofakeit/v7"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// Accessing the Lines variable from within the template.
|
||||||
|
template := `
|
||||||
|
Subject: {{RandomString (SliceString "Greetings" "Hello" "Hi")}}
|
||||||
|
|
||||||
|
Dear {{LastName}},
|
||||||
|
|
||||||
|
{{RandomString (SliceString "Greetings!" "Hello there!" "Hi, how are you?")}}
|
||||||
|
|
||||||
|
{{Paragraph 1 5 10 "\n\n"}}
|
||||||
|
|
||||||
|
{{RandomString (SliceString "Warm regards" "Best wishes" "Sincerely")}}
|
||||||
|
{{$person:=Person}}
|
||||||
|
{{$person.FirstName}} {{$person.LastName}}
|
||||||
|
{{$person.Email}}
|
||||||
|
{{$person.Phone}}
|
||||||
|
`
|
||||||
|
|
||||||
|
value, err := gofakeit.Template(template, &TemplateOptions{Data: 5})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(string(value))
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
```text
|
||||||
|
Subject: Hello
|
||||||
|
|
||||||
|
Dear Krajcik,
|
||||||
|
|
||||||
|
Greetings!
|
||||||
|
|
||||||
|
Quia voluptatem voluptatem voluptatem. Quia voluptatem voluptatem voluptatem. Quia voluptatem voluptatem voluptatem.
|
||||||
|
|
||||||
|
Warm regards
|
||||||
|
Kaitlyn Krajcik
|
||||||
|
kaitlynkrajcik@krajcik
|
||||||
|
570-245-7485
|
||||||
|
```
|
||||||
|
|
||||||
|
## Functions
|
||||||
|
|
||||||
|
All functions also exist as methods on the Faker struct
|
||||||
|
|
||||||
|
### File
|
||||||
|
|
||||||
|
Passing `nil` to `CSV`, `JSON` or `XML` will auto generate data using default values.
|
||||||
|
|
||||||
|
```go
|
||||||
|
CSV(co *CSVOptions) ([]byte, error)
|
||||||
|
JSON(jo *JSONOptions) ([]byte, error)
|
||||||
|
XML(xo *XMLOptions) ([]byte, error)
|
||||||
|
FileExtension() string
|
||||||
|
FileMimeType() string
|
||||||
|
```
|
||||||
|
|
||||||
|
### Template
|
||||||
|
|
||||||
|
Passing `nil` will auto generate data using default values.
|
||||||
|
|
||||||
|
```go
|
||||||
|
Template(co *TemplateOptions) (string, error)
|
||||||
|
Markdown(co *MarkdownOptions) (string, error)
|
||||||
|
EmailText(co *EmailOptions) (string, error)
|
||||||
|
FixedWidth(co *FixedWidthOptions) (string, error)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Product
|
||||||
|
|
||||||
|
|
||||||
|
```go
|
||||||
|
Product() *ProductInfo
|
||||||
|
ProductName() string
|
||||||
|
ProductDescription() string
|
||||||
|
ProductCategory() string
|
||||||
|
ProductFeature() string
|
||||||
|
ProductMaterial() string
|
||||||
|
ProductUPC() string
|
||||||
|
ProductAudience() string
|
||||||
|
ProductDimension() string
|
||||||
|
ProductUseCase() string
|
||||||
|
ProductBenefit() string
|
||||||
|
ProductSuffix() string
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Person
|
||||||
|
|
||||||
|
```go
|
||||||
|
Person() *PersonInfo
|
||||||
|
Name() string
|
||||||
|
NamePrefix() string
|
||||||
|
NameSuffix() string
|
||||||
|
FirstName() string
|
||||||
|
MiddleName() string
|
||||||
|
LastName() string
|
||||||
|
Gender() string
|
||||||
|
SSN() string
|
||||||
|
Hobby() string
|
||||||
|
Contact() *ContactInfo
|
||||||
|
Email() string
|
||||||
|
Phone() string
|
||||||
|
PhoneFormatted() string
|
||||||
|
Teams(peopleArray []string, teamsArray []string) map[string][]string
|
||||||
|
```
|
||||||
|
|
||||||
|
### Generate
|
||||||
|
|
||||||
|
```go
|
||||||
|
Struct(v any)
|
||||||
|
Slice(v any)
|
||||||
|
Map() map[string]any
|
||||||
|
Generate(value string) string
|
||||||
|
Regex(value string) string
|
||||||
|
```
|
||||||
|
|
||||||
|
### Auth
|
||||||
|
|
||||||
|
```go
|
||||||
|
Username() string
|
||||||
|
Password(lower bool, upper bool, numeric bool, special bool, space bool, num int) string
|
||||||
|
```
|
||||||
|
|
||||||
|
### Address
|
||||||
|
|
||||||
|
```go
|
||||||
|
Address() *AddressInfo
|
||||||
|
City() string
|
||||||
|
Country() string
|
||||||
|
CountryAbr() string
|
||||||
|
State() string
|
||||||
|
StateAbr() string
|
||||||
|
Street() string
|
||||||
|
StreetName() string
|
||||||
|
StreetNumber() string
|
||||||
|
StreetPrefix() string
|
||||||
|
StreetSuffix() string
|
||||||
|
Zip() string
|
||||||
|
Latitude() float64
|
||||||
|
LatitudeInRange(min, max float64) (float64, error)
|
||||||
|
Longitude() float64
|
||||||
|
LongitudeInRange(min, max float64) (float64, error)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Game
|
||||||
|
|
||||||
|
```go
|
||||||
|
Gamertag() string
|
||||||
|
Dice(numDice uint, sides []uint) []uint
|
||||||
|
```
|
||||||
|
|
||||||
|
### Beer
|
||||||
|
|
||||||
|
```go
|
||||||
|
BeerAlcohol() string
|
||||||
|
BeerBlg() string
|
||||||
|
BeerHop() string
|
||||||
|
BeerIbu() string
|
||||||
|
BeerMalt() string
|
||||||
|
BeerName() string
|
||||||
|
BeerStyle() string
|
||||||
|
BeerYeast() string
|
||||||
|
```
|
||||||
|
|
||||||
|
### Car
|
||||||
|
|
||||||
|
```go
|
||||||
|
Car() *CarInfo
|
||||||
|
CarMaker() string
|
||||||
|
CarModel() string
|
||||||
|
CarType() string
|
||||||
|
CarFuelType() string
|
||||||
|
CarTransmissionType() string
|
||||||
|
```
|
||||||
|
|
||||||
|
### Words
|
||||||
|
|
||||||
|
```go
|
||||||
|
// Nouns
|
||||||
|
Noun() string
|
||||||
|
NounCommon() string
|
||||||
|
NounConcrete() string
|
||||||
|
NounAbstract() string
|
||||||
|
NounCollectivePeople() string
|
||||||
|
NounCollectiveAnimal() string
|
||||||
|
NounCollectiveThing() string
|
||||||
|
NounCountable() string
|
||||||
|
NounUncountable() string
|
||||||
|
|
||||||
|
// Verbs
|
||||||
|
Verb() string
|
||||||
|
VerbAction() string
|
||||||
|
VerbLinking() string
|
||||||
|
VerbHelping() string
|
||||||
|
|
||||||
|
// Adverbs
|
||||||
|
Adverb() string
|
||||||
|
AdverbManner() string
|
||||||
|
AdverbDegree() string
|
||||||
|
AdverbPlace() string
|
||||||
|
AdverbTimeDefinite() string
|
||||||
|
AdverbTimeIndefinite() string
|
||||||
|
AdverbFrequencyDefinite() string
|
||||||
|
AdverbFrequencyIndefinite() string
|
||||||
|
|
||||||
|
// Propositions
|
||||||
|
Preposition() string
|
||||||
|
PrepositionSimple() string
|
||||||
|
PrepositionDouble() string
|
||||||
|
PrepositionCompound() string
|
||||||
|
|
||||||
|
// Adjectives
|
||||||
|
Adjective() string
|
||||||
|
AdjectiveDescriptive() string
|
||||||
|
AdjectiveQuantitative() string
|
||||||
|
AdjectiveProper() string
|
||||||
|
AdjectiveDemonstrative() string
|
||||||
|
AdjectivePossessive() string
|
||||||
|
AdjectiveInterrogative() string
|
||||||
|
AdjectiveIndefinite() string
|
||||||
|
|
||||||
|
// Pronouns
|
||||||
|
Pronoun() string
|
||||||
|
PronounPersonal() string
|
||||||
|
PronounObject() string
|
||||||
|
PronounPossessive() string
|
||||||
|
PronounReflective() string
|
||||||
|
PronounDemonstrative() string
|
||||||
|
PronounInterrogative() string
|
||||||
|
PronounRelative() string
|
||||||
|
|
||||||
|
// Connectives
|
||||||
|
Connective() string
|
||||||
|
ConnectiveTime() string
|
||||||
|
ConnectiveComparative() string
|
||||||
|
ConnectiveComplaint() string
|
||||||
|
ConnectiveListing() string
|
||||||
|
ConnectiveCasual() string
|
||||||
|
ConnectiveExamplify() string
|
||||||
|
|
||||||
|
// Words
|
||||||
|
Word() string
|
||||||
|
|
||||||
|
// Sentences
|
||||||
|
Sentence(wordCount int) string
|
||||||
|
Paragraph(paragraphCount int, sentenceCount int, wordCount int, separator string) string
|
||||||
|
LoremIpsumWord() string
|
||||||
|
LoremIpsumSentence(wordCount int) string
|
||||||
|
LoremIpsumParagraph(paragraphCount int, sentenceCount int, wordCount int, separator string) string
|
||||||
|
Question() string
|
||||||
|
Quote() string
|
||||||
|
Phrase() string
|
||||||
|
```
|
||||||
|
|
||||||
|
### Foods
|
||||||
|
|
||||||
|
```go
|
||||||
|
Fruit() string
|
||||||
|
Vegetable() string
|
||||||
|
Breakfast() string
|
||||||
|
Lunch() string
|
||||||
|
Dinner() string
|
||||||
|
Snack() string
|
||||||
|
Dessert() string
|
||||||
|
```
|
||||||
|
|
||||||
|
### Misc
|
||||||
|
|
||||||
|
```go
|
||||||
|
Bool() bool
|
||||||
|
UUID() string
|
||||||
|
Weighted(options []any, weights []float32) (any, error)
|
||||||
|
FlipACoin() string
|
||||||
|
RandomMapKey(mapI any) any
|
||||||
|
ShuffleAnySlice(v any)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Colors
|
||||||
|
|
||||||
|
```go
|
||||||
|
Color() string
|
||||||
|
HexColor() string
|
||||||
|
RGBColor() []int
|
||||||
|
SafeColor() string
|
||||||
|
NiceColors() string
|
||||||
|
```
|
||||||
|
|
||||||
|
### Images
|
||||||
|
|
||||||
|
```go
|
||||||
|
Image(width int, height int) *img.RGBA
|
||||||
|
ImageJpeg(width int, height int) []byte
|
||||||
|
ImagePng(width int, height int) []byte
|
||||||
|
```
|
||||||
|
|
||||||
|
### Internet
|
||||||
|
|
||||||
|
```go
|
||||||
|
URL() string
|
||||||
|
DomainName() string
|
||||||
|
DomainSuffix() string
|
||||||
|
IPv4Address() string
|
||||||
|
IPv6Address() string
|
||||||
|
MacAddress() string
|
||||||
|
HTTPStatusCode() string
|
||||||
|
HTTPStatusCodeSimple() int
|
||||||
|
LogLevel(logType string) string
|
||||||
|
HTTPMethod() string
|
||||||
|
HTTPVersion() string
|
||||||
|
UserAgent() string
|
||||||
|
ChromeUserAgent() string
|
||||||
|
FirefoxUserAgent() string
|
||||||
|
OperaUserAgent() string
|
||||||
|
SafariUserAgent() string
|
||||||
|
```
|
||||||
|
|
||||||
|
### HTML
|
||||||
|
|
||||||
|
```go
|
||||||
|
InputName() string
|
||||||
|
Svg(options *SVGOptions) string
|
||||||
|
```
|
||||||
|
|
||||||
|
### Date/Time
|
||||||
|
|
||||||
|
```go
|
||||||
|
Date() time.Time
|
||||||
|
PastDate() time.Time
|
||||||
|
FutureDate() time.Time
|
||||||
|
DateRange(start, end time.Time) time.Time
|
||||||
|
NanoSecond() int
|
||||||
|
Second() int
|
||||||
|
Minute() int
|
||||||
|
Hour() int
|
||||||
|
Month() int
|
||||||
|
MonthString() string
|
||||||
|
Day() int
|
||||||
|
WeekDay() string
|
||||||
|
Year() int
|
||||||
|
TimeZone() string
|
||||||
|
TimeZoneAbv() string
|
||||||
|
TimeZoneFull() string
|
||||||
|
TimeZoneOffset() float32
|
||||||
|
TimeZoneRegion() string
|
||||||
|
```
|
||||||
|
|
||||||
|
### Payment
|
||||||
|
|
||||||
|
```go
|
||||||
|
Price(min, max float64) float64
|
||||||
|
CreditCard() *CreditCardInfo
|
||||||
|
CreditCardCvv() string
|
||||||
|
CreditCardExp() string
|
||||||
|
CreditCardNumber(*CreditCardOptions) string
|
||||||
|
CreditCardType() string
|
||||||
|
Currency() *CurrencyInfo
|
||||||
|
CurrencyLong() string
|
||||||
|
CurrencyShort() string
|
||||||
|
AchRouting() string
|
||||||
|
AchAccount() string
|
||||||
|
BitcoinAddress() string
|
||||||
|
BitcoinPrivateKey() string
|
||||||
|
```
|
||||||
|
|
||||||
|
### Finance
|
||||||
|
|
||||||
|
```go
|
||||||
|
Cusip() string
|
||||||
|
Isin() string
|
||||||
|
```
|
||||||
|
|
||||||
|
### Company
|
||||||
|
|
||||||
|
```go
|
||||||
|
BS() string
|
||||||
|
Blurb() string
|
||||||
|
BuzzWord() string
|
||||||
|
Company() string
|
||||||
|
CompanySuffix() string
|
||||||
|
Job() *JobInfo
|
||||||
|
JobDescriptor() string
|
||||||
|
JobLevel() string
|
||||||
|
JobTitle() string
|
||||||
|
Slogan() string
|
||||||
|
```
|
||||||
|
|
||||||
|
### Hacker
|
||||||
|
|
||||||
|
```go
|
||||||
|
HackerAbbreviation() string
|
||||||
|
HackerAdjective() string
|
||||||
|
Hackeringverb() string
|
||||||
|
HackerNoun() string
|
||||||
|
HackerPhrase() string
|
||||||
|
HackerVerb() string
|
||||||
|
```
|
||||||
|
|
||||||
|
### Hipster
|
||||||
|
|
||||||
|
```go
|
||||||
|
HipsterWord() string
|
||||||
|
HipsterSentence(wordCount int) string
|
||||||
|
HipsterParagraph(paragraphCount int, sentenceCount int, wordCount int, separator string) string
|
||||||
|
```
|
||||||
|
|
||||||
|
### App
|
||||||
|
|
||||||
|
```go
|
||||||
|
AppName() string
|
||||||
|
AppVersion() string
|
||||||
|
AppAuthor() string
|
||||||
|
```
|
||||||
|
|
||||||
|
### Animal
|
||||||
|
|
||||||
|
```go
|
||||||
|
PetName() string
|
||||||
|
Animal() string
|
||||||
|
AnimalType() string
|
||||||
|
FarmAnimal() string
|
||||||
|
Cat() string
|
||||||
|
Dog() string
|
||||||
|
Bird() string
|
||||||
|
```
|
||||||
|
|
||||||
|
### Emoji
|
||||||
|
|
||||||
|
```go
|
||||||
|
Emoji() string
|
||||||
|
EmojiDescription() string
|
||||||
|
EmojiCategory() string
|
||||||
|
EmojiAlias() string
|
||||||
|
EmojiTag() string
|
||||||
|
```
|
||||||
|
|
||||||
|
### Language
|
||||||
|
|
||||||
|
```go
|
||||||
|
Language() string
|
||||||
|
LanguageAbbreviation() string
|
||||||
|
ProgrammingLanguage() string
|
||||||
|
ProgrammingLanguageBest() string
|
||||||
|
```
|
||||||
|
|
||||||
|
### Number
|
||||||
|
|
||||||
|
```go
|
||||||
|
Number(min int, max int) int
|
||||||
|
Int() int
|
||||||
|
IntN(n int) int
|
||||||
|
Int8() int8
|
||||||
|
Int16() int16
|
||||||
|
Int32() int32
|
||||||
|
Int64() int64
|
||||||
|
Uint() uint
|
||||||
|
UintN(n uint) uint
|
||||||
|
Uint8() uint8
|
||||||
|
Uint16() uint16
|
||||||
|
Uint32() uint32
|
||||||
|
Uint64() uint64
|
||||||
|
Float32() float32
|
||||||
|
Float32Range(min, max float32) float32
|
||||||
|
Float64() float64
|
||||||
|
Float64Range(min, max float64) float64
|
||||||
|
ShuffleInts(a []int)
|
||||||
|
RandomInt(i []int) int
|
||||||
|
HexUint(bitsize int) string
|
||||||
|
```
|
||||||
|
|
||||||
|
### String
|
||||||
|
|
||||||
|
```go
|
||||||
|
Digit() string
|
||||||
|
DigitN(n uint) string
|
||||||
|
Letter() string
|
||||||
|
LetterN(n uint) string
|
||||||
|
Lexify(str string) string
|
||||||
|
Numerify(str string) string
|
||||||
|
ShuffleStrings(a []string)
|
||||||
|
RandomString(a []string) string
|
||||||
|
```
|
||||||
|
|
||||||
|
### Celebrity
|
||||||
|
|
||||||
|
```go
|
||||||
|
CelebrityActor() string
|
||||||
|
CelebrityBusiness() string
|
||||||
|
CelebritySport() string
|
||||||
|
```
|
||||||
|
|
||||||
|
### Minecraft
|
||||||
|
|
||||||
|
```go
|
||||||
|
MinecraftOre() string
|
||||||
|
MinecraftWood() string
|
||||||
|
MinecraftArmorTier() string
|
||||||
|
MinecraftArmorPart() string
|
||||||
|
MinecraftWeapon() string
|
||||||
|
MinecraftTool() string
|
||||||
|
MinecraftDye() string
|
||||||
|
MinecraftFood() string
|
||||||
|
MinecraftAnimal() string
|
||||||
|
MinecraftVillagerJob() string
|
||||||
|
MinecraftVillagerStation() string
|
||||||
|
MinecraftVillagerLevel() string
|
||||||
|
MinecraftMobPassive() string
|
||||||
|
MinecraftMobNeutral() string
|
||||||
|
MinecraftMobHostile() string
|
||||||
|
MinecraftMobBoss() string
|
||||||
|
MinecraftBiome() string
|
||||||
|
MinecraftWeather() string
|
||||||
|
```
|
||||||
|
|
||||||
|
### Book
|
||||||
|
|
||||||
|
```go
|
||||||
|
Book() *BookInfo
|
||||||
|
BookTitle() string
|
||||||
|
BookAuthor() string
|
||||||
|
BookGenre() string
|
||||||
|
```
|
||||||
|
|
||||||
|
### Movie
|
||||||
|
|
||||||
|
```go
|
||||||
|
Movie() *MovieInfo
|
||||||
|
MovieName() string
|
||||||
|
MovieGenre() string
|
||||||
|
```
|
||||||
|
|
||||||
|
### Error
|
||||||
|
|
||||||
|
```go
|
||||||
|
Error() error
|
||||||
|
ErrorDatabase() error
|
||||||
|
ErrorGRPC() error
|
||||||
|
ErrorHTTP() error
|
||||||
|
ErrorHTTPClient() error
|
||||||
|
ErrorHTTPServer() error
|
||||||
|
ErrorInput() error
|
||||||
|
ErrorRuntime() error
|
||||||
|
```
|
||||||
|
|
||||||
|
### School
|
||||||
|
|
||||||
|
```go
|
||||||
|
School() string
|
||||||
|
```
|
||||||
|
|
@ -0,0 +1,420 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AddressInfo is a struct full of address information
|
||||||
|
type AddressInfo struct {
|
||||||
|
Address string `json:"address" xml:"address"`
|
||||||
|
Street string `json:"street" xml:"street"`
|
||||||
|
City string `json:"city" xml:"city"`
|
||||||
|
State string `json:"state" xml:"state"`
|
||||||
|
Zip string `json:"zip" xml:"zip"`
|
||||||
|
Country string `json:"country" xml:"country"`
|
||||||
|
Latitude float64 `json:"latitude" xml:"latitude"`
|
||||||
|
Longitude float64 `json:"longitude" xml:"longitude"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Address will generate a struct of address information
|
||||||
|
func Address() *AddressInfo { return address(GlobalFaker) }
|
||||||
|
|
||||||
|
// Address will generate a struct of address information
|
||||||
|
func (f *Faker) Address() *AddressInfo { return address(f) }
|
||||||
|
|
||||||
|
func address(f *Faker) *AddressInfo {
|
||||||
|
street := street(f)
|
||||||
|
city := city(f)
|
||||||
|
state := state(f)
|
||||||
|
zip := zip(f)
|
||||||
|
|
||||||
|
return &AddressInfo{
|
||||||
|
Address: street + ", " + city + ", " + state + " " + zip,
|
||||||
|
Street: street,
|
||||||
|
City: city,
|
||||||
|
State: state,
|
||||||
|
Zip: zip,
|
||||||
|
Country: country(f),
|
||||||
|
Latitude: latitude(f),
|
||||||
|
Longitude: longitude(f),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Street will generate a random address street string
|
||||||
|
func Street() string { return street(GlobalFaker) }
|
||||||
|
|
||||||
|
// Street will generate a random address street string
|
||||||
|
func (f *Faker) Street() string { return street(f) }
|
||||||
|
|
||||||
|
func street(f *Faker) string {
|
||||||
|
var street = ""
|
||||||
|
switch randInt := randIntRange(f, 1, 2); randInt {
|
||||||
|
case 1:
|
||||||
|
street = streetNumber(f) + " " + streetPrefix(f) + " " + streetName(f) + streetSuffix(f)
|
||||||
|
case 2:
|
||||||
|
street = streetNumber(f) + " " + streetName(f) + streetSuffix(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
return street
|
||||||
|
}
|
||||||
|
|
||||||
|
// StreetNumber will generate a random address street number string
|
||||||
|
func StreetNumber() string { return streetNumber(GlobalFaker) }
|
||||||
|
|
||||||
|
// StreetNumber will generate a random address street number string
|
||||||
|
func (f *Faker) StreetNumber() string { return streetNumber(f) }
|
||||||
|
|
||||||
|
func streetNumber(f *Faker) string {
|
||||||
|
return strings.TrimLeft(replaceWithNumbers(f, getRandValue(f, []string{"address", "number"})), "0")
|
||||||
|
}
|
||||||
|
|
||||||
|
// StreetPrefix will generate a random address street prefix string
|
||||||
|
func StreetPrefix() string { return streetPrefix(GlobalFaker) }
|
||||||
|
|
||||||
|
// StreetPrefix will generate a random address street prefix string
|
||||||
|
func (f *Faker) StreetPrefix() string { return streetPrefix(f) }
|
||||||
|
|
||||||
|
func streetPrefix(f *Faker) string { return getRandValue(f, []string{"address", "street_prefix"}) }
|
||||||
|
|
||||||
|
// StreetName will generate a random address street name string
|
||||||
|
func StreetName() string { return streetName(GlobalFaker) }
|
||||||
|
|
||||||
|
// StreetName will generate a random address street name string
|
||||||
|
func (f *Faker) StreetName() string { return streetName(f) }
|
||||||
|
|
||||||
|
func streetName(f *Faker) string { return getRandValue(f, []string{"address", "street_name"}) }
|
||||||
|
|
||||||
|
// StreetSuffix will generate a random address street suffix string
|
||||||
|
func StreetSuffix() string { return streetSuffix(GlobalFaker) }
|
||||||
|
|
||||||
|
// StreetSuffix will generate a random address street suffix string
|
||||||
|
func (f *Faker) StreetSuffix() string { return streetSuffix(f) }
|
||||||
|
|
||||||
|
func streetSuffix(f *Faker) string { return getRandValue(f, []string{"address", "street_suffix"}) }
|
||||||
|
|
||||||
|
// City will generate a random city string
|
||||||
|
func City() string { return city(GlobalFaker) }
|
||||||
|
|
||||||
|
// City will generate a random city string
|
||||||
|
func (f *Faker) City() string { return city(f) }
|
||||||
|
|
||||||
|
func city(f *Faker) string { return getRandValue(f, []string{"address", "city"}) }
|
||||||
|
|
||||||
|
// State will generate a random state string
|
||||||
|
func State() string { return state(GlobalFaker) }
|
||||||
|
|
||||||
|
// State will generate a random state string
|
||||||
|
func (f *Faker) State() string { return state(f) }
|
||||||
|
|
||||||
|
func state(f *Faker) string { return getRandValue(f, []string{"address", "state"}) }
|
||||||
|
|
||||||
|
// StateAbr will generate a random abbreviated state string
|
||||||
|
func StateAbr() string { return stateAbr(GlobalFaker) }
|
||||||
|
|
||||||
|
// StateAbr will generate a random abbreviated state string
|
||||||
|
func (f *Faker) StateAbr() string { return stateAbr(f) }
|
||||||
|
|
||||||
|
func stateAbr(f *Faker) string { return getRandValue(f, []string{"address", "state_abr"}) }
|
||||||
|
|
||||||
|
// Zip will generate a random Zip code string
|
||||||
|
func Zip() string { return zip(GlobalFaker) }
|
||||||
|
|
||||||
|
// Zip will generate a random Zip code string
|
||||||
|
func (f *Faker) Zip() string { return zip(f) }
|
||||||
|
|
||||||
|
func zip(f *Faker) string {
|
||||||
|
return replaceWithNumbers(f, getRandValue(f, []string{"address", "zip"}))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Country will generate a random country string
|
||||||
|
func Country() string { return country(GlobalFaker) }
|
||||||
|
|
||||||
|
// Country will generate a random country string
|
||||||
|
func (f *Faker) Country() string { return country(f) }
|
||||||
|
|
||||||
|
func country(f *Faker) string { return getRandValue(f, []string{"address", "country"}) }
|
||||||
|
|
||||||
|
// CountryAbr will generate a random abbreviated country string
|
||||||
|
func CountryAbr() string { return countryAbr(GlobalFaker) }
|
||||||
|
|
||||||
|
// CountryAbr will generate a random abbreviated country string
|
||||||
|
func (f *Faker) CountryAbr() string { return countryAbr(f) }
|
||||||
|
|
||||||
|
func countryAbr(f *Faker) string { return getRandValue(f, []string{"address", "country_abr"}) }
|
||||||
|
|
||||||
|
// Latitude will generate a random latitude float64
|
||||||
|
func Latitude() float64 { return latitude(GlobalFaker) }
|
||||||
|
|
||||||
|
// Latitude will generate a random latitude float64
|
||||||
|
func (f *Faker) Latitude() float64 { return latitude(f) }
|
||||||
|
|
||||||
|
func latitude(f *Faker) float64 { return toFixed((f.Float64()*180)-90, 6) }
|
||||||
|
|
||||||
|
// LatitudeInRange will generate a random latitude within the input range
|
||||||
|
func LatitudeInRange(min, max float64) (float64, error) {
|
||||||
|
return latitudeInRange(GlobalFaker, min, max)
|
||||||
|
}
|
||||||
|
|
||||||
|
// LatitudeInRange will generate a random latitude within the input range
|
||||||
|
func (f *Faker) LatitudeInRange(min, max float64) (float64, error) {
|
||||||
|
return latitudeInRange(f, min, max)
|
||||||
|
}
|
||||||
|
|
||||||
|
func latitudeInRange(f *Faker, min, max float64) (float64, error) {
|
||||||
|
if min > max || min < -90 || min > 90 || max < -90 || max > 90 {
|
||||||
|
return 0, errors.New("invalid min or max range, must be valid floats and between -90 and 90")
|
||||||
|
}
|
||||||
|
return toFixed(float64Range(f, min, max), 6), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Longitude will generate a random longitude float64
|
||||||
|
func Longitude() float64 { return longitude(GlobalFaker) }
|
||||||
|
|
||||||
|
// Longitude will generate a random longitude float64
|
||||||
|
func (f *Faker) Longitude() float64 { return longitude(f) }
|
||||||
|
|
||||||
|
func longitude(f *Faker) float64 { return toFixed((f.Float64()*360)-180, 6) }
|
||||||
|
|
||||||
|
// LongitudeInRange will generate a random longitude within the input range
|
||||||
|
func LongitudeInRange(min, max float64) (float64, error) {
|
||||||
|
return longitudeInRange(GlobalFaker, min, max)
|
||||||
|
}
|
||||||
|
|
||||||
|
// LongitudeInRange will generate a random longitude within the input range
|
||||||
|
func (f *Faker) LongitudeInRange(min, max float64) (float64, error) {
|
||||||
|
return longitudeInRange(f, min, max)
|
||||||
|
}
|
||||||
|
|
||||||
|
func longitudeInRange(f *Faker, min, max float64) (float64, error) {
|
||||||
|
if min > max || min < -180 || min > 180 || max < -180 || max > 180 {
|
||||||
|
return 0, errors.New("invalid min or max range, must be valid floats and between -180 and 180")
|
||||||
|
}
|
||||||
|
return toFixed(float64Range(f, min, max), 6), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func addAddressLookup() {
|
||||||
|
AddFuncLookup("address", Info{
|
||||||
|
Display: "Address",
|
||||||
|
Category: "address",
|
||||||
|
Description: "Residential location including street, city, state, country and postal code",
|
||||||
|
Example: `{
|
||||||
|
"address": "364 Unionsville, Norfolk, Ohio 99536",
|
||||||
|
"street": "364 Unionsville",
|
||||||
|
"city": "Norfolk",
|
||||||
|
"state": "Ohio",
|
||||||
|
"zip": "99536",
|
||||||
|
"country": "Lesotho",
|
||||||
|
"latitude": 88.792592,
|
||||||
|
"longitude": 174.504681
|
||||||
|
}`,
|
||||||
|
Output: "map[string]any",
|
||||||
|
ContentType: "application/json",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return address(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("city", Info{
|
||||||
|
Display: "City",
|
||||||
|
Category: "address",
|
||||||
|
Description: "Part of a country with significant population, often a central hub for culture and commerce",
|
||||||
|
Example: "Marcelside",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return city(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("country", Info{
|
||||||
|
Display: "Country",
|
||||||
|
Category: "address",
|
||||||
|
Description: "Nation with its own government and defined territory",
|
||||||
|
Example: "United States of America",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return country(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("countryabr", Info{
|
||||||
|
Display: "Country Abbreviation",
|
||||||
|
Category: "address",
|
||||||
|
Description: "Shortened 2-letter form of a country's name",
|
||||||
|
Example: "US",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return countryAbr(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("state", Info{
|
||||||
|
Display: "State",
|
||||||
|
Category: "address",
|
||||||
|
Description: "Governmental division within a country, often having its own laws and government",
|
||||||
|
Example: "Illinois",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return state(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("stateabr", Info{
|
||||||
|
Display: "State Abbreviation",
|
||||||
|
Category: "address",
|
||||||
|
Description: "Shortened 2-letter form of a country's state",
|
||||||
|
Example: "IL",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return stateAbr(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("street", Info{
|
||||||
|
Display: "Street",
|
||||||
|
Category: "address",
|
||||||
|
Description: "Public road in a city or town, typically with houses and buildings on each side",
|
||||||
|
Example: "364 East Rapidsborough",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return street(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("streetname", Info{
|
||||||
|
Display: "Street Name",
|
||||||
|
Category: "address",
|
||||||
|
Description: "Name given to a specific road or street",
|
||||||
|
Example: "View",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return streetName(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("streetnumber", Info{
|
||||||
|
Display: "Street Number",
|
||||||
|
Category: "address",
|
||||||
|
Description: "Numerical identifier assigned to a street",
|
||||||
|
Example: "13645",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return streetNumber(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("streetprefix", Info{
|
||||||
|
Display: "Street Prefix",
|
||||||
|
Category: "address",
|
||||||
|
Description: "Directional or descriptive term preceding a street name, like 'East' or 'Main'",
|
||||||
|
Example: "Lake",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return streetPrefix(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("streetsuffix", Info{
|
||||||
|
Display: "Street Suffix",
|
||||||
|
Category: "address",
|
||||||
|
Description: "Designation at the end of a street name indicating type, like 'Avenue' or 'Street'",
|
||||||
|
Example: "land",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return streetSuffix(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("zip", Info{
|
||||||
|
Display: "Zip",
|
||||||
|
Category: "address",
|
||||||
|
Description: "Numerical code for postal address sorting, specific to a geographic area",
|
||||||
|
Example: "13645",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return zip(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("latitude", Info{
|
||||||
|
Display: "Latitude",
|
||||||
|
Category: "address",
|
||||||
|
Description: "Geographic coordinate specifying north-south position on Earth's surface",
|
||||||
|
Example: "-73.534056",
|
||||||
|
Output: "float",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return latitude(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("latituderange", Info{
|
||||||
|
Display: "Latitude Range",
|
||||||
|
Category: "address",
|
||||||
|
Description: "Latitude number between the given range (default min=0, max=90)",
|
||||||
|
Example: "22.921026",
|
||||||
|
Output: "float",
|
||||||
|
Params: []Param{
|
||||||
|
{Field: "min", Display: "Min", Type: "float", Default: "0", Description: "Minimum range"},
|
||||||
|
{Field: "max", Display: "Max", Type: "float", Default: "90", Description: "Maximum range"},
|
||||||
|
},
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
min, err := info.GetFloat64(m, "min")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
max, err := info.GetFloat64(m, "max")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
rangeOut, err := latitudeInRange(f, min, max)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return rangeOut, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("longitude", Info{
|
||||||
|
Display: "Longitude",
|
||||||
|
Category: "address",
|
||||||
|
Description: "Geographic coordinate indicating east-west position on Earth's surface",
|
||||||
|
Example: "-147.068112",
|
||||||
|
Output: "float",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return longitude(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("longituderange", Info{
|
||||||
|
Display: "Longitude Range",
|
||||||
|
Category: "address",
|
||||||
|
Description: "Longitude number between the given range (default min=0, max=180)",
|
||||||
|
Example: "-8.170450",
|
||||||
|
Output: "float",
|
||||||
|
Params: []Param{
|
||||||
|
{Field: "min", Display: "Min", Type: "float", Default: "0", Description: "Minimum range"},
|
||||||
|
{Field: "max", Display: "Max", Type: "float", Default: "180", Description: "Maximum range"},
|
||||||
|
},
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
min, err := info.GetFloat64(m, "min")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
max, err := info.GetFloat64(m, "max")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
rangeOut, err := longitudeInRange(f, min, max)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return rangeOut, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,178 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
// PetName will return a random fun pet name
|
||||||
|
func PetName() string {
|
||||||
|
return petName(GlobalFaker)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PetName will return a random fun pet name
|
||||||
|
func (f *Faker) PetName() string {
|
||||||
|
return petName(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func petName(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"animal", "petname"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Animal will return a random animal
|
||||||
|
func Animal() string {
|
||||||
|
return animal(GlobalFaker)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Animal will return a random animal
|
||||||
|
func (f *Faker) Animal() string {
|
||||||
|
return animal(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func animal(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"animal", "animal"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// AnimalType will return a random animal type
|
||||||
|
func AnimalType() string {
|
||||||
|
return animalType(GlobalFaker)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AnimalType will return a random animal type
|
||||||
|
func (f *Faker) AnimalType() string {
|
||||||
|
return animalType(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func animalType(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"animal", "type"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// FarmAnimal will return a random animal that usually lives on a farm
|
||||||
|
func FarmAnimal() string {
|
||||||
|
return farmAnimal(GlobalFaker)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FarmAnimal will return a random animal that usually lives on a farm
|
||||||
|
func (f *Faker) FarmAnimal() string {
|
||||||
|
return farmAnimal(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func farmAnimal(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"animal", "farm"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cat will return a random cat breed
|
||||||
|
func Cat() string {
|
||||||
|
return cat(GlobalFaker)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cat will return a random cat breed
|
||||||
|
func (f *Faker) Cat() string {
|
||||||
|
return cat(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func cat(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"animal", "cat"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dog will return a random dog breed
|
||||||
|
func Dog() string {
|
||||||
|
return dog(GlobalFaker)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dog will return a random dog breed
|
||||||
|
func (f *Faker) Dog() string {
|
||||||
|
return dog(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func dog(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"animal", "dog"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bird will return a random bird species
|
||||||
|
func Bird() string {
|
||||||
|
return bird(GlobalFaker)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bird will return a random bird species
|
||||||
|
func (f *Faker) Bird() string {
|
||||||
|
return bird(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func bird(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"animal", "bird"})
|
||||||
|
}
|
||||||
|
|
||||||
|
func addAnimalLookup() {
|
||||||
|
AddFuncLookup("petname", Info{
|
||||||
|
Display: "Pet Name",
|
||||||
|
Category: "animal",
|
||||||
|
Description: "Affectionate nickname given to a pet",
|
||||||
|
Example: "Ozzy Pawsborne",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return petName(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("animal", Info{
|
||||||
|
Display: "Animal",
|
||||||
|
Category: "animal",
|
||||||
|
Description: "Living creature with the ability to move, eat, and interact with its environment",
|
||||||
|
Example: "elk",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return animal(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("animaltype", Info{
|
||||||
|
Display: "Animal Type",
|
||||||
|
Category: "animal",
|
||||||
|
Description: "Type of animal, such as mammals, birds, reptiles, etc.",
|
||||||
|
Example: "amphibians",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return animalType(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("farmanimal", Info{
|
||||||
|
Display: "Farm Animal",
|
||||||
|
Category: "animal",
|
||||||
|
Description: "Animal name commonly found on a farm",
|
||||||
|
Example: "Chicken",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return farmAnimal(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("cat", Info{
|
||||||
|
Display: "Cat",
|
||||||
|
Category: "animal",
|
||||||
|
Description: "Various breeds that define different cats",
|
||||||
|
Example: "Chausie",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return cat(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("dog", Info{
|
||||||
|
Display: "Dog",
|
||||||
|
Category: "animal",
|
||||||
|
Description: "Various breeds that define different dogs",
|
||||||
|
Example: "Norwich Terrier",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return dog(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("bird", Info{
|
||||||
|
Display: "Bird",
|
||||||
|
Category: "animal",
|
||||||
|
Description: "Distinct species of birds",
|
||||||
|
Example: "goose",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return bird(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,96 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AppName will generate a random app name
|
||||||
|
func AppName() string {
|
||||||
|
return appName(GlobalFaker)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AppName will generate a random app name
|
||||||
|
func (f *Faker) AppName() string {
|
||||||
|
return appName(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func appName(f *Faker) string {
|
||||||
|
name := ""
|
||||||
|
switch number(f, 1, 3) {
|
||||||
|
case 1:
|
||||||
|
name = noun(f) + verb(f)
|
||||||
|
case 2:
|
||||||
|
name = color(f) + noun(f)
|
||||||
|
case 3:
|
||||||
|
name = animal(f) + verb(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
return title(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AppVersion will generate a random app version
|
||||||
|
func AppVersion() string {
|
||||||
|
return appVersion(GlobalFaker)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AppVersion will generate a random app version
|
||||||
|
func (f *Faker) AppVersion() string {
|
||||||
|
return appVersion(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func appVersion(f *Faker) string {
|
||||||
|
return fmt.Sprintf("%d.%d.%d", number(f, 1, 5), number(f, 1, 20), number(f, 1, 20))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AppAuthor will generate a random company or person name
|
||||||
|
func AppAuthor() string {
|
||||||
|
return appAuthor(GlobalFaker)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AppAuthor will generate a random company or person name
|
||||||
|
func (f *Faker) AppAuthor() string {
|
||||||
|
return appAuthor(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func appAuthor(f *Faker) string {
|
||||||
|
if boolFunc(f) {
|
||||||
|
return name(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
return company(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func addAppLookup() {
|
||||||
|
AddFuncLookup("appname", Info{
|
||||||
|
Display: "App Name",
|
||||||
|
Category: "app",
|
||||||
|
Description: "Software program designed for a specific purpose or task on a computer or mobile device",
|
||||||
|
Example: "Parkrespond",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return appName(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("appversion", Info{
|
||||||
|
Display: "App Version",
|
||||||
|
Category: "app",
|
||||||
|
Description: "Particular release of an application in Semantic Versioning format",
|
||||||
|
Example: "1.12.14",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return appVersion(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("appauthor", Info{
|
||||||
|
Display: "App Author",
|
||||||
|
Category: "app",
|
||||||
|
Description: "Person or group creating and developing an application",
|
||||||
|
Example: "Qado Energy, Inc.",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return appAuthor(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,163 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
// Username will generate a random username based upon picking a random lastname and random numbers at the end
|
||||||
|
func Username() string {
|
||||||
|
return username(GlobalFaker)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Username will generate a random username based upon picking a random lastname and random numbers at the end
|
||||||
|
func (f *Faker) Username() string {
|
||||||
|
return username(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func username(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"person", "last"}) + replaceWithNumbers(f, "####")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Password will generate a random password.
|
||||||
|
// Minimum number length of 5 if less than.
|
||||||
|
func Password(lower bool, upper bool, numeric bool, special bool, space bool, num int) string {
|
||||||
|
return password(GlobalFaker, lower, upper, numeric, special, space, num)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Password will generate a random password.
|
||||||
|
// Minimum number length of 5 if less than.
|
||||||
|
func (f *Faker) Password(lower bool, upper bool, numeric bool, special bool, space bool, num int) string {
|
||||||
|
return password(f, lower, upper, numeric, special, space, num)
|
||||||
|
}
|
||||||
|
|
||||||
|
func password(f *Faker, lower bool, upper bool, numeric bool, special bool, space bool, num int) string {
|
||||||
|
// Make sure the num minimum is at least 5
|
||||||
|
if num < 5 {
|
||||||
|
num = 5
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup weights
|
||||||
|
items := make([]any, 0)
|
||||||
|
weights := make([]float32, 0)
|
||||||
|
if lower {
|
||||||
|
items = append(items, "l")
|
||||||
|
weights = append(weights, 4)
|
||||||
|
}
|
||||||
|
if upper {
|
||||||
|
items = append(items, "u")
|
||||||
|
weights = append(weights, 4)
|
||||||
|
}
|
||||||
|
if numeric {
|
||||||
|
items = append(items, "n")
|
||||||
|
weights = append(weights, 3)
|
||||||
|
}
|
||||||
|
if special {
|
||||||
|
items = append(items, "e")
|
||||||
|
weights = append(weights, 2)
|
||||||
|
}
|
||||||
|
if space {
|
||||||
|
items = append(items, "a")
|
||||||
|
weights = append(weights, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no items are selected then default to lower, upper, numeric
|
||||||
|
if len(items) == 0 {
|
||||||
|
items = append(items, "l", "u", "n")
|
||||||
|
weights = append(weights, 4, 4, 3)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create byte slice
|
||||||
|
b := make([]byte, num)
|
||||||
|
|
||||||
|
for i := 0; i <= num-1; i++ {
|
||||||
|
// Run weighted
|
||||||
|
weight, _ := weighted(f, items, weights)
|
||||||
|
|
||||||
|
switch weight.(string) {
|
||||||
|
case "l":
|
||||||
|
b[i] = lowerStr[f.Int64()%int64(len(lowerStr))]
|
||||||
|
case "u":
|
||||||
|
b[i] = upperStr[f.Int64()%int64(len(upperStr))]
|
||||||
|
case "n":
|
||||||
|
b[i] = numericStr[f.Int64()%int64(len(numericStr))]
|
||||||
|
case "e":
|
||||||
|
b[i] = specialSafeStr[f.Int64()%int64(len(specialSafeStr))]
|
||||||
|
case "a":
|
||||||
|
b[i] = spaceStr[f.Int64()%int64(len(spaceStr))]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Shuffle bytes
|
||||||
|
for i := range b {
|
||||||
|
j := f.IntN(i + 1)
|
||||||
|
b[i], b[j] = b[j], b[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace first or last character if it's a space, and other options are available
|
||||||
|
if b[0] == ' ' {
|
||||||
|
b[0] = password(f, lower, upper, numeric, special, false, 1)[0]
|
||||||
|
}
|
||||||
|
if b[len(b)-1] == ' ' {
|
||||||
|
b[len(b)-1] = password(f, lower, upper, numeric, special, false, 1)[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
func addAuthLookup() {
|
||||||
|
AddFuncLookup("username", Info{
|
||||||
|
Display: "Username",
|
||||||
|
Category: "auth",
|
||||||
|
Description: "Unique identifier assigned to a user for accessing an account or system",
|
||||||
|
Example: "Daniel1364",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return username(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("password", Info{
|
||||||
|
Display: "Password",
|
||||||
|
Category: "auth",
|
||||||
|
Description: "Secret word or phrase used to authenticate access to a system or account",
|
||||||
|
Example: "EEP+wwpk 4lU-eHNXlJZ4n K9%v&TZ9e",
|
||||||
|
Output: "string",
|
||||||
|
Params: []Param{
|
||||||
|
{Field: "lower", Display: "Lower", Type: "bool", Default: "true", Description: "Whether or not to add lower case characters"},
|
||||||
|
{Field: "upper", Display: "Upper", Type: "bool", Default: "true", Description: "Whether or not to add upper case characters"},
|
||||||
|
{Field: "numeric", Display: "Numeric", Type: "bool", Default: "true", Description: "Whether or not to add numeric characters"},
|
||||||
|
{Field: "special", Display: "Special", Type: "bool", Default: "true", Description: "Whether or not to add special characters"},
|
||||||
|
{Field: "space", Display: "Space", Type: "bool", Default: "false", Description: "Whether or not to add spaces"},
|
||||||
|
{Field: "length", Display: "Length", Type: "int", Default: "12", Description: "Number of characters in password"},
|
||||||
|
},
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
lower, err := info.GetBool(m, "lower")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
upper, err := info.GetBool(m, "upper")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
numeric, err := info.GetBool(m, "numeric")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
special, err := info.GetBool(m, "special")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
space, err := info.GetBool(m, "space")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
length, err := info.GetInt(m, "length")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return password(f, lower, upper, numeric, special, space, length), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,207 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
// BeerName will return a random beer name
|
||||||
|
func BeerName() string {
|
||||||
|
return beerName(GlobalFaker)
|
||||||
|
}
|
||||||
|
|
||||||
|
// BeerName will return a random beer name
|
||||||
|
func (f *Faker) BeerName() string {
|
||||||
|
return beerName(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func beerName(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"beer", "name"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// BeerStyle will return a random beer style
|
||||||
|
func BeerStyle() string {
|
||||||
|
return beerStyle(GlobalFaker)
|
||||||
|
}
|
||||||
|
|
||||||
|
// BeerStyle will return a random beer style
|
||||||
|
func (f *Faker) BeerStyle() string {
|
||||||
|
return beerStyle(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func beerStyle(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"beer", "style"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// BeerHop will return a random beer hop
|
||||||
|
func BeerHop() string {
|
||||||
|
return beerHop(GlobalFaker)
|
||||||
|
}
|
||||||
|
|
||||||
|
// BeerHop will return a random beer hop
|
||||||
|
func (f *Faker) BeerHop() string {
|
||||||
|
return beerHop(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func beerHop(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"beer", "hop"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// BeerYeast will return a random beer yeast
|
||||||
|
func BeerYeast() string {
|
||||||
|
return beerYeast(GlobalFaker)
|
||||||
|
}
|
||||||
|
|
||||||
|
// BeerYeast will return a random beer yeast
|
||||||
|
func (f *Faker) BeerYeast() string {
|
||||||
|
return beerYeast(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func beerYeast(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"beer", "yeast"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// BeerMalt will return a random beer malt
|
||||||
|
func BeerMalt() string {
|
||||||
|
return beerMalt(GlobalFaker)
|
||||||
|
}
|
||||||
|
|
||||||
|
// BeerMalt will return a random beer malt
|
||||||
|
func (f *Faker) BeerMalt() string {
|
||||||
|
return beerMalt(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func beerMalt(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"beer", "malt"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// BeerAlcohol will return a random beer alcohol level between 2.0 and 10.0
|
||||||
|
func BeerAlcohol() string {
|
||||||
|
return beerAlcohol(GlobalFaker)
|
||||||
|
}
|
||||||
|
|
||||||
|
// BeerAlcohol will return a random beer alcohol level between 2.0 and 10.0
|
||||||
|
func (f *Faker) BeerAlcohol() string {
|
||||||
|
return beerAlcohol(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func beerAlcohol(f *Faker) string {
|
||||||
|
return strconv.FormatFloat(float64Range(f, 2.0, 10.0), 'f', 1, 64) + "%"
|
||||||
|
}
|
||||||
|
|
||||||
|
// BeerIbu will return a random beer ibu value between 10 and 100
|
||||||
|
func BeerIbu() string {
|
||||||
|
return beerIbu(GlobalFaker)
|
||||||
|
}
|
||||||
|
|
||||||
|
// BeerIbu will return a random beer ibu value between 10 and 100
|
||||||
|
func (f *Faker) BeerIbu() string {
|
||||||
|
return beerIbu(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func beerIbu(f *Faker) string {
|
||||||
|
return strconv.Itoa(randIntRange(f, 10, 100)) + " IBU"
|
||||||
|
}
|
||||||
|
|
||||||
|
// BeerBlg will return a random beer blg between 5.0 and 20.0
|
||||||
|
func BeerBlg() string {
|
||||||
|
return beerBlg(GlobalFaker)
|
||||||
|
}
|
||||||
|
|
||||||
|
// BeerBlg will return a random beer blg between 5.0 and 20.0
|
||||||
|
func (f *Faker) BeerBlg() string {
|
||||||
|
return beerBlg(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func beerBlg(f *Faker) string {
|
||||||
|
return strconv.FormatFloat(float64Range(f, 5.0, 20.0), 'f', 1, 64) + "°Blg"
|
||||||
|
}
|
||||||
|
|
||||||
|
func addBeerLookup() {
|
||||||
|
AddFuncLookup("beername", Info{
|
||||||
|
Display: "Beer Name",
|
||||||
|
Category: "beer",
|
||||||
|
Description: "Specific brand or variety of beer",
|
||||||
|
Example: "Duvel",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return beerName(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("beerstyle", Info{
|
||||||
|
Display: "Beer Style",
|
||||||
|
Category: "beer",
|
||||||
|
Description: "Distinct characteristics and flavors of beer",
|
||||||
|
Example: "European Amber Lager",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return beerStyle(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("beerhop", Info{
|
||||||
|
Display: "Beer Hop",
|
||||||
|
Category: "beer",
|
||||||
|
Description: "The flower used in brewing to add flavor, aroma, and bitterness to beer",
|
||||||
|
Example: "Glacier",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return beerHop(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("beeryeast", Info{
|
||||||
|
Display: "Beer Yeast",
|
||||||
|
Category: "beer",
|
||||||
|
Description: "Microorganism used in brewing to ferment sugars, producing alcohol and carbonation in beer",
|
||||||
|
Example: "1388 - Belgian Strong Ale",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return beerYeast(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("beermalt", Info{
|
||||||
|
Display: "Beer Malt",
|
||||||
|
Category: "beer",
|
||||||
|
Description: "Processed barley or other grains, provides sugars for fermentation and flavor to beer",
|
||||||
|
Example: "Munich",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return beerMalt(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("beeralcohol", Info{
|
||||||
|
Display: "Beer Alcohol",
|
||||||
|
Category: "beer",
|
||||||
|
Description: "Measures the alcohol content in beer",
|
||||||
|
Example: "2.7%",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return beerAlcohol(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("beeribu", Info{
|
||||||
|
Display: "Beer IBU",
|
||||||
|
Category: "beer",
|
||||||
|
Description: "Scale measuring bitterness of beer from hops",
|
||||||
|
Example: "29 IBU",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return beerIbu(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("beerblg", Info{
|
||||||
|
Display: "Beer BLG",
|
||||||
|
Category: "beer",
|
||||||
|
Description: "Scale indicating the concentration of extract in worts",
|
||||||
|
Example: "6.4°Blg",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return beerBlg(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,88 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
func BookTitle() string { return bookTitle(GlobalFaker) }
|
||||||
|
|
||||||
|
func (f *Faker) BookTitle() string { return bookTitle(f) }
|
||||||
|
|
||||||
|
func bookTitle(f *Faker) string { return getRandValue(f, []string{"book", "title"}) }
|
||||||
|
|
||||||
|
func BookAuthor() string { return bookAuthor(GlobalFaker) }
|
||||||
|
|
||||||
|
func (f *Faker) BookAuthor() string { return bookAuthor(f) }
|
||||||
|
|
||||||
|
func bookAuthor(f *Faker) string { return getRandValue(f, []string{"book", "author"}) }
|
||||||
|
|
||||||
|
func BookGenre() string { return bookGenre(GlobalFaker) }
|
||||||
|
|
||||||
|
func (f *Faker) BookGenre() string { return bookGenre(f) }
|
||||||
|
|
||||||
|
func bookGenre(f *Faker) string { return getRandValue(f, []string{"book", "genre"}) }
|
||||||
|
|
||||||
|
type BookInfo struct {
|
||||||
|
Title string `json:"title" xml:"name"`
|
||||||
|
Author string `json:"author" xml:"author"`
|
||||||
|
Genre string `json:"genre" xml:"genre"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func Book() *BookInfo { return book(GlobalFaker) }
|
||||||
|
|
||||||
|
func (f *Faker) Book() *BookInfo { return book(f) }
|
||||||
|
|
||||||
|
func book(f *Faker) *BookInfo {
|
||||||
|
return &BookInfo{
|
||||||
|
Title: bookTitle(f),
|
||||||
|
Author: bookAuthor(f),
|
||||||
|
Genre: bookGenre(f),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func addBookLookup() {
|
||||||
|
AddFuncLookup("book", Info{
|
||||||
|
Display: "Book",
|
||||||
|
Category: "book",
|
||||||
|
Description: "Written or printed work consisting of pages bound together, covering various subjects or stories",
|
||||||
|
Example: `{
|
||||||
|
"title": "Anna Karenina",
|
||||||
|
"author": "Toni Morrison",
|
||||||
|
"genre": "Thriller"
|
||||||
|
}`,
|
||||||
|
Output: "map[string]string",
|
||||||
|
ContentType: "application/json",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return book(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("booktitle", Info{
|
||||||
|
Display: "Title",
|
||||||
|
Category: "book",
|
||||||
|
Description: "The specific name given to a book",
|
||||||
|
Example: "Hamlet",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return bookTitle(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("bookauthor", Info{
|
||||||
|
Display: "Author",
|
||||||
|
Category: "book",
|
||||||
|
Description: "The individual who wrote or created the content of a book",
|
||||||
|
Example: "Mark Twain",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return bookAuthor(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("bookgenre", Info{
|
||||||
|
Display: "Genre",
|
||||||
|
Category: "book",
|
||||||
|
Description: "Category or type of book defined by its content, style, or form",
|
||||||
|
Example: "Adventure",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return bookGenre(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,146 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
// CarInfo is a struct dataset of all car information
|
||||||
|
type CarInfo struct {
|
||||||
|
Type string `json:"type" xml:"type"`
|
||||||
|
Fuel string `json:"fuel" xml:"fuel"`
|
||||||
|
Transmission string `json:"transmission" xml:"transmission"`
|
||||||
|
Brand string `json:"brand" xml:"brand"`
|
||||||
|
Model string `json:"model" xml:"model"`
|
||||||
|
Year int `json:"year" xml:"year"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Car will generate a struct with car information
|
||||||
|
func Car() *CarInfo { return car(GlobalFaker) }
|
||||||
|
|
||||||
|
// Car will generate a struct with car information
|
||||||
|
func (f *Faker) Car() *CarInfo { return car(f) }
|
||||||
|
|
||||||
|
func car(f *Faker) *CarInfo {
|
||||||
|
return &CarInfo{
|
||||||
|
Type: carType(f),
|
||||||
|
Fuel: carFuelType(f),
|
||||||
|
Transmission: carTransmissionType(f),
|
||||||
|
Brand: carMaker(f),
|
||||||
|
Model: carModel(f),
|
||||||
|
Year: year(f),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CarType will generate a random car type string
|
||||||
|
func CarType() string { return carType(GlobalFaker) }
|
||||||
|
|
||||||
|
// CarType will generate a random car type string
|
||||||
|
func (f *Faker) CarType() string { return carType(f) }
|
||||||
|
|
||||||
|
func carType(f *Faker) string { return getRandValue(f, []string{"car", "type"}) }
|
||||||
|
|
||||||
|
// CarFuelType will return a random fuel type
|
||||||
|
func CarFuelType() string { return carFuelType(GlobalFaker) }
|
||||||
|
|
||||||
|
// CarFuelType will return a random fuel type
|
||||||
|
func (f *Faker) CarFuelType() string { return carFuelType(f) }
|
||||||
|
|
||||||
|
func carFuelType(f *Faker) string { return getRandValue(f, []string{"car", "fuel_type"}) }
|
||||||
|
|
||||||
|
// CarTransmissionType will return a random transmission type
|
||||||
|
func CarTransmissionType() string { return carTransmissionType(GlobalFaker) }
|
||||||
|
|
||||||
|
// CarTransmissionType will return a random transmission type
|
||||||
|
func (f *Faker) CarTransmissionType() string { return carTransmissionType(f) }
|
||||||
|
|
||||||
|
func carTransmissionType(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"car", "transmission_type"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CarMaker will return a random car maker
|
||||||
|
func CarMaker() string { return carMaker(GlobalFaker) }
|
||||||
|
|
||||||
|
// CarMaker will return a random car maker
|
||||||
|
func (f *Faker) CarMaker() string { return carMaker(f) }
|
||||||
|
|
||||||
|
func carMaker(f *Faker) string { return getRandValue(f, []string{"car", "maker"}) }
|
||||||
|
|
||||||
|
// CarModel will return a random car model
|
||||||
|
func CarModel() string { return carModel(GlobalFaker) }
|
||||||
|
|
||||||
|
// CarModel will return a random car model
|
||||||
|
func (f *Faker) CarModel() string { return carModel(f) }
|
||||||
|
|
||||||
|
func carModel(f *Faker) string { return getRandValue(f, []string{"car", "model"}) }
|
||||||
|
|
||||||
|
func addCarLookup() {
|
||||||
|
AddFuncLookup("car", Info{
|
||||||
|
Display: "Car",
|
||||||
|
Category: "car",
|
||||||
|
Description: "Wheeled motor vehicle used for transportation",
|
||||||
|
Example: `{
|
||||||
|
"type": "Passenger car mini",
|
||||||
|
"fuel": "Gasoline",
|
||||||
|
"transmission": "Automatic",
|
||||||
|
"brand": "Fiat",
|
||||||
|
"model": "Freestyle Fwd",
|
||||||
|
"year": 1991
|
||||||
|
}`,
|
||||||
|
Output: "map[string]any",
|
||||||
|
ContentType: "application/json",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return car(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("cartype", Info{
|
||||||
|
Display: "Car Type",
|
||||||
|
Category: "car",
|
||||||
|
Description: "Classification of cars based on size, use, or body style",
|
||||||
|
Example: "Passenger car mini",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return carType(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("carfueltype", Info{
|
||||||
|
Display: "Car Fuel Type",
|
||||||
|
Category: "car",
|
||||||
|
Description: "Type of energy source a car uses",
|
||||||
|
Example: "CNG",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return carFuelType(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("cartransmissiontype", Info{
|
||||||
|
Display: "Car Transmission Type",
|
||||||
|
Category: "car",
|
||||||
|
Description: "Mechanism a car uses to transmit power from the engine to the wheels",
|
||||||
|
Example: "Manual",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return carTransmissionType(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("carmaker", Info{
|
||||||
|
Display: "Car Maker",
|
||||||
|
Category: "car",
|
||||||
|
Description: "Company or brand that manufactures and designs cars",
|
||||||
|
Example: "Nissan",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return carMaker(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("carmodel", Info{
|
||||||
|
Display: "Car Model",
|
||||||
|
Category: "car",
|
||||||
|
Description: "Specific design or version of a car produced by a manufacturer",
|
||||||
|
Example: "Aveo",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return carModel(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,62 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
// CelebrityActor will generate a random celebrity actor
|
||||||
|
func CelebrityActor() string { return celebrityActor(GlobalFaker) }
|
||||||
|
|
||||||
|
// CelebrityActor will generate a random celebrity actor
|
||||||
|
func (f *Faker) CelebrityActor() string { return celebrityActor(f) }
|
||||||
|
|
||||||
|
func celebrityActor(f *Faker) string { return getRandValue(f, []string{"celebrity", "actor"}) }
|
||||||
|
|
||||||
|
// CelebrityBusiness will generate a random celebrity business person
|
||||||
|
func CelebrityBusiness() string { return celebrityBusiness(GlobalFaker) }
|
||||||
|
|
||||||
|
// CelebrityBusiness will generate a random celebrity business person
|
||||||
|
func (f *Faker) CelebrityBusiness() string { return celebrityBusiness(f) }
|
||||||
|
|
||||||
|
func celebrityBusiness(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"celebrity", "business"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CelebritySport will generate a random celebrity sport person
|
||||||
|
func CelebritySport() string { return celebritySport(GlobalFaker) }
|
||||||
|
|
||||||
|
// CelebritySport will generate a random celebrity sport person
|
||||||
|
func (f *Faker) CelebritySport() string { return celebritySport(f) }
|
||||||
|
|
||||||
|
func celebritySport(f *Faker) string { return getRandValue(f, []string{"celebrity", "sport"}) }
|
||||||
|
|
||||||
|
func addCelebrityLookup() {
|
||||||
|
AddFuncLookup("celebrityactor", Info{
|
||||||
|
Display: "Celebrity Actor",
|
||||||
|
Category: "celebrity",
|
||||||
|
Description: "Famous person known for acting in films, television, or theater",
|
||||||
|
Example: "Brad Pitt",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return celebrityActor(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("celebritybusiness", Info{
|
||||||
|
Display: "Celebrity Business",
|
||||||
|
Category: "celebrity",
|
||||||
|
Description: "High-profile individual known for significant achievements in business or entrepreneurship",
|
||||||
|
Example: "Elon Musk",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return celebrityBusiness(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("celebritysport", Info{
|
||||||
|
Display: "Celebrity Sport",
|
||||||
|
Category: "celebrity",
|
||||||
|
Description: "Famous athlete known for achievements in a particular sport",
|
||||||
|
Example: "Michael Phelps",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return celebritySport(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,116 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/brianvoe/gofakeit/v7/data"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Color will generate a random color string
|
||||||
|
func Color() string { return color(GlobalFaker) }
|
||||||
|
|
||||||
|
// Color will generate a random color string
|
||||||
|
func (f *Faker) Color() string { return color(f) }
|
||||||
|
|
||||||
|
func color(f *Faker) string { return getRandValue(f, []string{"color", "full"}) }
|
||||||
|
|
||||||
|
// NiceColor will generate a random safe color string
|
||||||
|
func NiceColors() []string { return niceColors(GlobalFaker) }
|
||||||
|
|
||||||
|
// NiceColor will generate a random safe color string
|
||||||
|
func (f *Faker) NiceColors() []string { return niceColors(f) }
|
||||||
|
|
||||||
|
func niceColors(f *Faker) []string {
|
||||||
|
return data.ColorsNice[randIntRange(f, 0, len(data.ColorsNice)-1)]
|
||||||
|
}
|
||||||
|
|
||||||
|
// SafeColor will generate a random safe color string
|
||||||
|
func SafeColor() string { return safeColor(GlobalFaker) }
|
||||||
|
|
||||||
|
// SafeColor will generate a random safe color string
|
||||||
|
func (f *Faker) SafeColor() string { return safeColor(f) }
|
||||||
|
|
||||||
|
func safeColor(f *Faker) string { return getRandValue(f, []string{"color", "safe"}) }
|
||||||
|
|
||||||
|
// HexColor will generate a random hexadecimal color string
|
||||||
|
func HexColor() string { return hexColor(GlobalFaker) }
|
||||||
|
|
||||||
|
// HexColor will generate a random hexadecimal color string
|
||||||
|
func (f *Faker) HexColor() string { return hexColor(f) }
|
||||||
|
|
||||||
|
func hexColor(f *Faker) string {
|
||||||
|
color := make([]byte, 6)
|
||||||
|
hashQuestion := []byte("?#")
|
||||||
|
for i := 0; i < 6; i++ {
|
||||||
|
color[i] = hashQuestion[f.IntN(2)]
|
||||||
|
}
|
||||||
|
|
||||||
|
return "#" + replaceWithHexLetters(f, replaceWithNumbers(f, string(color)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RGBColor will generate a random int slice color
|
||||||
|
func RGBColor() []int { return rgbColor(GlobalFaker) }
|
||||||
|
|
||||||
|
// RGBColor will generate a random int slice color
|
||||||
|
func (f *Faker) RGBColor() []int { return rgbColor(f) }
|
||||||
|
|
||||||
|
func rgbColor(f *Faker) []int {
|
||||||
|
return []int{randIntRange(f, 0, 255), randIntRange(f, 0, 255), randIntRange(f, 0, 255)}
|
||||||
|
}
|
||||||
|
|
||||||
|
func addColorLookup() {
|
||||||
|
AddFuncLookup("color", Info{
|
||||||
|
Display: "Color",
|
||||||
|
Category: "color",
|
||||||
|
Description: "Hue seen by the eye, returns the name of the color like red or blue",
|
||||||
|
Example: "MediumOrchid",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return color(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("nicecolors", Info{
|
||||||
|
Display: "Nice Colors",
|
||||||
|
Category: "color",
|
||||||
|
Description: "Attractive and appealing combinations of colors, returns an list of color hex codes",
|
||||||
|
Example: `["#cfffdd","#b4dec1","#5c5863","#a85163","#ff1f4c"]`,
|
||||||
|
Output: "[]string",
|
||||||
|
ContentType: "application/json",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return niceColors(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("safecolor", Info{
|
||||||
|
Display: "Safe Color",
|
||||||
|
Category: "color",
|
||||||
|
Description: "Colors displayed consistently on different web browsers and devices",
|
||||||
|
Example: "black",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return safeColor(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("hexcolor", Info{
|
||||||
|
Display: "Hex Color",
|
||||||
|
Category: "color",
|
||||||
|
Description: "Six-digit code representing a color in the color model",
|
||||||
|
Example: "#a99fb4",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return hexColor(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("rgbcolor", Info{
|
||||||
|
Display: "RGB Color",
|
||||||
|
Category: "color",
|
||||||
|
Description: "Color defined by red, green, and blue light values",
|
||||||
|
Example: "[85, 224, 195]",
|
||||||
|
Output: "[]int",
|
||||||
|
ContentType: "application/json",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return rgbColor(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,229 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
// Company will generate a random company name string
|
||||||
|
func Company() string { return company(GlobalFaker) }
|
||||||
|
|
||||||
|
// Company will generate a random company name string
|
||||||
|
func (f *Faker) Company() string { return company(f) }
|
||||||
|
|
||||||
|
func company(f *Faker) string { return getRandValue(f, []string{"company", "name"}) }
|
||||||
|
|
||||||
|
// CompanySuffix will generate a random company suffix string
|
||||||
|
func CompanySuffix() string { return companySuffix(GlobalFaker) }
|
||||||
|
|
||||||
|
// CompanySuffix will generate a random company suffix string
|
||||||
|
func (f *Faker) CompanySuffix() string { return companySuffix(f) }
|
||||||
|
|
||||||
|
func companySuffix(f *Faker) string { return getRandValue(f, []string{"company", "suffix"}) }
|
||||||
|
|
||||||
|
// Blurb will generate a random company blurb string
|
||||||
|
func Blurb() string { return blurb(GlobalFaker) }
|
||||||
|
|
||||||
|
func (f *Faker) Blurb() string { return blurb(f) }
|
||||||
|
|
||||||
|
func blurb(f *Faker) string { return getRandValue(f, []string{"company", "blurb"}) }
|
||||||
|
|
||||||
|
// BuzzWord will generate a random company buzz word string
|
||||||
|
func BuzzWord() string { return buzzWord(GlobalFaker) }
|
||||||
|
|
||||||
|
// BuzzWord will generate a random company buzz word string
|
||||||
|
func (f *Faker) BuzzWord() string { return buzzWord(f) }
|
||||||
|
|
||||||
|
func buzzWord(f *Faker) string { return getRandValue(f, []string{"company", "buzzwords"}) }
|
||||||
|
|
||||||
|
// BS will generate a random company bs string
|
||||||
|
func BS() string { return bs(GlobalFaker) }
|
||||||
|
|
||||||
|
// BS will generate a random company bs string
|
||||||
|
func (f *Faker) BS() string { return bs(f) }
|
||||||
|
|
||||||
|
func bs(f *Faker) string { return getRandValue(f, []string{"company", "bs"}) }
|
||||||
|
|
||||||
|
// JobInfo is a struct of job information
|
||||||
|
type JobInfo struct {
|
||||||
|
Company string `json:"company" xml:"company"`
|
||||||
|
Title string `json:"title" xml:"title"`
|
||||||
|
Descriptor string `json:"descriptor" xml:"descriptor"`
|
||||||
|
Level string `json:"level" xml:"level"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Job will generate a struct with random job information
|
||||||
|
func Job() *JobInfo { return job(GlobalFaker) }
|
||||||
|
|
||||||
|
// Job will generate a struct with random job information
|
||||||
|
func (f *Faker) Job() *JobInfo { return job(f) }
|
||||||
|
|
||||||
|
func job(f *Faker) *JobInfo {
|
||||||
|
return &JobInfo{
|
||||||
|
Company: company(f),
|
||||||
|
Title: jobTitle(f),
|
||||||
|
Descriptor: jobDescriptor(f),
|
||||||
|
Level: jobLevel(f),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// JobTitle will generate a random job title string
|
||||||
|
func JobTitle() string { return jobTitle(GlobalFaker) }
|
||||||
|
|
||||||
|
// JobTitle will generate a random job title string
|
||||||
|
func (f *Faker) JobTitle() string { return jobTitle(f) }
|
||||||
|
|
||||||
|
func jobTitle(f *Faker) string { return getRandValue(f, []string{"job", "title"}) }
|
||||||
|
|
||||||
|
// JobDescriptor will generate a random job descriptor string
|
||||||
|
func JobDescriptor() string { return jobDescriptor(GlobalFaker) }
|
||||||
|
|
||||||
|
// JobDescriptor will generate a random job descriptor string
|
||||||
|
func (f *Faker) JobDescriptor() string { return jobDescriptor(f) }
|
||||||
|
|
||||||
|
func jobDescriptor(f *Faker) string { return getRandValue(f, []string{"job", "descriptor"}) }
|
||||||
|
|
||||||
|
// JobLevel will generate a random job level string
|
||||||
|
func JobLevel() string { return jobLevel(GlobalFaker) }
|
||||||
|
|
||||||
|
// JobLevel will generate a random job level string
|
||||||
|
func (f *Faker) JobLevel() string { return jobLevel(f) }
|
||||||
|
|
||||||
|
func jobLevel(f *Faker) string { return getRandValue(f, []string{"job", "level"}) }
|
||||||
|
|
||||||
|
// Slogan will generate a random company slogan
|
||||||
|
func Slogan() string { return slogan(GlobalFaker) }
|
||||||
|
|
||||||
|
// Slogan will generate a random company slogan
|
||||||
|
func (f *Faker) Slogan() string { return slogan(f) }
|
||||||
|
|
||||||
|
// Slogan will generate a random company slogan
|
||||||
|
func slogan(f *Faker) string {
|
||||||
|
slogan := ""
|
||||||
|
var sloganStyle = number(f, 0, 2)
|
||||||
|
switch sloganStyle {
|
||||||
|
// Noun. Buzzword!
|
||||||
|
case 0:
|
||||||
|
slogan = getRandValue(f, []string{"company", "blurb"}) + ". " + getRandValue(f, []string{"company", "buzzwords"}) + "!"
|
||||||
|
// Buzzword Noun, Buzzword Noun.
|
||||||
|
case 1:
|
||||||
|
slogan = getRandValue(f, []string{"company", "buzzwords"}) + " " + getRandValue(f, []string{"company", "blurb"}) + ", " + getRandValue(f, []string{"company", "buzzwords"}) + " " + getRandValue(f, []string{"company", "blurb"}) + "."
|
||||||
|
// Buzzword bs Noun, Buzzword.
|
||||||
|
case 2:
|
||||||
|
slogan = getRandValue(f, []string{"company", "buzzwords"}) + " " + getRandValue(f, []string{"company", "bs"}) + " " + getRandValue(f, []string{"company", "blurb"}) + ", " + getRandValue(f, []string{"company", "buzzwords"}) + "."
|
||||||
|
}
|
||||||
|
return slogan
|
||||||
|
}
|
||||||
|
|
||||||
|
func addCompanyLookup() {
|
||||||
|
AddFuncLookup("company", Info{
|
||||||
|
Display: "Company",
|
||||||
|
Category: "company",
|
||||||
|
Description: "Designated official name of a business or organization",
|
||||||
|
Example: "Moen, Pagac and Wuckert",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return company(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("companysuffix", Info{
|
||||||
|
Display: "Company Suffix",
|
||||||
|
Category: "company",
|
||||||
|
Description: "Suffix at the end of a company name, indicating business structure, like 'Inc.' or 'LLC'",
|
||||||
|
Example: "Inc",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return companySuffix(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("bs", Info{
|
||||||
|
Display: "BS",
|
||||||
|
Category: "company",
|
||||||
|
Description: "Random bs company word",
|
||||||
|
Example: "front-end",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return bs(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("blurb", Info{
|
||||||
|
Display: "Blurb",
|
||||||
|
Category: "company",
|
||||||
|
Description: "Brief description or summary of a company's purpose, products, or services",
|
||||||
|
Example: "word",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return blurb(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("buzzword", Info{
|
||||||
|
Display: "Buzzword",
|
||||||
|
Category: "company",
|
||||||
|
Description: "Trendy or overused term often used in business to sound impressive",
|
||||||
|
Example: "disintermediate",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return buzzWord(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("job", Info{
|
||||||
|
Display: "Job",
|
||||||
|
Category: "company",
|
||||||
|
Description: "Position or role in employment, involving specific tasks and responsibilities",
|
||||||
|
Example: `{
|
||||||
|
"company": "ClearHealthCosts",
|
||||||
|
"title": "Agent",
|
||||||
|
"descriptor": "Future",
|
||||||
|
"level": "Tactics"
|
||||||
|
}`,
|
||||||
|
Output: "map[string]string",
|
||||||
|
ContentType: "application/json",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return job(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("jobtitle", Info{
|
||||||
|
Display: "Job Title",
|
||||||
|
Category: "company",
|
||||||
|
Description: "Specific title for a position or role within a company or organization",
|
||||||
|
Example: "Director",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return jobTitle(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("jobdescriptor", Info{
|
||||||
|
Display: "Job Descriptor",
|
||||||
|
Category: "company",
|
||||||
|
Description: "Word used to describe the duties, requirements, and nature of a job",
|
||||||
|
Example: "Central",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return jobDescriptor(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("joblevel", Info{
|
||||||
|
Display: "Job Level",
|
||||||
|
Category: "company",
|
||||||
|
Description: "Random job level",
|
||||||
|
Example: "Assurance",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return jobLevel(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("slogan", Info{
|
||||||
|
Display: "Slogan",
|
||||||
|
Category: "company",
|
||||||
|
Description: "Catchphrase or motto used by a company to represent its brand or values",
|
||||||
|
Example: "Universal seamless Focus, interactive.",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return slogan(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,183 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/csv"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CSVOptions defines values needed for csv generation
|
||||||
|
type CSVOptions struct {
|
||||||
|
Delimiter string `json:"delimiter" xml:"delimiter" fake:"{randomstring:[,,tab]}"`
|
||||||
|
RowCount int `json:"row_count" xml:"row_count" fake:"{number:1,10}"`
|
||||||
|
Fields []Field `json:"fields" xml:"fields" fake:"{fields}"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CSV generates an object or an array of objects in json format
|
||||||
|
// A nil CSVOptions returns a randomly structured CSV.
|
||||||
|
func CSV(co *CSVOptions) ([]byte, error) { return csvFunc(GlobalFaker, co) }
|
||||||
|
|
||||||
|
// CSV generates an object or an array of objects in json format
|
||||||
|
// A nil CSVOptions returns a randomly structured CSV.
|
||||||
|
func (f *Faker) CSV(co *CSVOptions) ([]byte, error) { return csvFunc(f, co) }
|
||||||
|
|
||||||
|
func csvFunc(f *Faker, co *CSVOptions) ([]byte, error) {
|
||||||
|
if co == nil {
|
||||||
|
// We didn't get a CSVOptions, so create a new random one
|
||||||
|
err := f.Struct(&co)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check delimiter
|
||||||
|
if co.Delimiter == "" {
|
||||||
|
co.Delimiter = ","
|
||||||
|
}
|
||||||
|
if strings.ToLower(co.Delimiter) == "tab" {
|
||||||
|
co.Delimiter = "\t"
|
||||||
|
}
|
||||||
|
if co.Delimiter != "," && co.Delimiter != "\t" && co.Delimiter != ";" {
|
||||||
|
return nil, errors.New("invalid delimiter type")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check fields
|
||||||
|
if co.Fields == nil || len(co.Fields) <= 0 {
|
||||||
|
return nil, errors.New("must pass fields in order to build json object(s)")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure you set a row count
|
||||||
|
if co.RowCount <= 0 {
|
||||||
|
return nil, errors.New("must have row count")
|
||||||
|
}
|
||||||
|
|
||||||
|
b := &bytes.Buffer{}
|
||||||
|
w := csv.NewWriter(b)
|
||||||
|
w.Comma = []rune(co.Delimiter)[0]
|
||||||
|
|
||||||
|
// Add header row
|
||||||
|
header := make([]string, len(co.Fields))
|
||||||
|
for i, field := range co.Fields {
|
||||||
|
header[i] = field.Name
|
||||||
|
}
|
||||||
|
w.Write(header)
|
||||||
|
|
||||||
|
// Loop through row count +1(for header) and add fields
|
||||||
|
for i := 1; i < co.RowCount+1; i++ {
|
||||||
|
vr := make([]string, len(co.Fields))
|
||||||
|
|
||||||
|
// Loop through fields and add to them to map[string]any
|
||||||
|
for ii, field := range co.Fields {
|
||||||
|
if field.Function == "autoincrement" {
|
||||||
|
vr[ii] = fmt.Sprintf("%d", i)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get function info
|
||||||
|
funcInfo := GetFuncLookup(field.Function)
|
||||||
|
if funcInfo == nil {
|
||||||
|
return nil, errors.New("invalid function, " + field.Function + " does not exist")
|
||||||
|
}
|
||||||
|
|
||||||
|
value, err := funcInfo.Generate(f, &field.Params, funcInfo)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := value.([]byte); ok {
|
||||||
|
// If it's a slice of bytes or struct, unmarshal it into an interface
|
||||||
|
var v any
|
||||||
|
if err := json.Unmarshal(value.([]byte), &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
value = v
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the value is a list of possible values, marsha it into a string
|
||||||
|
if reflect.TypeOf(value).Kind() == reflect.Struct ||
|
||||||
|
reflect.TypeOf(value).Kind() == reflect.Ptr ||
|
||||||
|
reflect.TypeOf(value).Kind() == reflect.Map ||
|
||||||
|
reflect.TypeOf(value).Kind() == reflect.Slice {
|
||||||
|
b, err := json.Marshal(value)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
value = string(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
vr[ii] = fmt.Sprintf("%v", value)
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Write(vr)
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Flush()
|
||||||
|
|
||||||
|
if err := w.Error(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return b.Bytes(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func addFileCSVLookup() {
|
||||||
|
AddFuncLookup("csv", Info{
|
||||||
|
Display: "CSV",
|
||||||
|
Category: "file",
|
||||||
|
Description: "Individual lines or data entries within a CSV (Comma-Separated Values) format",
|
||||||
|
Example: `id,first_name,last_name,password
|
||||||
|
1,Markus,Moen,Dc0VYXjkWABx
|
||||||
|
2,Osborne,Hilll,XPJ9OVNbs5lm`,
|
||||||
|
Output: "[]byte",
|
||||||
|
ContentType: "text/csv",
|
||||||
|
Params: []Param{
|
||||||
|
{Field: "delimiter", Display: "Delimiter", Type: "string", Default: ",", Description: "Separator in between row values"},
|
||||||
|
{Field: "rowcount", Display: "Row Count", Type: "int", Default: "100", Description: "Number of rows"},
|
||||||
|
{Field: "fields", Display: "Fields", Type: "[]Field", Description: "Fields containing key name and function"},
|
||||||
|
},
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
co := CSVOptions{}
|
||||||
|
|
||||||
|
delimiter, err := info.GetString(m, "delimiter")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
co.Delimiter = delimiter
|
||||||
|
|
||||||
|
rowcount, err := info.GetInt(m, "rowcount")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
co.RowCount = rowcount
|
||||||
|
|
||||||
|
fieldsStr, err := info.GetStringArray(m, "fields")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check to make sure fields has length
|
||||||
|
if len(fieldsStr) > 0 {
|
||||||
|
co.Fields = make([]Field, len(fieldsStr))
|
||||||
|
|
||||||
|
for i, f := range fieldsStr {
|
||||||
|
// Unmarshal fields string into fields array
|
||||||
|
err = json.Unmarshal([]byte(f), &co.Fields[i])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
csvOut, err := csvFunc(f, &co)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return csvOut, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
# Gofakeit Data
|
||||||
|
|
||||||
|
Gofakeit data set
|
||||||
|
|
||||||
|
## List
|
||||||
|
|
||||||
|
```go
|
||||||
|
List()
|
||||||
|
```
|
||||||
|
|
||||||
|
## Get/Set/Remove Data
|
||||||
|
|
||||||
|
```go
|
||||||
|
data.Get("desserts")
|
||||||
|
|
||||||
|
data.Set("desserts", map[string][]string{
|
||||||
|
"cake": {"chocolate", "vanilla"},
|
||||||
|
"pie": {"apple", "pecan"},
|
||||||
|
"ice cream": {"strawberry", "vanilla"},
|
||||||
|
})
|
||||||
|
|
||||||
|
data.Remove("desserts")
|
||||||
|
```
|
||||||
|
|
||||||
|
## Get/Set/Remove Sub Data
|
||||||
|
|
||||||
|
```go
|
||||||
|
data.GetSubData("desserts", "cake")
|
||||||
|
|
||||||
|
data.SetSub("desserts", "cake", []string{"chocolate", "vanilla"})
|
||||||
|
|
||||||
|
data.RemoveSub("desserts", "cake")
|
||||||
|
```
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
package data
|
||||||
|
|
||||||
|
// Address consists of address information
|
||||||
|
var Address = map[string][]string{
|
||||||
|
"number": {"#####", "####", "###"},
|
||||||
|
"street_prefix": {"North", "East", "West", "South", "New", "Lake", "Port"},
|
||||||
|
"street_name": {"Alley", "Avenue", "Branch", "Bridge", "Brook", "Brooks", "Burg", "Burgs", "Bypass", "Camp", "Canyon", "Cape", "Causeway", "Center", "Centers", "Circle", "Circles", "Cliff", "Cliffs", "Club", "Common", "Corner", "Corners", "Course", "Court", "Courts", "Cove", "Coves", "Creek", "Crescent", "Crest", "Crossing", "Crossroad", "Curve", "Dale", "Dam", "Divide", "Drive", "Drive", "Drives", "Estate", "Estates", "Expressway", "Extension", "Extensions", "Fall", "Falls", "Ferry", "Field", "Fields", "Flat", "Flats", "Ford", "Fords", "Forest", "Forge", "Forges", "Fork", "Forks", "Fort", "Freeway", "Garden", "Gardens", "Gateway", "Glen", "Glens", "Green", "Greens", "Grove", "Groves", "Harbor", "Harbors", "Haven", "Heights", "Highway", "Hill", "Hills", "Hollow", "Inlet", "Inlet", "Island", "Island", "Islands", "Islands", "Isle", "Isle", "Junction", "Junctions", "Key", "Keys", "Knoll", "Knolls", "Lake", "Lakes", "Land", "Landing", "Lane", "Light", "Lights", "Loaf", "Lock", "Locks", "Locks", "Lodge", "Lodge", "Loop", "Mall", "Manor", "Manors", "Meadow", "Meadows", "Mews", "Mill", "Mills", "Mission", "Mission", "Motorway", "Mount", "Mountain", "Mountain", "Mountains", "Mountains", "Neck", "Orchard", "Oval", "Overpass", "Park", "Parks", "Parkway", "Parkways", "Pass", "Passage", "Path", "Pike", "Pine", "Pines", "Place", "Plain", "Plains", "Plains", "Plaza", "Plaza", "Point", "Points", "Port", "Port", "Ports", "Ports", "Prairie", "Prairie", "Radial", "Ramp", "Ranch", "Rapid", "Rapids", "Rest", "Ridge", "Ridges", "River", "Road", "Road", "Roads", "Roads", "Route", "Row", "Rue", "Run", "Shoal", "Shoals", "Shore", "Shores", "Skyway", "Spring", "Springs", "Springs", "Spur", "Spurs", "Square", "Square", "Squares", "Squares", "Station", "Station", "Stravenue", "Stravenue", "Stream", "Stream", "Street", "Street", "Streets", "Summit", "Summit", "Terrace", "Throughway", "Trace", "Track", "Trafficway", "Trail", "Trail", "Tunnel", "Tunnel", "Turnpike", "Turnpike", "Underpass", "Union", "Unions", "Valley", "Valleys", "Via", "Viaduct", "View", "Views", "Village", "Village", "Villages", "Ville", "Vista", "Vista", "Walk", "Walks", "Wall", "Way", "Ways", "Well", "Wells"},
|
||||||
|
"street_suffix": {"town", "ton", "land", "ville", "berg", "burgh", "borough", "bury", "view", "port", "mouth", "stad", "furt", "chester", "mouth", "fort", "haven", "side", "shire"},
|
||||||
|
"city": {"New York City", "Los Angeles", "Chicago", "Houston", "Philadelphia", "Phoenix", "San Antonio", "San Diego", "Dallas", "San Jose", "Austin", "Jacksonville", "Indianapolis", "San Francisco", "Columbus", "Fort Worth", "Charlotte", "Detroit", "El Paso", "Memphis", "Boston", "Seattle", "Denver", "Washington", "Nashville-Davidson", "Baltimore", "Louisville/Jefferson", "Portland", "Oklahoma", "Milwaukee", "Las Vegas", "Albuquerque", "Tucson", "Fresno", "Sacramento", "Long Beach", "Kansas", "Mesa", "Virginia Beach", "Atlanta", "Colorado Springs", "Raleigh", "Omaha", "Miami", "Oakland", "Tulsa", "Minneapolis", "Cleveland", "Wichita", "Arlington", "New Orleans", "Bakersfield", "Tampa", "Honolulu", "Anaheim", "Aurora", "Santa Ana", "St. Louis", "Riverside", "Corpus Christi", "Pittsburgh", "Lexington-Fayette", "Stockton", "Cincinnati", "St. Paul", "Toledo", "Newark", "Greensboro", "Plano", "Henderson", "Lincoln", "Buffalo", "Fort Wayne", "Jersey", "Chula Vista", "Orlando", "St. Petersburg", "Norfolk", "Chandler", "Laredo", "Madison", "Durham", "Lubbock", "Winston-Salem", "Garland", "Glendale", "Hialeah", "Reno", "Baton Rouge", "Irvine", "Chesapeake", "Irving", "Scottsdale", "North Las Vegas", "Fremont", "San Bernardino", "Boise", "Birmingham"},
|
||||||
|
"state": {"Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"},
|
||||||
|
"state_abr": {"AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY", "AE", "AA", "AP"},
|
||||||
|
"zip": {"#####"},
|
||||||
|
"country": {"Andorra", "United Arab Emirates", "Afghanistan", "Antigua and Barbuda", "Anguilla", "Albania", "Armenia", "Angola", "Antarctica", "Argentina", "American Samoa", "Austria", "Australia", "Aruba", "Åland Islands", "Azerbaijan", "Bosnia and Herzegovina", "Barbados", "Bangladesh", "Belgium", "Burkina Faso", "Bulgaria", "Bahrain", "Burundi", "Benin", "Saint Barthélemy", "Bermuda", "Brunei Darussalam", "Bolivia (Plurinational State of)", "Bonaire, Sint Eustatius and Saba", "Brazil", "Bahamas", "Bhutan", "Bouvet Island", "Botswana", "Belarus", "Belize", "Canada", "Cocos (Keeling) Islands", "Congo, Democratic Republic of the", "Central African Republic", "Congo", "Switzerland", "Côte d'Ivoire", "Cook Islands", "Chile", "Cameroon", "China", "Colombia", "Costa Rica", "Cuba", "Cabo Verde", "Curaçao", "Christmas Island", "Cyprus", "Czechia", "Germany", "Djibouti", "Denmark", "Dominica", "Dominican Republic", "Algeria", "Ecuador", "Estonia", "Egypt", "Western Sahara", "Eritrea", "Spain", "Ethiopia", "Finland", "Fiji", "Falkland Islands (Malvinas)", "Micronesia (Federated States of)", "Faroe Islands", "France", "Gabon", "United Kingdom of Great Britain and Northern Ireland", "Grenada", "Georgia", "French Guiana", "Guernsey", "Ghana", "Gibraltar", "Greenland", "Gambia", "Guinea", "Guadeloupe", "Equatorial Guinea", "Greece", "South Georgia and the South Sandwich Islands", "Guatemala", "Guam", "Guinea-Bissau", "Guyana", "Hong Kong", "Heard Island and McDonald Islands", "Honduras", "Croatia", "Haiti", "Hungary", "Indonesia", "Ireland", "Israel", "Isle of Man", "India", "British Indian Ocean Territory", "Iraq", "Iran (Islamic Republic of)", "Iceland", "Italy", "Jersey", "Jamaica", "Jordan", "Japan", "Kenya", "Kyrgyzstan", "Cambodia", "Kiribati", "Comoros", "Saint Kitts and Nevis", "Korea (Democratic People's Republic of)", "Korea, Republic of", "Kuwait", "Cayman Islands", "Kazakhstan", "Lao People's Democratic Republic", "Lebanon", "Saint Lucia", "Liechtenstein", "Sri Lanka", "Liberia", "Lesotho", "Lithuania", "Luxembourg", "Latvia", "Libya", "Morocco", "Monaco", "Moldova, Republic of", "Montenegro", "Saint Martin (French part)", "Madagascar", "Marshall Islands", "North Macedonia", "Mali", "Myanmar", "Mongolia", "Macao", "Northern Mariana Islands", "Martinique", "Mauritania", "Montserrat", "Malta", "Mauritius", "Maldives", "Malawi", "Mexico", "Malaysia", "Mozambique", "Namibia", "New Caledonia", "Niger", "Norfolk Island", "Nigeria", "Nicaragua", "Netherlands", "Norway", "Nepal", "Nauru", "Niue", "New Zealand", "Oman", "Panama", "Peru", "French Polynesia", "Papua New Guinea", "Philippines", "Pakistan", "Poland", "Saint Pierre and Miquelon", "Pitcairn", "Puerto Rico", "Palestine, State of", "Portugal", "Palau", "Paraguay", "Qatar", "Réunion", "Romania", "Serbia", "Russian Federation", "Rwanda", "Saudi Arabia", "Solomon Islands", "Seychelles", "Sudan", "Sweden", "Singapore", "Saint Helena, Ascension and Tristan da Cunha", "Slovenia", "Svalbard and Jan Mayen", "Slovakia", "Sierra Leone", "San Marino", "Senegal", "Somalia", "Suriname", "South Sudan", "Sao Tome and Principe", "El Salvador", "Sint Maarten (Dutch part)", "Syrian Arab Republic", "Eswatini", "Turks and Caicos Islands", "Chad", "French Southern Territories", "Togo", "Thailand", "Tajikistan", "Tokelau", "Timor-Leste", "Turkmenistan", "Tunisia", "Tonga", "Turkey", "Trinidad and Tobago", "Tuvalu", "Taiwan, Province of China", "Tanzania, United Republic of", "Ukraine", "Uganda", "United States Minor Outlying Islands", "United States of America", "Uruguay", "Uzbekistan", "Holy See", "Saint Vincent and the Grenadines", "Venezuela (Bolivarian Republic of)", "Virgin Islands (British)", "Virgin Islands (U.S.)", "Viet Nam", "Vanuatu", "Wallis and Futuna", "Samoa", "Yemen", "Mayotte", "South Africa", "Zambia", "Zimbabwe"},
|
||||||
|
"country_abr": {"AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS", "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", "WS", "YE", "YT", "ZA", "ZM", "ZW"},
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
package data
|
||||||
|
|
||||||
|
// Animal consists of animal information
|
||||||
|
var Animal = map[string][]string{
|
||||||
|
"petname": {"Alfalfa", "Archie", "Attila", "Baloo", "Bark Twain", "Barney", "Beans", "Bernadette", "Betty", "Binx", "Biscuit", "Bitsy", "Bob", "Bruiser", "Butterball", "Butters", "Chalupa", "Cheeseburger", "Chewbarka", "Chompers", "Cujo", "Demi", "Dobby", "Doc McDoggins", "Droolius Caesar", "Elmo", "Fergus", "Fluffernutter", "Franz Fur-dinand", "Frodo", "Fyodor Dogstoevsky", "Gary", "Gollum", "Hairy Paw-ter", "Hercules", "Hobbit", "Jabba", "Jellybean", "Jimmy Chew", "Kareem Abdul Ja-Bark", "Kevin", "Khaleesi", "Larry", "Lloyd", "Mary Puppins", "Matilda", "Meatball", "Mister Miyagi", "Moose", "Munchkin", "Nacho", "Noodles", "Nugget", "Olga", "Orville Redenbarker", "Ozzy Pawsborne", "Pam", "Peanut", "Pee Wee", "Pikachu", "Prince of Barkness", "Pumba", "Rambo", "Rex", "Rocky", "Rufus", "Salsa", "Salvador Dogi", "Santa Paws", "Sarah Jessica Barker", "Scrappy", "Sherlock Bones", "Squeakers", "Squirt", "Tank", "Tater", "The Notorious D.O.G.", "Toto", "Twinkie", "Waffles", "Waldo", "Winnie the Poodle", "Woofgang Puck", "Yoda", "Zeus"},
|
||||||
|
"animal": {"alligator", "alpaca", "ant", "antelope", "ape", "armadillo", "baboon", "badger", "bat", "bear", "beaver", "bee", "beetle", "buffalo", "butterfly", "camel", "caribou", "cat", "cattle", "cheetah", "chimpanzee", "chinchilla", "cicada", "clam", "cockroach", "cod", "coyote", "crab", "cricket", "crocodile", "crow", "deer", "dinosaur", "dog", "dolphin", "donkey", "duck", "eagle", "eel", "elephant", "elk", "ferret", "fish", "fly", "fox", "frog", "gerbil", "giraffe", "gnat", "gnu", "goat", "goldfish", "goose", "gorilla", "grasshopper", "guinea pig", "hamster", "hare", "hedgehog", "herring", "hippopotamus", "hornet", "horse", "hound", "hyena", "impala", "jackal", "jellyfish", "kangaroo", "koala", "leopard", "lion", "lizard", "llama", "locust", "louse", "macaw", "mallard", "mammoth", "manatee", "marten", "mink", "minnow", "mole", "monkey", "moose", "mosquito", "mouse", "mule", "muskrat", "otter", "ox", "oyster", "panda", "pig", "platypus", "porcupine", "porpoise", "prairie dog", "pug", "rabbit", "raccoon", "rat", "raven", "reindeer", "rhinoceros", "salmon", "sardine", "scorpion", "sea lion", "seal", "serval", "shark", "sheep", "skunk", "snail", "snake", "spider", "squirrel", "swan", "termite", "tiger", "toad", "tortoise", "trout", "turtle", "wallaby", "walrus", "wasp", "water buffalo", "weasel", "whale", "wildebeest", "wolf", "wombat", "woodchuck", "worm", "yak", "yellowjacket", "zebra"},
|
||||||
|
"type": {"amphibians", "birds", "fish", "invertebrates", "mammals", "reptiles"},
|
||||||
|
"farm": {"Chicken", "Cow", "Donkey", "Duck", "Goat", "Goose", "Horse", "Llama", "Pig", "Sheep", "Turkey"},
|
||||||
|
"cat": {"Abyssinian", "Aegean", "American Bobtail", "American Curl", "American Shorthair", "American Wirehair", "Arabian Mau", "Asian", "Asian Semi-longhair", "Australian Mist", "Balinese", "Bambino", "Bengal", "Birman", "Bombay", "Brazilian Shorthair", "British Longhair", "British Semipi-longhair", "British Shorthair", "Burmese", "Burmilla", "California Spangled", "Chantilly-Tiffany", "Chartreux", "Chausie", "Cheetoh", "Colorpoint Shorthair", "Cornish Rex", "Cymric, or Manx Longhair", "Cyprus", "Devon Rex", "Donskoy, or Don Sphynx", "Dragon Li", "Dwarf cat, or Dwelf", "Egyptian Mau", "European Shorthair", "Exotic Shorthair", "Foldex Cat", "German Rex", "Havana Brown", "Highlander", "Himalayan, or Colorpoint Persian", "Japanese Bobtail", "Javanese", "Khao Manee", "Korat", "Korean Bobtail", "Korn Ja", "Kurilian Bobtail", "Kurilian Bobtail, or Kuril Islands Bobtail", "LaPerm", "Lykoi", "Maine Coon", "Manx", "Mekong Bobtail", "Minskin", "Munchkin", "Napoleon", "Nebelung", "Norwegian Forest Cat", "Ocicat", "Ojos Azules", "Oregon Rex", "Oriental Bicolor", "Oriental Longhair", "Oriental Shorthair", "Persian", "Peterbald", "Pixie-bob", "Raas", "Ragamuffin", "Ragdoll", "Russian Blue", "Russian White, Black and Tabby", "Sam Sawet", "Savannah", "Scottish Fold", "Selkirk Rex", "Serengeti", "Serrade petit", "Siamese", "Siberian", "Singapura", "Snowshoe", "Sokoke", "Somali", "Sphynx", "Suphalak", "Thai", "Tonkinese", "Toyger", "Turkish Angora", "Turkish Van", "Ukrainian Levkoy"},
|
||||||
|
"dog": {"Affenpinscher", "African", "Airedale", "Akita", "Appenzeller", "Basenji", "Beagle", "Bluetick", "Borzoi", "Bouvier", "Boxer", "Brabancon", "Briard", "Boston Bulldog", "French Bulldog", "Staffordshire Bullterrier", "Cairn", "Chihuahua", "Chow", "Clumber", "Border Collie", "Coonhound", "Cardigan Corgi", "Dachshund", "Great Dane", "Scottish Deerhound", "Dhole", "Dingo", "Doberman", "Norwegian Elkhound", "Entlebucher", "Eskimo", "Germanshepherd", "Italian Greyhound", "Groenendael", "Ibizan Hound", "Afghan Hound", "Basset Hound", "Blood Hound", "English Hound", "Walker Hound", "Husky", "Keeshond", "Kelpie", "Komondor", "Kuvasz", "Labrador", "Leonberg", "Lhasa", "Malamute", "Malinois", "Maltese", "Bull Mastiff", "Tibetan Mastiff", "Mexicanhairless", "Bernese Mountain", "Swiss Mountain", "Newfoundland", "Otterhound", "Papillon", "Pekinese", "Pembroke", "Miniature Pinscher", "German Pointer", "Pomeranian", "Miniature Poodle", "Standard Poodle", "Toy Poodle", "Pug", "Pyrenees", "Redbone", "Chesapeake Retriever", "Curly Retriever", "Flatcoated Retriever", "Golden Retriever", "Rhodesian Ridgeback", "Rottweiler", "Saluki", "Samoyed", "Schipperke", "Giant Schnauzer", "Miniature Schnauzer", "English Setter", "Gordon Setter", "Irish Setter", "English Sheepdog", "Shetland Sheepdog", "Shiba", "Shihtzu", "Blenheim Spaniel", "Brittany Spaniel", "Cocker Spaniel", "Irish Spaniel", "Japanese Spaniel", "Sussex Spaniel", "Welsh Spaniel", "English Springer", "Stbernard", "American Terrier", "Australian Terrier", "Bedlington Terrier", "Border Terrier", "Dandie Terrier", "Fox Terrier", "Irish Terrier", "Kerryblue Terrier", "Lakeland Terrier", "Norfolk Terrier", "Norwich Terrier", "Patterdale Terrier", "Rat Terrier", "Scottish Terrier", "Sealyham Terrier", "Silky Terrier", "Tibetan Terrier", "Toy Terrier", "Westhighland Terrier", "Wheaten Terrier", "Yorkshire Terrier", "Vizsla", "Weimaraner", "Whippet", "Irish Wolfhound"},
|
||||||
|
"bird": {"albatross", "bluejay", "canary", "cardinal", "chicken", "crow", "dove", "duck", "eagle", "emu", "falcon", "flamingo", "goose", "hornbill", "hummingbird", "ibis", "jay", "kingfisher", "lovebird", "mynah", "nightingale", "oriole", "ostrich", "owl", "parrot", "peacock", "penguin", "quail", "rooster", "sparrow", "swan", "thrush", "toucan", "vulture", "woodpecker", "yellow warbler"},
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
package data
|
||||||
|
|
||||||
|
// Beer consists of various beer information
|
||||||
|
var Beer = map[string][]string{
|
||||||
|
"name": {"Pliny The Elder", "Founders Kentucky Breakfast", "Trappistes Rochefort 10", "HopSlam Ale", "Stone Imperial Russian Stout", "St. Bernardus Abt 12", "Founders Breakfast Stout", "Weihenstephaner Hefeweissbier", "Péché Mortel", "Celebrator Doppelbock", "Duvel", "Dreadnaught IPA", "Nugget Nectar", "La Fin Du Monde", "Bourbon County Stout", "Old Rasputin Russian Imperial Stout", "Two Hearted Ale", "Ruination IPA", "Schneider Aventinus", "Double Bastard Ale", "90 Minute IPA", "Hop Rod Rye", "Trappistes Rochefort 8", "Chimay Grande Réserve", "Stone IPA", "Arrogant Bastard Ale", "Edmund Fitzgerald Porter", "Chocolate St", "Oak Aged Yeti Imperial Stout", "Ten FIDY", "Storm King Stout", "Shakespeare Oatmeal", "Alpha King Pale Ale", "Westmalle Trappist Tripel", "Samuel Smith’s Imperial IPA", "Yeti Imperial Stout", "Hennepin", "Samuel Smith’s Oatmeal Stout", "Brooklyn Black", "Oaked Arrogant Bastard Ale", "Sublimely Self-Righteous Ale", "Trois Pistoles", "Bell’s Expedition", "Sierra Nevada Celebration Ale", "Sierra Nevada Bigfoot Barleywine Style Ale", "Racer 5 India Pale Ale, Bear Republic Bre", "Orval Trappist Ale", "Hercules Double IPA", "Maharaj", "Maudite"},
|
||||||
|
"hop": {"Ahtanum", "Amarillo", "Bitter Gold", "Bravo", "Brewer’s Gold", "Bullion", "Cascade", "Cashmere", "Centennial", "Chelan", "Chinook", "Citra", "Cluster", "Columbia", "Columbus", "Comet", "Crystal", "Equinox", "Eroica", "Fuggle", "Galena", "Glacier", "Golding", "Hallertau", "Horizon", "Liberty", "Magnum", "Millennium", "Mosaic", "Mt. Hood", "Mt. Rainier", "Newport", "Northern Brewer", "Nugget", "Olympic", "Palisade", "Perle", "Saaz", "Santiam", "Simcoe", "Sorachi Ace", "Sterling", "Summit", "Tahoma", "Tettnang", "TriplePearl", "Ultra", "Vanguard", "Warrior", "Willamette", "Yakima Gol"},
|
||||||
|
"yeast": {"1007 - German Ale", "1010 - American Wheat", "1028 - London Ale", "1056 - American Ale", "1084 - Irish Ale", "1098 - British Ale", "1099 - Whitbread Ale", "1187 - Ringwood Ale", "1272 - American Ale II", "1275 - Thames Valley Ale", "1318 - London Ale III", "1332 - Northwest Ale", "1335 - British Ale II", "1450 - Dennys Favorite 50", "1469 - West Yorkshire Ale", "1728 - Scottish Ale", "1968 - London ESB Ale", "2565 - Kölsch", "1214 - Belgian Abbey", "1388 - Belgian Strong Ale", "1762 - Belgian Abbey II", "3056 - Bavarian Wheat Blend", "3068 - Weihenstephan Weizen", "3278 - Belgian Lambic Blend", "3333 - German Wheat", "3463 - Forbidden Fruit", "3522 - Belgian Ardennes", "3638 - Bavarian Wheat", "3711 - French Saison", "3724 - Belgian Saison", "3763 - Roeselare Ale Blend", "3787 - Trappist High Gravity", "3942 - Belgian Wheat", "3944 - Belgian Witbier", "2000 - Budvar Lager", "2001 - Urquell Lager", "2007 - Pilsen Lager", "2035 - American Lager", "2042 - Danish Lager", "2112 - California Lager", "2124 - Bohemian Lager", "2206 - Bavarian Lager", "2278 - Czech Pils", "2308 - Munich Lager", "2633 - Octoberfest Lager Blend", "5112 - Brettanomyces bruxellensis", "5335 - Lactobacillus", "5526 - Brettanomyces lambicus", "5733 - Pediococcus"},
|
||||||
|
"malt": {"Black malt", "Caramel", "Carapils", "Chocolate", "Munich", "Caramel", "Carapils", "Chocolate malt", "Munich", "Pale", "Roasted barley", "Rye malt", "Special roast", "Victory", "Vienna", "Wheat mal"},
|
||||||
|
"style": {"Light Lager", "Pilsner", "European Amber Lager", "Dark Lager", "Bock", "Light Hybrid Beer", "Amber Hybrid Beer", "English Pale Ale", "Scottish And Irish Ale", "Merican Ale", "English Brown Ale", "Porter", "Stout", "India Pale Ale", "German Wheat And Rye Beer", "Belgian And French Ale", "Sour Ale", "Belgian Strong Ale", "Strong Ale", "Fruit Beer", "Vegetable Beer", "Smoke-flavored", "Wood-aged Beer"},
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,101 @@
|
||||||
|
package data
|
||||||
|
|
||||||
|
var Books = map[string][]string{
|
||||||
|
"title": {
|
||||||
|
"Anna Karenina",
|
||||||
|
"Beloved",
|
||||||
|
"Blindness",
|
||||||
|
"Bostan",
|
||||||
|
"Buddenbrooks",
|
||||||
|
"Crime and Punishment",
|
||||||
|
"Don Quijote De La Mancha",
|
||||||
|
"Fairy tales",
|
||||||
|
"Faust",
|
||||||
|
"Gulliver's Travels",
|
||||||
|
"Gypsy Ballads",
|
||||||
|
"Hamlet",
|
||||||
|
"Harry potter and the sorcerer's stone",
|
||||||
|
"King Lear",
|
||||||
|
"Leaves of Grass",
|
||||||
|
"Lolita",
|
||||||
|
"Madame Bovary",
|
||||||
|
"Memoirs of Hadrian",
|
||||||
|
"Metamorphoses",
|
||||||
|
"Moby Dick",
|
||||||
|
"Nineteen Eighty-Four",
|
||||||
|
"Odyssey",
|
||||||
|
"Oedipus the King",
|
||||||
|
"One Hundred Years of Solitude",
|
||||||
|
"One Thousand and One Nights",
|
||||||
|
"Othello",
|
||||||
|
"Pippi Longstocking",
|
||||||
|
"Pride and Prejudice",
|
||||||
|
"Romeo & Juliet",
|
||||||
|
"Sherlock Holmes",
|
||||||
|
"Sons and Lovers",
|
||||||
|
"The Adventures of Huckleberry Finn",
|
||||||
|
"The Book Of Job",
|
||||||
|
"The Brothers Karamazov",
|
||||||
|
"The Golden Notebook",
|
||||||
|
"The Idiot",
|
||||||
|
"The Old Man and the Sea",
|
||||||
|
"The Stranger",
|
||||||
|
"Things Fall Apart",
|
||||||
|
"Ulysses",
|
||||||
|
"War and Peace",
|
||||||
|
"Wuthering Heights",
|
||||||
|
"Zorba the Greek",
|
||||||
|
},
|
||||||
|
"author": {
|
||||||
|
"Albert Camus",
|
||||||
|
"Astrid Lindgren",
|
||||||
|
"Charles Dickens",
|
||||||
|
"D. H. Lawrence",
|
||||||
|
"Edgar Allan Poe",
|
||||||
|
"Emily Brontë",
|
||||||
|
"Ernest Hemingway",
|
||||||
|
"Franz Kafka",
|
||||||
|
"Fyodor Dostoevsky",
|
||||||
|
"George Orwell",
|
||||||
|
"Hans Christian Andersen",
|
||||||
|
"Homer",
|
||||||
|
"James Joyce",
|
||||||
|
"Jane Austen",
|
||||||
|
"Johann Wolfgang von Goethe",
|
||||||
|
"Jorge Luis Borges",
|
||||||
|
"Joanne K. Rowling",
|
||||||
|
"Leo Tolstoy",
|
||||||
|
"Marcel Proust",
|
||||||
|
"Mark Twain",
|
||||||
|
"Paul Celan",
|
||||||
|
"Salman Rushdie",
|
||||||
|
"Sophocles",
|
||||||
|
"Thomas Mann",
|
||||||
|
"Toni Morrison",
|
||||||
|
"Vladimir Nabokov",
|
||||||
|
"William Faulkner",
|
||||||
|
"William Shakespeare",
|
||||||
|
"Yasunari Kawabata",
|
||||||
|
},
|
||||||
|
"genre": {
|
||||||
|
"Adventure",
|
||||||
|
"Comic",
|
||||||
|
"Crime",
|
||||||
|
"Erotic",
|
||||||
|
"Fiction",
|
||||||
|
"Fantasy",
|
||||||
|
"Historical",
|
||||||
|
"Horror",
|
||||||
|
"Magic",
|
||||||
|
"Mystery",
|
||||||
|
"Philosophical",
|
||||||
|
"Political",
|
||||||
|
"Romance",
|
||||||
|
"Saga",
|
||||||
|
"Satire",
|
||||||
|
"Science",
|
||||||
|
"Speculative",
|
||||||
|
"Thriller",
|
||||||
|
"Urban",
|
||||||
|
},
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,7 @@
|
||||||
|
package data
|
||||||
|
|
||||||
|
var Celebrity = map[string][]string{
|
||||||
|
"actor": {"Arnold Schwarzenegger", "Jim Carrey", "Emma Watson", "Robert Downey Jr.", "Daniel Radcliffe", "Chris Evans", "Leonardo DiCaprio", "Tom Cruise", "Brad Pitt", "Charles Chaplin", "Morgan Freeman", "Tom Hanks", "Hugh Jackman", "Matt Damon", "Sylvester Stallone", "Will Smith", "Clint Eastwood", "Cameron Diaz", "George Clooney", "Steven Spielberg", "Harrison Ford", "Robert De Niro", "Al Pacino", "Robert Downey Jr.", "Russell Crowe", "Liam Neeson", "Kate Winslet", "Mark Wahlberg", "Natalie Portman", "Pierce Brosnan", "Sean Connery", "Orlando Bloom", "Dwayne Johnson", "Jackie Chan", "Angelina Jolie", "Adam Sandler", "Scarlett Johansson", "Heath Ledger", "Anne Hathaway", "Jessica Alba", "Edward Norton", "Keira Knightley", "Bradley Cooper", "Will Ferrell", "Julia Roberts", "Nicolas Cage", "Daniel Craig", "Keanu Reeves", "Ian McKellen", "Halle Berry", "Bruce Willis", "Ben Stiller", "Tommy Lee Jones", "Antonio Banderas", "Denzel Washington", "Steve Carell", "Shia LaBeouf", "Megan Fox", "James Franco", "Mel Gibson", "Vin Diesel", "Tim Allen", "Robin Williams", "Kevin Spacey", "Jason Biggs", "Seann William Scott", "Jean-Claude Van Damme", "Zach Galifianakis", "Owen Wilson", "Christian Bale", "Peter Jackson", "Sandra Bullock", "Bruce Lee", "Drew Barrymore", "Macaulay Culkin", "Jack Nicholson", "Bill Murray", "Sigourney Weaver", "Jake Gyllenhaal", "Jason Statham", "Jet Li", "Kate Beckinsale", "Rowan Atkinson", "Marlon Brando", "John Travolta", "Channing Tatum", "Ben Affleck", "Shah Rukh Khan", "Jennifer Aniston", "Emma Stone", "Chris Hemsworth", "James McAvoy", "James Cameron", "Amitabh Bachchan", "Brendan Fraser", "Rachel McAdams", "Tom Hiddleston", "Aamir Khan"},
|
||||||
|
"business": {"Elon Musk", "Steve Jobs", "Jeff Bezos", "Bill Gates", "Mark Zuckerberg", "Sundar Pichai", "Walt Disney", "Warren Buffett", "Mukesh Ambani", "P. T. Barnum", "Colonel Sanders", "Ray Kroc", "Richard Branson", "Henry Ford", "Larry Page", "Steve Wozniak", "Ratan Tata", "John D. Rockefeller", "Madam C. J. Walker", "Tim Cook", "Andrew Carnegie", "Paul Allen", "Bobby Flay", "J. P. Morgan", "Satya Nadella", "Dhirubhai Ambani", "Carlos Slim", "Ross Perot", "Jamie Oliver", "Jack Ma", "Larry Ellison", "Sam Walton", "Sheryl Sandberg", "Marco Pierre White", "Indra Nooyi", "David Rockefeller", "Steve Ballmer", "Beyonce Knowles", "N. R. Narayana Murthy", "Mark Wahlberg", "Cameron Diaz", "Sergey Brin", "Howard Hughes", "Jessica Alba", "Dustin Moskovitz", "Eva Mendes", "Amancio Ortega Gaona", "Fred Trump", "Jamsetji Tata", "Kate Hudson", "Martha Stewart", "Peter Jones", "Marco Polo", "Susan Wojcicki", "Oskar Schindler", "Elizabeth Hurley", "Sean Combs", "Kate Spade", "Vincent McMahon", "David Chang", "Coco Chanel", "Vera Wang", "Arianna Huffington", "John McAfee", "Dany Garcia", "Richard Attenborough", "Donatella Versace", "Chris Hughes", "Alexis Ohanian", "J. Paul Getty", "Sharon Osbourne", "Bob Iger", "Kate Walsh", "Chris Gardner", "Jessica Simpson", "Guy Fieri", "Joy Mangano", "Wolfgang Puck", "Christie Brinkley", "Tom Steyer", "Evan Spiegel", "Hugh Hefner", "Preity Zinta", "Shane McMahon", "Salt Bae", "Mario Batali", "Bernard Arnault", "Michael Bloomberg", "Portia de Rossi", "Kevin O'Leary", "Roman Abramovich", "Jamie Dimon", "Rob Dyrdek", "Emeril Lagasse", "Kat Von D", "Karlie Kloss", "Antoni Porowski", "Edmond James de Rothschild", "Mitt Romney", "Aristotle Onassis", "Richard Benjamin Harrison", "Ben Bernanke", "Mark Cuban", "William Randolph Hearst", "Nate Robinson", "Alan Shepard", "Christina Anstead", "Laurene Powell Jobs", "Adam Weitsman", "Gladys Knight", "Gary Vaynerchuk", "Robert Kraft", "John Paul DeJoria", "Lori Greiner", "Carly Fiorina", "Lakshmi Mittal", "Jerry Jones", "Meg Whitman", "Azim Premji", "Lisa Vanderpump", "Dana White", "Russell Simmons", "Jennifer Flavin", "Harry Hamlin", "Conrad Hilton", "Prescott Bush", "Alvaro Morte", "Shigeru Miyamoto", "Phil Knight", "Jack Dorsey", "Barbara Bush", "Lee Iacocca", "Ma Huateng", "Rick Harrison", "Drew Scott", "Jawed Karim", "Daymond John", "Jaclyn Smith", "Maryse Ouellet", "Allegra Versace"},
|
||||||
|
"sport": {"Pele", "Usain Bolt", "Muhammad Ali", "Carl Lewis", "Jesse Owens", "Sir Donald Bradman", "Billie Jean King", "Eddy Merckx", "Jackie Joyner-Kersee", "Lionel Messi", "Babe Didrikson Zaharias", "Michael Jordan", "Larisa Latynina", "Diego Maradona", "Serena Williams", "Babe Ruth", "Roger Federer", "Martina Navratilova", "Michael Phelps", "Lottie Dod", "Sachin Tendulkar", "Johan Cruyff", "Tiger Woods", "Sonja Henie", "Aryton Senna", "Nadia Comaneci", "Sergei Bubka", "Emil Zatopek", "Manny Pacquiao", "Imran Khan", "Jackie Robinson", "Shane Warne", "Dhyan Chand", "Fred Perry", "Lin Dan", "Abebe Bikila", "Clara Hughes", "Jan-Ove Waldner", "Bobby Moore", "Bjorn Borg", "Karch Kiraly", "Bradley Wiggins", "Seve Ballesteros", "David Beckham", "Michael Schumacher", "Greg Lemond", "Mia Hamm", "Jacques Anquetil", "Jack Nicklaus", "Steve Davis", "John McEnroe", "Monica Seles", "Magic Johnson", "Joe DiMaggio", "Roger Bannister", "Mo Farah", "Mark Spitz", "Chris Evert", "Al Oerter", "Jimmy Connors", "Michael Johnson", "Ian Botham", "Jim Thorpe", "Sir Steve Redgrave", "Steffi Graf", "Sebastian Coe", "Hicham El Guerrouj", "Eric Liddell", "W.G Grace", "Kenenisa Bekele", "Bernard Hinault", "Bob Beamon", "Paavo Nurmi", "David Campese", "Kelly Slater", "Haile Gebreselassie", "Rafael Nadal", "Brian Lara", "Chris Hoy", "Serge Blanco", "Cristiano Ronaldo", "Sir Gary Sobers", "Andy Murray", "George Best", "Sir Viv Richards", "Fausto Coppi", "Eusebio", "Rod Laver", "Grete Waitz", "Margaret Smith Court", "Tegla Laroupe", "Fanny Blankers-Koen", "Asbel Kiprop", "Lewis Hamilton", "C.B.Fry", "Annika Sörenstam", "Wilma Rudolph", "Alberta Tomba", "Bo Jackson"},
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,110 @@
|
||||||
|
package data
|
||||||
|
|
||||||
|
// Colors consists of color information
|
||||||
|
var Colors = map[string][]string{
|
||||||
|
"safe": {"black", "maroon", "green", "navy", "olive", "purple", "teal", "lime", "blue", "silver", "gray", "yellow", "fuchsia", "aqua", "white"},
|
||||||
|
"full": {"AliceBlue", "AntiqueWhite", "Aqua", "Aquamarine", "Azure", "Beige", "Bisque", "Black", "BlanchedAlmond", "Blue", "BlueViolet", "Brown", "BurlyWood", "CadetBlue", "Chartreuse", "Chocolate", "Coral", "CornflowerBlue", "Cornsilk", "Crimson", "Cyan", "DarkBlue", "DarkCyan", "DarkGoldenRod", "DarkGray", "DarkGreen", "DarkKhaki", "DarkMagenta", "DarkOliveGreen", "Darkorange", "DarkOrchid", "DarkRed", "DarkSalmon", "DarkSeaGreen", "DarkSlateBlue", "DarkSlateGray", "DarkTurquoise", "DarkViolet", "DeepPink", "DeepSkyBlue", "DimGray", "DimGrey", "DodgerBlue", "FireBrick", "FloralWhite", "ForestGreen", "Fuchsia", "Gainsboro", "GhostWhite", "Gold", "GoldenRod", "Gray", "Green", "GreenYellow", "HoneyDew", "HotPink", "IndianRed", "Indigo", "Ivory", "Khaki", "Lavender", "LavenderBlush", "LawnGreen", "LemonChiffon", "LightBlue", "LightCoral", "LightCyan", "LightGoldenRodYellow", "LightGray", "LightGreen", "LightPink", "LightSalmon", "LightSeaGreen", "LightSkyBlue", "LightSlateGray", "LightSteelBlue", "LightYellow", "Lime", "LimeGreen", "Linen", "Magenta", "Maroon", "MediumAquaMarine", "MediumBlue", "MediumOrchid", "MediumPurple", "MediumSeaGreen", "MediumSlateBlue", "MediumSpringGreen", "MediumTurquoise", "MediumVioletRed", "MidnightBlue", "MintCream", "MistyRose", "Moccasin", "NavajoWhite", "Navy", "OldLace", "Olive", "OliveDrab", "Orange", "OrangeRed", "Orchid", "PaleGoldenRod", "PaleGreen", "PaleTurquoise", "PaleVioletRed", "PapayaWhip", "PeachPuff", "Peru", "Pink", "Plum", "PowderBlue", "Purple", "Red", "RosyBrown", "RoyalBlue", "SaddleBrown", "Salmon", "SandyBrown", "SeaGreen", "SeaShell", "Sienna", "Silver", "SkyBlue", "SlateBlue", "SlateGray", "Snow", "SpringGreen", "SteelBlue", "Tan", "Teal", "Thistle", "Tomato", "Turquoise", "Violet", "Wheat", "White", "WhiteSmoke", "Yellow", "YellowGreen"},
|
||||||
|
}
|
||||||
|
|
||||||
|
var ColorsNice = [][]string{
|
||||||
|
{"#69d2e7", "#a7dbd8", "#e0e4cc", "#f38630", "#fa6900"},
|
||||||
|
{"#fe4365", "#fc9d9a", "#f9cdad", "#c8c8a9", "#83af9b"},
|
||||||
|
{"#ecd078", "#d95b43", "#c02942", "#542437", "#53777a"},
|
||||||
|
{"#556270", "#4ecdc4", "#c7f464", "#ff6b6b", "#c44d58"},
|
||||||
|
{"#774f38", "#e08e79", "#f1d4af", "#ece5ce", "#c5e0dc"},
|
||||||
|
{"#e8ddcb", "#cdb380", "#036564", "#033649", "#031634"},
|
||||||
|
{"#490a3d", "#bd1550", "#e97f02", "#f8ca00", "#8a9b0f"},
|
||||||
|
{"#594f4f", "#547980", "#45ada8", "#9de0ad", "#e5fcc2"},
|
||||||
|
{"#00a0b0", "#6a4a3c", "#cc333f", "#eb6841", "#edc951"},
|
||||||
|
{"#e94e77", "#d68189", "#c6a49a", "#c6e5d9", "#f4ead5"},
|
||||||
|
{"#3fb8af", "#7fc7af", "#dad8a7", "#ff9e9d", "#ff3d7f"},
|
||||||
|
{"#d9ceb2", "#948c75", "#d5ded9", "#7a6a53", "#99b2b7"},
|
||||||
|
{"#ffffff", "#cbe86b", "#f2e9e1", "#1c140d", "#cbe86b"},
|
||||||
|
{"#efffcd", "#dce9be", "#555152", "#2e2633", "#99173c"},
|
||||||
|
{"#343838", "#005f6b", "#008c9e", "#00b4cc", "#00dffc"},
|
||||||
|
{"#413e4a", "#73626e", "#b38184", "#f0b49e", "#f7e4be"},
|
||||||
|
{"#ff4e50", "#fc913a", "#f9d423", "#ede574", "#e1f5c4"},
|
||||||
|
{"#99b898", "#fecea8", "#ff847c", "#e84a5f", "#2a363b"},
|
||||||
|
{"#655643", "#80bca3", "#f6f7bd", "#e6ac27", "#bf4d28"},
|
||||||
|
{"#00a8c6", "#40c0cb", "#f9f2e7", "#aee239", "#8fbe00"},
|
||||||
|
{"#351330", "#424254", "#64908a", "#e8caa4", "#cc2a41"},
|
||||||
|
{"#554236", "#f77825", "#d3ce3d", "#f1efa5", "#60b99a"},
|
||||||
|
{"#5d4157", "#838689", "#a8caba", "#cad7b2", "#ebe3aa"},
|
||||||
|
{"#8c2318", "#5e8c6a", "#88a65e", "#bfb35a", "#f2c45a"},
|
||||||
|
{"#fad089", "#ff9c5b", "#f5634a", "#ed303c", "#3b8183"},
|
||||||
|
{"#ff4242", "#f4fad2", "#d4ee5e", "#e1edb9", "#f0f2eb"},
|
||||||
|
{"#f8b195", "#f67280", "#c06c84", "#6c5b7b", "#355c7d"},
|
||||||
|
{"#d1e751", "#ffffff", "#000000", "#4dbce9", "#26ade4"},
|
||||||
|
{"#1b676b", "#519548", "#88c425", "#bef202", "#eafde6"},
|
||||||
|
{"#5e412f", "#fcebb6", "#78c0a8", "#f07818", "#f0a830"},
|
||||||
|
{"#bcbdac", "#cfbe27", "#f27435", "#f02475", "#3b2d38"},
|
||||||
|
{"#452632", "#91204d", "#e4844a", "#e8bf56", "#e2f7ce"},
|
||||||
|
{"#eee6ab", "#c5bc8e", "#696758", "#45484b", "#36393b"},
|
||||||
|
{"#f0d8a8", "#3d1c00", "#86b8b1", "#f2d694", "#fa2a00"},
|
||||||
|
{"#2a044a", "#0b2e59", "#0d6759", "#7ab317", "#a0c55f"},
|
||||||
|
{"#f04155", "#ff823a", "#f2f26f", "#fff7bd", "#95cfb7"},
|
||||||
|
{"#b9d7d9", "#668284", "#2a2829", "#493736", "#7b3b3b"},
|
||||||
|
{"#bbbb88", "#ccc68d", "#eedd99", "#eec290", "#eeaa88"},
|
||||||
|
{"#b3cc57", "#ecf081", "#ffbe40", "#ef746f", "#ab3e5b"},
|
||||||
|
{"#a3a948", "#edb92e", "#f85931", "#ce1836", "#009989"},
|
||||||
|
{"#300030", "#480048", "#601848", "#c04848", "#f07241"},
|
||||||
|
{"#67917a", "#170409", "#b8af03", "#ccbf82", "#e33258"},
|
||||||
|
{"#aab3ab", "#c4cbb7", "#ebefc9", "#eee0b7", "#e8caaf"},
|
||||||
|
{"#e8d5b7", "#0e2430", "#fc3a51", "#f5b349", "#e8d5b9"},
|
||||||
|
{"#ab526b", "#bca297", "#c5ceae", "#f0e2a4", "#f4ebc3"},
|
||||||
|
{"#607848", "#789048", "#c0d860", "#f0f0d8", "#604848"},
|
||||||
|
{"#b6d8c0", "#c8d9bf", "#dadabd", "#ecdbbc", "#fedcba"},
|
||||||
|
{"#a8e6ce", "#dcedc2", "#ffd3b5", "#ffaaa6", "#ff8c94"},
|
||||||
|
{"#3e4147", "#fffedf", "#dfba69", "#5a2e2e", "#2a2c31"},
|
||||||
|
{"#fc354c", "#29221f", "#13747d", "#0abfbc", "#fcf7c5"},
|
||||||
|
{"#cc0c39", "#e6781e", "#c8cf02", "#f8fcc1", "#1693a7"},
|
||||||
|
{"#1c2130", "#028f76", "#b3e099", "#ffeaad", "#d14334"},
|
||||||
|
{"#a7c5bd", "#e5ddcb", "#eb7b59", "#cf4647", "#524656"},
|
||||||
|
{"#dad6ca", "#1bb0ce", "#4f8699", "#6a5e72", "#563444"},
|
||||||
|
{"#5c323e", "#a82743", "#e15e32", "#c0d23e", "#e5f04c"},
|
||||||
|
{"#edebe6", "#d6e1c7", "#94c7b6", "#403b33", "#d3643b"},
|
||||||
|
{"#fdf1cc", "#c6d6b8", "#987f69", "#e3ad40", "#fcd036"},
|
||||||
|
{"#230f2b", "#f21d41", "#ebebbc", "#bce3c5", "#82b3ae"},
|
||||||
|
{"#b9d3b0", "#81bda4", "#b28774", "#f88f79", "#f6aa93"},
|
||||||
|
{"#3a111c", "#574951", "#83988e", "#bcdea5", "#e6f9bc"},
|
||||||
|
{"#5e3929", "#cd8c52", "#b7d1a3", "#dee8be", "#fcf7d3"},
|
||||||
|
{"#1c0113", "#6b0103", "#a30006", "#c21a01", "#f03c02"},
|
||||||
|
{"#000000", "#9f111b", "#b11623", "#292c37", "#cccccc"},
|
||||||
|
{"#382f32", "#ffeaf2", "#fcd9e5", "#fbc5d8", "#f1396d"},
|
||||||
|
{"#e3dfba", "#c8d6bf", "#93ccc6", "#6cbdb5", "#1a1f1e"},
|
||||||
|
{"#f6f6f6", "#e8e8e8", "#333333", "#990100", "#b90504"},
|
||||||
|
{"#1b325f", "#9cc4e4", "#e9f2f9", "#3a89c9", "#f26c4f"},
|
||||||
|
{"#a1dbb2", "#fee5ad", "#faca66", "#f7a541", "#f45d4c"},
|
||||||
|
{"#c1b398", "#605951", "#fbeec2", "#61a6ab", "#accec0"},
|
||||||
|
{"#5e9fa3", "#dcd1b4", "#fab87f", "#f87e7b", "#b05574"},
|
||||||
|
{"#951f2b", "#f5f4d7", "#e0dfb1", "#a5a36c", "#535233"},
|
||||||
|
{"#8dccad", "#988864", "#fea6a2", "#f9d6ac", "#ffe9af"},
|
||||||
|
{"#2d2d29", "#215a6d", "#3ca2a2", "#92c7a3", "#dfece6"},
|
||||||
|
{"#413d3d", "#040004", "#c8ff00", "#fa023c", "#4b000f"},
|
||||||
|
{"#eff3cd", "#b2d5ba", "#61ada0", "#248f8d", "#605063"},
|
||||||
|
{"#ffefd3", "#fffee4", "#d0ecea", "#9fd6d2", "#8b7a5e"},
|
||||||
|
{"#cfffdd", "#b4dec1", "#5c5863", "#a85163", "#ff1f4c"},
|
||||||
|
{"#9dc9ac", "#fffec7", "#f56218", "#ff9d2e", "#919167"},
|
||||||
|
{"#4e395d", "#827085", "#8ebe94", "#ccfc8e", "#dc5b3e"},
|
||||||
|
{"#a8a7a7", "#cc527a", "#e8175d", "#474747", "#363636"},
|
||||||
|
{"#f8edd1", "#d88a8a", "#474843", "#9d9d93", "#c5cfc6"},
|
||||||
|
{"#046d8b", "#309292", "#2fb8ac", "#93a42a", "#ecbe13"},
|
||||||
|
{"#f38a8a", "#55443d", "#a0cab5", "#cde9ca", "#f1edd0"},
|
||||||
|
{"#a70267", "#f10c49", "#fb6b41", "#f6d86b", "#339194"},
|
||||||
|
{"#ff003c", "#ff8a00", "#fabe28", "#88c100", "#00c176"},
|
||||||
|
{"#ffedbf", "#f7803c", "#f54828", "#2e0d23", "#f8e4c1"},
|
||||||
|
{"#4e4d4a", "#353432", "#94ba65", "#2790b0", "#2b4e72"},
|
||||||
|
{"#0ca5b0", "#4e3f30", "#fefeeb", "#f8f4e4", "#a5b3aa"},
|
||||||
|
{"#4d3b3b", "#de6262", "#ffb88c", "#ffd0b3", "#f5e0d3"},
|
||||||
|
{"#fffbb7", "#a6f6af", "#66b6ab", "#5b7c8d", "#4f2958"},
|
||||||
|
{"#edf6ee", "#d1c089", "#b3204d", "#412e28", "#151101"},
|
||||||
|
{"#9d7e79", "#ccac95", "#9a947c", "#748b83", "#5b756c"},
|
||||||
|
{"#fcfef5", "#e9ffe1", "#cdcfb7", "#d6e6c3", "#fafbe3"},
|
||||||
|
{"#9cddc8", "#bfd8ad", "#ddd9ab", "#f7af63", "#633d2e"},
|
||||||
|
{"#30261c", "#403831", "#36544f", "#1f5f61", "#0b8185"},
|
||||||
|
{"#aaff00", "#ffaa00", "#ff00aa", "#aa00ff", "#00aaff"},
|
||||||
|
{"#d1313d", "#e5625c", "#f9bf76", "#8eb2c5", "#615375"},
|
||||||
|
{"#ffe181", "#eee9e5", "#fad3b2", "#ffba7f", "#ff9c97"},
|
||||||
|
{"#73c8a9", "#dee1b6", "#e1b866", "#bd5532", "#373b44"},
|
||||||
|
{"#805841", "#dcf7f3", "#fffcdd", "#ffd8d8", "#f5a2a2"},
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,8 @@
|
||||||
|
package data
|
||||||
|
|
||||||
|
// Computer consists of computer information
|
||||||
|
var Computer = map[string][]string{
|
||||||
|
"linux_processor": {"i686", "x86_64"},
|
||||||
|
"mac_processor": {"Intel", "PPC", "U; Intel", "U; PPC"},
|
||||||
|
"windows_platform": {"Windows NT 6.2", "Windows NT 6.1", "Windows NT 6.0", "Windows NT 5.2", "Windows NT 5.1", "Windows NT 5.01", "Windows NT 5.0", "Windows NT 4.0", "Windows 98; Win 9x 4.90", "Windows 98", "Windows 95", "Windows CE"},
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
package data
|
||||||
|
|
||||||
|
// Currency consists of currency information
|
||||||
|
var Currency = map[string][]string{
|
||||||
|
"short": {"AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BRL", "BSD", "BTN", "BWP", "BYR", "BZD", "CAD", "CDF", "CHF", "CLP", "CNY", "COP", "CRC", "CUC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "GBP", "GEL", "GGP", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "IMP", "INR", "IQD", "IRR", "ISK", "JEP", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LTL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRO", "MUR", "MVR", "MWK", "MXN", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLL", "SOS", "SPL", "SRD", "STD", "SVC", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TVD", "TWD", "TZS", "UAH", "UGX", "USD", "UYU", "UZS", "VEF", "VND", "VUV", "WST", "XAF", "XCD", "XDR", "XOF", "XPF", "YER", "ZAR", "ZMW", "ZWD"},
|
||||||
|
"long": {"United Arab Emirates Dirham", "Afghanistan Afghani", "Albania Lek", "Armenia Dram", "Netherlands Antilles Guilder", "Angola Kwanza", "Argentina Peso", "Australia Dollar", "Aruba Guilder", "Azerbaijan New Manat", "Bosnia and Herzegovina Convertible Marka", "Barbados Dollar", "Bangladesh Taka", "Bulgaria Lev", "Bahrain Dinar", "Burundi Franc", "Bermuda Dollar", "Brunei Darussalam Dollar", "Bolivia Boliviano", "Brazil Real", "Bahamas Dollar", "Bhutan Ngultrum", "Botswana Pula", "Belarus Ruble", "Belize Dollar", "Canada Dollar", "Congo/Kinshasa Franc", "Switzerland Franc", "Chile Peso", "China Yuan Renminbi", "Colombia Peso", "Costa Rica Colon", "Cuba Convertible Peso", "Cuba Peso", "Cape Verde Escudo", "Czech Republic Koruna", "Djibouti Franc", "Denmark Krone", "Dominican Republic Peso", "Algeria Dinar", "Egypt Pound", "Eritrea Nakfa", "Ethiopia Birr", "Euro Member Countries", "Fiji Dollar", "Falkland Islands (Malvinas) Pound", "United Kingdom Pound", "Georgia Lari", "Guernsey Pound", "Ghana Cedi", "Gibraltar Pound", "Gambia Dalasi", "Guinea Franc", "Guatemala Quetzal", "Guyana Dollar", "Hong Kong Dollar", "Honduras Lempira", "Croatia Kuna", "Haiti Gourde", "Hungary Forint", "Indonesia Rupiah", "Israel Shekel", "Isle of Man Pound", "India Rupee", "Iraq Dinar", "Iran Rial", "Iceland Krona", "Jersey Pound", "Jamaica Dollar", "Jordan Dinar", "Japan Yen", "Kenya Shilling", "Kyrgyzstan Som", "Cambodia Riel", "Comoros Franc", "Korea (North) Won", "Korea (South) Won", "Kuwait Dinar", "Cayman Islands Dollar", "Kazakhstan Tenge", "Laos Kip", "Lebanon Pound", "Sri Lanka Rupee", "Liberia Dollar", "Lesotho Loti", "Lithuania Litas", "Libya Dinar", "Morocco Dirham", "Moldova Leu", "Madagascar Ariary", "Macedonia Denar", "Myanmar (Burma) Kyat", "Mongolia Tughrik", "Macau Pataca", "Mauritania Ouguiya", "Mauritius Rupee", "Maldives (Maldive Islands) Rufiyaa", "Malawi Kwacha", "Mexico Peso", "Malaysia Ringgit", "Mozambique Metical", "Namibia Dollar", "Nigeria Naira", "Nicaragua Cordoba", "Norway Krone", "Nepal Rupee", "New Zealand Dollar", "Oman Rial", "Panama Balboa", "Peru Nuevo Sol", "Papua New Guinea Kina", "Philippines Peso", "Pakistan Rupee", "Poland Zloty", "Paraguay Guarani", "Qatar Riyal", "Romania New Leu", "Serbia Dinar", "Russia Ruble", "Rwanda Franc", "Saudi Arabia Riyal", "Solomon Islands Dollar", "Seychelles Rupee", "Sudan Pound", "Sweden Krona", "Singapore Dollar", "Saint Helena Pound", "Sierra Leone Leone", "Somalia Shilling", "Seborga Luigino", "Suriname Dollar", "São Tomé and Príncipe Dobra", "El Salvador Colon", "Syria Pound", "Swaziland Lilangeni", "Thailand Baht", "Tajikistan Somoni", "Turkmenistan Manat", "Tunisia Dinar", "Tonga Pa'anga", "Turkey Lira", "Trinidad and Tobago Dollar", "Tuvalu Dollar", "Taiwan New Dollar", "Tanzania Shilling", "Ukraine Hryvnia", "Uganda Shilling", "United States Dollar", "Uruguay Peso", "Uzbekistan Som", "Venezuela Bolivar", "Viet Nam Dong", "Vanuatu Vatu", "Samoa Tala", "Communauté Financière Africaine (BEAC) CFA Franc BEAC", "East Caribbean Dollar", "International Monetary Fund (IMF) Special Drawing Rights", "Communauté Financière Africaine (BCEAO) Franc", "Comptoirs Français du Pacifique (CFP) Franc", "Yemen Rial", "South Africa Rand", "Zambia Kwacha", "Zimbabwe Dollar"},
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,90 @@
|
||||||
|
package data
|
||||||
|
|
||||||
|
// Data consists of the main set of fake information
|
||||||
|
var Data = map[string]map[string][]string{
|
||||||
|
"person": Person,
|
||||||
|
"address": Address,
|
||||||
|
"company": Company,
|
||||||
|
"job": Job,
|
||||||
|
"lorem": Lorem,
|
||||||
|
"language": Languages,
|
||||||
|
"internet": Internet,
|
||||||
|
"file": Files,
|
||||||
|
"color": Colors,
|
||||||
|
"computer": Computer,
|
||||||
|
"hipster": Hipster,
|
||||||
|
"beer": Beer,
|
||||||
|
"hacker": Hacker,
|
||||||
|
"animal": Animal,
|
||||||
|
"currency": Currency,
|
||||||
|
"log_level": LogLevels,
|
||||||
|
"timezone": TimeZone,
|
||||||
|
"car": Car,
|
||||||
|
"emoji": Emoji,
|
||||||
|
"word": Word,
|
||||||
|
"sentence": Sentence,
|
||||||
|
"food": Food,
|
||||||
|
"minecraft": Minecraft,
|
||||||
|
"celebrity": Celebrity,
|
||||||
|
"error": Error,
|
||||||
|
"html": Html,
|
||||||
|
"book": Books,
|
||||||
|
"movie": Movies,
|
||||||
|
"school": School,
|
||||||
|
"product": Product,
|
||||||
|
}
|
||||||
|
|
||||||
|
func List() map[string][]string {
|
||||||
|
var list = make(map[string][]string)
|
||||||
|
|
||||||
|
// Loop through the data and add the keys to the list
|
||||||
|
for key := range Data {
|
||||||
|
list[key] = []string{}
|
||||||
|
|
||||||
|
// Loop through the sub data and add the keys to the list
|
||||||
|
for subkey := range Data[key] {
|
||||||
|
list[key] = append(list[key], subkey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
|
||||||
|
func Get(key string) map[string][]string {
|
||||||
|
// Make sure the key exists, if not return an empty map
|
||||||
|
if _, ok := Data[key]; !ok {
|
||||||
|
return make(map[string][]string)
|
||||||
|
}
|
||||||
|
|
||||||
|
return Data[key]
|
||||||
|
}
|
||||||
|
|
||||||
|
func Set(key string, data map[string][]string) {
|
||||||
|
Data[key] = data
|
||||||
|
}
|
||||||
|
|
||||||
|
func Remove(key string) {
|
||||||
|
delete(Data, key)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetSubData(key, subkey string) []string {
|
||||||
|
// Make sure the key exists, if not return an empty map
|
||||||
|
if _, ok := Data[key]; !ok {
|
||||||
|
return []string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Data[key][subkey]
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetSub(key, subkey string, data []string) {
|
||||||
|
// Make sure the key exists, if not add it
|
||||||
|
if _, ok := Data[key]; !ok {
|
||||||
|
Data[key] = make(map[string][]string)
|
||||||
|
}
|
||||||
|
|
||||||
|
Data[key][subkey] = data
|
||||||
|
}
|
||||||
|
|
||||||
|
func RemoveSub(key, subkey string) {
|
||||||
|
delete(Data[key], subkey)
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,122 @@
|
||||||
|
package data
|
||||||
|
|
||||||
|
var Error = map[string][]string{
|
||||||
|
"object": {
|
||||||
|
"argument",
|
||||||
|
"buffer",
|
||||||
|
"connection",
|
||||||
|
"database",
|
||||||
|
"header",
|
||||||
|
"hostname",
|
||||||
|
"method",
|
||||||
|
"object",
|
||||||
|
"parameter",
|
||||||
|
"pointer",
|
||||||
|
"port",
|
||||||
|
"protocol",
|
||||||
|
"request",
|
||||||
|
"response",
|
||||||
|
"server",
|
||||||
|
"service",
|
||||||
|
"signature",
|
||||||
|
"tag",
|
||||||
|
"undefined",
|
||||||
|
"url",
|
||||||
|
"uri",
|
||||||
|
"variable",
|
||||||
|
},
|
||||||
|
"generic": {
|
||||||
|
"error",
|
||||||
|
"syntax error",
|
||||||
|
"requested {errorobject} is unavailable",
|
||||||
|
"failed to {hackerverb} {errorobject}",
|
||||||
|
"expected {errorobject} is undefined",
|
||||||
|
"[object Object]",
|
||||||
|
"no such variable",
|
||||||
|
"{errorobject} not initialized",
|
||||||
|
"variable assigned before declaration",
|
||||||
|
},
|
||||||
|
"database": {
|
||||||
|
"sql error",
|
||||||
|
"database connection error",
|
||||||
|
"table does not exist",
|
||||||
|
"unique key constraint",
|
||||||
|
"table migration failed",
|
||||||
|
"bad connection",
|
||||||
|
"destination pointer is nil",
|
||||||
|
},
|
||||||
|
"grpc": {
|
||||||
|
"connection refused",
|
||||||
|
"connection closed",
|
||||||
|
"connection is shut down",
|
||||||
|
"client protocol error",
|
||||||
|
},
|
||||||
|
"http": {
|
||||||
|
"cross-origin-resource-policy error",
|
||||||
|
"feature not supported",
|
||||||
|
"trailer header without chunked transfer encoding",
|
||||||
|
"no multipart boundary param in Content-Type",
|
||||||
|
"request Content-Type isn't multipart/form-data",
|
||||||
|
"header too long",
|
||||||
|
"entity body too short",
|
||||||
|
"missing ContentLength in HEAD response",
|
||||||
|
"named cookie not present",
|
||||||
|
"invalid method",
|
||||||
|
"connection has been hijacked",
|
||||||
|
"request method or response status code does not allow body",
|
||||||
|
"wrote more than the declared Content-Length",
|
||||||
|
"{httpmethod} not allowed",
|
||||||
|
},
|
||||||
|
"http_client": { // 400s
|
||||||
|
"bad request", // 400
|
||||||
|
"unauthorized", // 401
|
||||||
|
"payment required", // 402
|
||||||
|
"forbidden", // 403
|
||||||
|
"not found", // 404
|
||||||
|
"method not allowed", // 405
|
||||||
|
"not acceptable", // 406
|
||||||
|
"proxy authentication required", // 407
|
||||||
|
"request timeout", // 408
|
||||||
|
"conflict", // 409
|
||||||
|
"gone", // 410
|
||||||
|
"length required", // 411
|
||||||
|
"precondition failed", // 412
|
||||||
|
"payload too large", // 413
|
||||||
|
"URI too long", // 414
|
||||||
|
"unsupported media type", // 415
|
||||||
|
"range not satisfiable", // 416
|
||||||
|
"expectation failed", // 417
|
||||||
|
"im a teapot", // 418
|
||||||
|
},
|
||||||
|
"http_server": { // 500s
|
||||||
|
"internal server error", // 500
|
||||||
|
"not implemented", // 501
|
||||||
|
"bad gateway", // 502
|
||||||
|
"service unavailable", // 503
|
||||||
|
"gateway timeout", // 504
|
||||||
|
"http version not supported", // 505
|
||||||
|
"variant also negotiates", // 506
|
||||||
|
"insufficient storage", // 507
|
||||||
|
"loop detected", // 508
|
||||||
|
"not extended", // 510
|
||||||
|
"network authentication required", // 511
|
||||||
|
},
|
||||||
|
"runtime": {
|
||||||
|
"panic: runtime error: invalid memory address or nil pointer dereference",
|
||||||
|
"address out of bounds",
|
||||||
|
"undefined has no such property 'length'",
|
||||||
|
"not enough arguments",
|
||||||
|
"expected 2 arguments, got 3",
|
||||||
|
},
|
||||||
|
"validation": {
|
||||||
|
"invalid format",
|
||||||
|
"missing required field",
|
||||||
|
"{inputname} is required",
|
||||||
|
"{inputname} max length exceeded",
|
||||||
|
"{inputname} must be at exactly 16 characters",
|
||||||
|
"{inputname} must be at exactly 32 bytes",
|
||||||
|
"failed to parse {inputname}",
|
||||||
|
"date is in the past",
|
||||||
|
"payment details cannot be verified",
|
||||||
|
},
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,20 @@
|
||||||
|
package data
|
||||||
|
|
||||||
|
// Hacker consists of random hacker phrases
|
||||||
|
var Hacker = map[string][]string{
|
||||||
|
"abbreviation": {"TCP", "HTTP", "SDD", "RAM", "GB", "CSS", "SSL", "AGP", "SQL", "FTP", "PCI", "AI", "ADP", "RSS", "XML", "EXE", "COM", "HDD", "THX", "SMTP", "SMS", "USB", "PNG", "SAS", "IB", "SCSI", "JSON", "XSS", "JBOD"},
|
||||||
|
"adjective": {"auxiliary", "primary", "back-end", "digital", "open-source", "virtual", "cross-platform", "redundant", "online", "haptic", "multi-byte", "bluetooth", "wireless", "1080p", "neural", "optical", "solid state", "mobile"},
|
||||||
|
"noun": {"driver", "protocol", "bandwidth", "panel", "microchip", "program", "port", "card", "array", "interface", "system", "sensor", "firewall", "hard drive", "pixel", "alarm", "feed", "monitor", "application", "transmitter", "bus", "circuit", "capacitor", "matrix"},
|
||||||
|
"verb": {"back up", "bypass", "hack", "override", "compress", "copy", "navigate", "index", "connect", "generate", "quantify", "calculate", "synthesize", "input", "transmit", "program", "reboot", "parse", "read", "write", "load", "render", "validate", "verify", "sign", "decrypt", "encrypt", "construct", "deconstruct", "compile", "transpile", "bundle", "lock", "unlock", "buffer", "format"},
|
||||||
|
"ingverb": {"backing up", "bypassing", "hacking", "overriding", "compressing", "copying", "navigating", "indexing", "connecting", "generating", "quantifying", "calculating", "synthesizing", "transmitting", "programming", "parsing"},
|
||||||
|
"phrase": {
|
||||||
|
"If we {hackerverb} the {hackernoun}, we can get to the {hackerabbreviation} {hackernoun} through the {hackeradjective} {hackerabbreviation} {hackernoun}!",
|
||||||
|
"We need to {hackerverb} the {hackeradjective} {hackerabbreviation} {hackernoun}!",
|
||||||
|
"Try to {hackerverb} the {hackerabbreviation} {hackernoun}, maybe it will {hackerverb} the {hackeradjective} {hackernoun}!",
|
||||||
|
"You can't {hackerverb} the {hackernoun} without {hackeringverb} the {hackeradjective} {hackerabbreviation} {hackernoun}!",
|
||||||
|
"Use the {hackeradjective} {hackerabbreviation} {hackernoun}, then you can {hackerverb} the {hackeradjective} {hackernoun}!",
|
||||||
|
"The {hackerabbreviation} {hackernoun} is down, {hackerverb} the {hackeradjective} {hackernoun} so we can {hackerverb} the {hackerabbreviation} {hackernoun}!",
|
||||||
|
"{hackeringverb} the {hackernoun} won't do anything, we need to {hackerverb} the {hackeradjective} {hackerabbreviation} {hackernoun}!",
|
||||||
|
"I'll {hackerverb} the {hackeradjective} {hackerabbreviation} {hackernoun}, that should {hackerverb} the {hackerabbreviation} {hackernoun}!",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
package data
|
||||||
|
|
||||||
|
// Hipster consists of random hipster words
|
||||||
|
var Hipster = map[string][]string{
|
||||||
|
"word": {"Wes Anderson", "chicharrones", "narwhal", "food truck", "marfa", "aesthetic", "keytar", "art party", "sustainable", "forage", "mlkshk", "gentrify", "locavore", "swag", "hoodie", "microdosing", "VHS", "before they sold out", "pabst", "plaid", "Thundercats", "freegan", "scenester", "hella", "occupy", "truffaut", "raw denim", "beard", "post-ironic", "photo booth", "twee", "90's", "pitchfork", "cray", "cornhole", "kale chips", "pour-over", "yr", "five dollar toast", "kombucha", "you probably haven't heard of them", "mustache", "fixie", "try-hard", "franzen", "kitsch", "austin", "stumptown", "keffiyeh", "whatever", "tumblr", "DIY", "shoreditch", "biodiesel", "vegan", "pop-up", "banjo", "kogi", "cold-pressed", "letterpress", "chambray", "butcher", "synth", "trust fund", "hammock", "farm-to-table", "intelligentsia", "loko", "ugh", "offal", "poutine", "gastropub", "Godard", "jean shorts", "sriracha", "dreamcatcher", "leggings", "fashion axe", "church-key", "meggings", "tote bag", "disrupt", "readymade", "helvetica", "flannel", "meh", "roof", "hashtag", "knausgaard", "cronut", "schlitz", "green juice", "waistcoat", "normcore", "viral", "ethical", "actually", "fingerstache", "humblebrag", "deep v", "wayfarers", "tacos", "taxidermy", "selvage", "put a bird on it", "ramps", "portland", "retro", "kickstarter", "bushwick", "brunch", "distillery", "migas", "flexitarian", "XOXO", "small batch", "messenger bag", "heirloom", "tofu", "bicycle rights", "bespoke", "salvia", "wolf", "selfies", "echo", "park", "listicle", "craft beer", "chartreuse", "sartorial", "pinterest", "mumblecore", "kinfolk", "vinyl", "etsy", "umami", "8-bit", "polaroid", "banh mi", "crucifix", "bitters", "brooklyn", "PBR&B", "drinking", "vinegar", "squid", "tattooed", "skateboard", "vice", "authentic", "literally", "lomo", "celiac", "health", "goth", "artisan", "chillwave", "blue bottle", "pickled", "next level", "neutra", "organic", "Yuccie", "paleo", "blog", "single-origin coffee", "seitan", "street", "gluten-free", "mixtape", "venmo", "irony", "everyday", "carry", "slow-carb", "3 wolf moon", "direct trade", "lo-fi", "tousled", "tilde", "semiotics", "cred", "chia", "master", "cleanse", "ennui", "quinoa", "pug", "iPhone", "fanny pack", "cliche", "cardigan", "asymmetrical", "meditation", "YOLO", "typewriter", "pork belly", "shabby chic", "+1", "lumbersexual", "williamsburg"},
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
package data
|
||||||
|
|
||||||
|
// Html consists of various html information
|
||||||
|
var Html = map[string][]string{
|
||||||
|
"svg": {"rect", "circle", "ellipse", "line", "polyline", "polygon"},
|
||||||
|
"input_name": {"title", "first_name", "last_name", "suffix", "address", "postal_code", "city", "state", "country", "date_of_birth", "card_number", "description", "message", "status"},
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
package data
|
||||||
|
|
||||||
|
// Internet consists of various internet information
|
||||||
|
var Internet = map[string][]string{
|
||||||
|
"browser": {"firefox", "chrome", "internetExplorer", "opera", "safari"},
|
||||||
|
"domain_suffix": {"com", "biz", "info", "name", "net", "org", "io"},
|
||||||
|
"http_method": {"HEAD", "GET", "POST", "PUT", "PATCH", "DELETE"},
|
||||||
|
"http_version": {"HTTP/1.0", "HTTP/1.1", "HTTP/2.0"},
|
||||||
|
"http_status_simple": {"200", "301", "302", "400", "404", "500"},
|
||||||
|
"http_status_general": {"100", "200", "201", "203", "204", "205", "301", "302", "304", "400", "401", "403", "404", "405", "406", "416", "500", "501", "502", "503", "504"},
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
package data
|
||||||
|
|
||||||
|
// Job consists of job data
|
||||||
|
var Job = map[string][]string{
|
||||||
|
"title": {"Administrator", "Agent", "Analyst", "Architect", "Assistant", "Associate", "Consultant", "Coordinator", "Designer", "Developer", "Director", "Engineer", "Executive", "Facilitator", "Liaison", "Manager", "Officer", "Orchestrator", "Planner", "Producer", "Representative", "Specialist", "Strategist", "Supervisor", "Technician"},
|
||||||
|
"descriptor": {"Central", "Chief", "Corporate", "Customer", "Direct", "District", "Dynamic", "Dynamic", "Forward", "Future", "Global", "Human", "Internal", "International", "Investor", "Lead", "Legacy", "National", "Principal", "Product", "Regional", "Senior"},
|
||||||
|
"level": {"Accountability", "Accounts", "Applications", "Assurance", "Brand", "Branding", "Communications", "Configuration", "Creative", "Data", "Directives", "Division", "Factors", "Functionality", "Group", "Identity", "Implementation", "Infrastructure", "Integration", "Interactions", "Intranet", "Marketing", "Markets", "Metrics", "Mobility", "Operations", "Optimization", "Paradigm", "Program", "Quality", "Research", "Response", "Security", "Solutions", "Tactics", "Usability", "Web"},
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,8 @@
|
||||||
|
package data
|
||||||
|
|
||||||
|
// LogLevels consists of log levels for several types
|
||||||
|
var LogLevels = map[string][]string{
|
||||||
|
"general": {"error", "warning", "info", "fatal", "trace", "debug"},
|
||||||
|
"syslog": {"emerg", "alert", "crit", "err", "warning", "notice", "info", "debug"},
|
||||||
|
"apache": {"emerg", "alert", "crit", "error", "warn", "notice", "info", "debug", "trace1-8"},
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
package data
|
||||||
|
|
||||||
|
// Lorem consists of lorem ipsum information
|
||||||
|
var Lorem = map[string][]string{
|
||||||
|
"word": {"alias", "consequatur", "aut", "perferendis", "sit", "voluptatem", "accusantium", "doloremque", "aperiam", "eaque", "ipsa", "quae", "ab", "illo", "inventore", "veritatis", "et", "quasi", "architecto", "beatae", "vitae", "dicta", "sunt", "explicabo", "aspernatur", "aut", "odit", "aut", "fugit", "sed", "quia", "consequuntur", "magni", "dolores", "eos", "qui", "ratione", "voluptatem", "sequi", "nesciunt", "neque", "dolorem", "ipsum", "quia", "dolor", "sit", "amet", "consectetur", "adipisci", "velit", "sed", "quia", "non", "numquam", "eius", "modi", "tempora", "incidunt", "ut", "labore", "et", "dolore", "magnam", "aliquam", "quaerat", "voluptatem", "ut", "enim", "ad", "minima", "veniam", "quis", "nostrum", "exercitationem", "ullam", "corporis", "nemo", "enim", "ipsam", "voluptatem", "quia", "voluptas", "sit", "suscipit", "laboriosam", "nisi", "ut", "aliquid", "ex", "ea", "commodi", "consequatur", "quis", "autem", "vel", "eum", "iure", "reprehenderit", "qui", "in", "ea", "voluptate", "velit", "esse", "quam", "nihil", "molestiae", "et", "iusto", "odio", "dignissimos", "ducimus", "qui", "blanditiis", "praesentium", "laudantium", "totam", "rem", "voluptatum", "deleniti", "atque", "corrupti", "quos", "dolores", "et", "quas", "molestias", "excepturi", "sint", "occaecati", "cupiditate", "non", "provident", "sed", "ut", "perspiciatis", "unde", "omnis", "iste", "natus", "error", "similique", "sunt", "in", "culpa", "qui", "officia", "deserunt", "mollitia", "animi", "id", "est", "laborum", "et", "dolorum", "fuga", "et", "harum", "quidem", "rerum", "facilis", "est", "et", "expedita", "distinctio", "nam", "libero", "tempore", "cum", "soluta", "nobis", "est", "eligendi", "optio", "cumque", "nihil", "impedit", "quo", "porro", "quisquam", "est", "qui", "minus", "id", "quod", "maxime", "placeat", "facere", "possimus", "omnis", "voluptas", "assumenda", "est", "omnis", "dolor", "repellendus", "temporibus", "autem", "quibusdam", "et", "aut", "consequatur", "vel", "illum", "qui", "dolorem", "eum", "fugiat", "quo", "voluptas", "nulla", "pariatur", "at", "vero", "eos", "et", "accusamus", "officiis", "debitis", "aut", "rerum", "necessitatibus", "saepe", "eveniet", "ut", "et", "voluptates", "repudiandae", "sint", "et", "molestiae", "non", "recusandae", "itaque", "earum", "rerum", "hic", "tenetur", "a", "sapiente", "delectus", "ut", "aut", "reiciendis", "voluptatibus", "maiores", "doloribus", "asperiores", "repellat"},
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
package data
|
||||||
|
|
||||||
|
// Minecraft consists of various minecraft items
|
||||||
|
var Minecraft = map[string][]string{
|
||||||
|
"ore": {"coal", "copper", "iron", "gold", "redstone", "lapis", "diamond", "emerald"},
|
||||||
|
"wood": {"oak", "spruce", "birch", "jungle", "acacia", "dark oak"},
|
||||||
|
"armortier": {"leather", "chainmail", "iron", "gold", "diamond", "netherite"},
|
||||||
|
"armorpart": {"helmet", "chestplate", "leggings", "boots"},
|
||||||
|
"weapon": {"sword", "bow", "arrow", "trident", "shield"},
|
||||||
|
"tool": {"pickaxe", "axe", "shovel", "hoe", "fishing rod"},
|
||||||
|
"dye": {"white", "orange", "magenta", "light blue", "yellow", "lime", "pink", "gray", "light gray", "cyan", "purple", "blue", "brown", "green", "red", "black"},
|
||||||
|
"food": {"apple", "baked potato", "beetroot", "beetroot soup", "bread", "cake", "carrot", "chorus fruit", "cooked chicken", "cooked cod", "cooked mutton", "cooked salmon", "cookie", "enchanted golden apple", "golden apple", "glow berry", "golden carrot", "honey bottle", "melon slice", "mushroom stew", "poisonous potato", "potato", "pufferfish", "pumpkin pie", "rabbit stew", "raw beef", "raw chicken", "raw cod", "raw mutton", "raw porkchop", "raw rabbit", "raw salmon", "rotten flesh", "spider eye", "steak", "suspicous stew", "sweet berry", "tropical fish"},
|
||||||
|
"animal": {"chicken", "cow", "pig", "rabbit", "sheep", "wolf"},
|
||||||
|
"villagerjob": {"armourer", "butcher", "carpenter", "cleric", "farmer", "fisherman", "fletcher", "leatherworker", "librarian", "mason", "nitwit", "shepherd", "toolsmith", "weaponsmith"},
|
||||||
|
"villagerstation": {"composter", "smoker", "barrel", "loom", "blast furnace", "brewing stand", "cauldron", "fletching table", "cartography table", "lectern", "smithing table", "stonecutter", "grindstone"},
|
||||||
|
"villagerlevel": {"novice", "apprentice", "journeyman", "expert", "master"},
|
||||||
|
"mobpassive": {"axolotl", "bat", "cat", "chicken", "cod", "cow", "donkey", "fox", "glow squid", "horse", "mooshroom", "mule", "ocelot", "parrot", "pig", "pufferfish", "rabbit", "salmon", "sheep", "skeleton horse", "snow golem", "squid", "strider", "tropical fish", "turtle", "villager", "wandering trader"},
|
||||||
|
"mobneutral": {"bee", "cave spider", "dolphin", "enderman", "goat", "iron golem", "llama", "panda", "piglin", "polar bear", "spider", "trader llama", "wolf", "zombified piglin"},
|
||||||
|
"mobhostile": {"blaze", "chicken jockey", "creeper", "drowned", "elder guardian", "endermite", "evoker", "ghast", "guardian", "hoglin phantom", "husk", "magma cube", "phantom", "piglin brute", "pillager", "ravager", "shulker", "silverfish", "skeleton", "skeleton horseman", "slime", "spider jockey", "stray", "vex", "vindicator", "witch", "wither skeleton", "zoglin", "zombie", "zombie villager"},
|
||||||
|
"mobboss": {"ender dragon", "wither"},
|
||||||
|
"biome": {"plain", "forest", "jungle", "mountain", "desert", "taiga", "snowy tundra", "ice spike", "swamp", "savannah", "badlands", "beach", "stone shore", "river", "ocean", "mushroom island", "the nether", "the end"},
|
||||||
|
"weather": {"clear", "rain", "thunder"},
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,130 @@
|
||||||
|
package data
|
||||||
|
|
||||||
|
// From IMDB - Top 250 Movies subset to 100
|
||||||
|
var Movies = map[string][]string{
|
||||||
|
"name": {
|
||||||
|
"12 Years a Slave",
|
||||||
|
"1917",
|
||||||
|
"2001: A Space Odyssey",
|
||||||
|
"3 Idiots",
|
||||||
|
"A Beautiful Mind",
|
||||||
|
"A Clockwork Orange",
|
||||||
|
"Alien",
|
||||||
|
"American Beauty",
|
||||||
|
"American History X",
|
||||||
|
"Apocalypse Now",
|
||||||
|
"Avengers: Infinity War",
|
||||||
|
"Back to the Future",
|
||||||
|
"Batman Begins",
|
||||||
|
"Ben-Hur",
|
||||||
|
"Blade Runner",
|
||||||
|
"Casablanca",
|
||||||
|
"Casino",
|
||||||
|
"Catch Me If You Can",
|
||||||
|
"Das Leben der Anderen",
|
||||||
|
"Dead Poets Society",
|
||||||
|
"Die Hard",
|
||||||
|
"Django Unchained",
|
||||||
|
"Fight Club",
|
||||||
|
"Finding Nemo",
|
||||||
|
"Forrest Gump",
|
||||||
|
"Full Metal Jacket",
|
||||||
|
"Gandhi",
|
||||||
|
"Gladiator",
|
||||||
|
"Gone with the Wind",
|
||||||
|
"Good Will Hunting",
|
||||||
|
"Goodfellas",
|
||||||
|
"Green Book",
|
||||||
|
"Groundhog Day",
|
||||||
|
"Harry Potter and the Deathly Hallows - Part 2",
|
||||||
|
"Heat",
|
||||||
|
"Inception",
|
||||||
|
"Indiana Jones and the Last Crusade",
|
||||||
|
"Inglourious Basterds",
|
||||||
|
"Interstellar",
|
||||||
|
"Into the Wild",
|
||||||
|
"Intouchables",
|
||||||
|
"Joker",
|
||||||
|
"Judgment at Nuremberg",
|
||||||
|
"Jurassic Park",
|
||||||
|
"Kill Bill: Vol. 1",
|
||||||
|
"L.A. Confidential",
|
||||||
|
"La vita è bella",
|
||||||
|
"Lock, Stock and Two Smoking Barrels",
|
||||||
|
"Léon",
|
||||||
|
"Mad Max: Fury Road",
|
||||||
|
"Memento",
|
||||||
|
"Million Dollar Baby",
|
||||||
|
"Monsters, Inc.",
|
||||||
|
"Monty Python and the Holy Grail",
|
||||||
|
"No Country for Old Men",
|
||||||
|
"Once Upon a Time in America",
|
||||||
|
"One Flew Over the Cuckoo's Nest",
|
||||||
|
"Pirates of the Caribbean: The Curse of the Black Pearl",
|
||||||
|
"Platoon",
|
||||||
|
"Prisoners",
|
||||||
|
"Psycho",
|
||||||
|
"Pulp Fiction",
|
||||||
|
"Raiders of the Lost Ark",
|
||||||
|
"Ratatouille",
|
||||||
|
"Reservoir Dogs",
|
||||||
|
"Rocky",
|
||||||
|
"Saving Private Ryan",
|
||||||
|
"Scarface",
|
||||||
|
"Schindler's List",
|
||||||
|
"Se7en",
|
||||||
|
"Sherlock Jr.",
|
||||||
|
"Shutter Island",
|
||||||
|
"Snatch",
|
||||||
|
"Spider-Man: No Way Home",
|
||||||
|
"Star Wars: Episode VI - Return of the Jedi",
|
||||||
|
"Taxi Driver",
|
||||||
|
"Terminator 2: Judgment Day",
|
||||||
|
"The Big Lebowski",
|
||||||
|
"The Dark Knight",
|
||||||
|
"The Departed",
|
||||||
|
"The Empire Strikes Back",
|
||||||
|
"The Godfather",
|
||||||
|
"The Green Mile",
|
||||||
|
"The Lion King",
|
||||||
|
"The Lord of the Rings: The Fellowship of the Ring",
|
||||||
|
"The Matrix",
|
||||||
|
"The Pianist",
|
||||||
|
"The Prestige",
|
||||||
|
"The Shawshank Redemption",
|
||||||
|
"The Terminator",
|
||||||
|
"The Usual Suspects",
|
||||||
|
"The Wolf of Wall Street",
|
||||||
|
"Top Gun: Maverick",
|
||||||
|
"Toy Story",
|
||||||
|
"Unforgiven",
|
||||||
|
"Up",
|
||||||
|
"V for Vendetta",
|
||||||
|
"WALL·E",
|
||||||
|
"Warrior",
|
||||||
|
"Whiplash",
|
||||||
|
},
|
||||||
|
"genre": {
|
||||||
|
"Action",
|
||||||
|
"Adventure",
|
||||||
|
"Animation",
|
||||||
|
"Biography",
|
||||||
|
"Comedy",
|
||||||
|
"Crime",
|
||||||
|
"Drama",
|
||||||
|
"Family",
|
||||||
|
"Fantasy",
|
||||||
|
"Film-Noir",
|
||||||
|
"History",
|
||||||
|
"Horror",
|
||||||
|
"Music",
|
||||||
|
"Musical",
|
||||||
|
"Mystery",
|
||||||
|
"Romance",
|
||||||
|
"Sci-Fi",
|
||||||
|
"Sport",
|
||||||
|
"Thriller",
|
||||||
|
"War",
|
||||||
|
"Western",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,211 @@
|
||||||
|
package data
|
||||||
|
|
||||||
|
// CreditCardInfo contains credit card info
|
||||||
|
type CreditCardInfo struct {
|
||||||
|
Display string
|
||||||
|
Patterns []uint
|
||||||
|
Gaps []uint
|
||||||
|
Lengths []uint
|
||||||
|
Code CreditCardCode
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreditCardCode contains code type and size
|
||||||
|
type CreditCardCode struct {
|
||||||
|
Name string
|
||||||
|
Size uint
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreditCardTypes is an array of credit card types
|
||||||
|
var CreditCardTypes = []string{"visa", "mastercard", "american-express", "diners-club", "discover", "jcb", "unionpay", "maestro", "elo", "hiper", "hipercard"}
|
||||||
|
|
||||||
|
// CreditCards contains payment information
|
||||||
|
var CreditCards = map[string]CreditCardInfo{
|
||||||
|
"visa": {
|
||||||
|
Display: "Visa",
|
||||||
|
Patterns: []uint{4},
|
||||||
|
Gaps: []uint{4, 8, 12},
|
||||||
|
Lengths: []uint{16},
|
||||||
|
Code: CreditCardCode{
|
||||||
|
Name: "CVV",
|
||||||
|
Size: 3,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"mastercard": {
|
||||||
|
Display: "Mastercard",
|
||||||
|
Patterns: []uint{
|
||||||
|
51, 55,
|
||||||
|
2221, 2229,
|
||||||
|
223, 229,
|
||||||
|
23, 26,
|
||||||
|
270, 271,
|
||||||
|
2720,
|
||||||
|
},
|
||||||
|
Gaps: []uint{4, 8, 12},
|
||||||
|
Lengths: []uint{16},
|
||||||
|
Code: CreditCardCode{
|
||||||
|
Name: "CVC",
|
||||||
|
Size: 3,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"american-express": {
|
||||||
|
Display: "American Express",
|
||||||
|
Patterns: []uint{34, 37},
|
||||||
|
Gaps: []uint{4, 10},
|
||||||
|
Lengths: []uint{15},
|
||||||
|
Code: CreditCardCode{
|
||||||
|
Name: "CID",
|
||||||
|
Size: 4,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"diners-club": {
|
||||||
|
Display: "Diners Club",
|
||||||
|
Patterns: []uint{
|
||||||
|
300, 305,
|
||||||
|
36, 38, 39,
|
||||||
|
},
|
||||||
|
Gaps: []uint{4, 10},
|
||||||
|
Lengths: []uint{14, 16, 19},
|
||||||
|
Code: CreditCardCode{
|
||||||
|
Name: "CVV",
|
||||||
|
Size: 3,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"discover": {
|
||||||
|
Display: "Discover",
|
||||||
|
Patterns: []uint{
|
||||||
|
6011, 644, 649, 65,
|
||||||
|
},
|
||||||
|
Gaps: []uint{4, 8, 12},
|
||||||
|
Lengths: []uint{16, 19},
|
||||||
|
Code: CreditCardCode{
|
||||||
|
Name: "CID",
|
||||||
|
Size: 3,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"jcb": {
|
||||||
|
Display: "JCB",
|
||||||
|
Patterns: []uint{
|
||||||
|
2131, 1800, 3528, 3589,
|
||||||
|
},
|
||||||
|
Gaps: []uint{4, 8, 12},
|
||||||
|
Lengths: []uint{16, 17, 18, 19},
|
||||||
|
Code: CreditCardCode{
|
||||||
|
Name: "CVV",
|
||||||
|
Size: 3,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"unionpay": {
|
||||||
|
Display: "UnionPay",
|
||||||
|
Patterns: []uint{
|
||||||
|
620, 624, 626,
|
||||||
|
62100, 62182,
|
||||||
|
62184, 62187,
|
||||||
|
62185, 62197,
|
||||||
|
62200, 62205,
|
||||||
|
622010, 622999,
|
||||||
|
622018,
|
||||||
|
622019, 622999,
|
||||||
|
62207, 62209,
|
||||||
|
622126, 622925,
|
||||||
|
623, 626,
|
||||||
|
6270, 6272, 6276,
|
||||||
|
627700, 627779,
|
||||||
|
627781, 627799,
|
||||||
|
6282, 6289,
|
||||||
|
6291, 6292,
|
||||||
|
810,
|
||||||
|
8110, 8131,
|
||||||
|
8132, 8151,
|
||||||
|
8152, 8163,
|
||||||
|
8164, 817,
|
||||||
|
},
|
||||||
|
Gaps: []uint{4, 8, 12},
|
||||||
|
Lengths: []uint{14, 15, 16, 17, 18, 19},
|
||||||
|
Code: CreditCardCode{
|
||||||
|
Name: "CVN",
|
||||||
|
Size: 3,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"maestro": {
|
||||||
|
Display: "Maestro",
|
||||||
|
Patterns: []uint{
|
||||||
|
493698,
|
||||||
|
500000, 506698,
|
||||||
|
506779, 508999,
|
||||||
|
56, 59,
|
||||||
|
6, 63, 67,
|
||||||
|
},
|
||||||
|
Gaps: []uint{4, 8, 12},
|
||||||
|
Lengths: []uint{12, 13, 14, 15, 16, 17, 18, 19},
|
||||||
|
Code: CreditCardCode{
|
||||||
|
Name: "CVC",
|
||||||
|
Size: 3,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"elo": {
|
||||||
|
Display: "Elo",
|
||||||
|
Patterns: []uint{
|
||||||
|
401178, 401179,
|
||||||
|
438935, 457631,
|
||||||
|
457632, 431274,
|
||||||
|
451416, 457393,
|
||||||
|
504175, 506699,
|
||||||
|
506778, 509000,
|
||||||
|
509999, 627780,
|
||||||
|
636297, 636368,
|
||||||
|
650031, 650033,
|
||||||
|
650035, 650051,
|
||||||
|
650405, 650439,
|
||||||
|
650485, 650538,
|
||||||
|
650541, 650598,
|
||||||
|
650700, 650718,
|
||||||
|
650720, 650727,
|
||||||
|
650901, 650978,
|
||||||
|
651652, 651679,
|
||||||
|
655000, 655019,
|
||||||
|
655021, 65505,
|
||||||
|
},
|
||||||
|
Gaps: []uint{4, 8, 12},
|
||||||
|
Lengths: []uint{16},
|
||||||
|
Code: CreditCardCode{
|
||||||
|
Name: "CVE",
|
||||||
|
Size: 3,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"mir": {
|
||||||
|
Display: "Mir",
|
||||||
|
Patterns: []uint{2200, 2204},
|
||||||
|
Gaps: []uint{4, 8, 12},
|
||||||
|
Lengths: []uint{16, 17, 18, 19},
|
||||||
|
Code: CreditCardCode{
|
||||||
|
Name: "CVP2",
|
||||||
|
Size: 3,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"hiper": {
|
||||||
|
Display: "Hiper",
|
||||||
|
Patterns: []uint{
|
||||||
|
637095,
|
||||||
|
637568,
|
||||||
|
637599,
|
||||||
|
637609,
|
||||||
|
637612,
|
||||||
|
},
|
||||||
|
Gaps: []uint{4, 8, 12},
|
||||||
|
Lengths: []uint{16},
|
||||||
|
Code: CreditCardCode{
|
||||||
|
Name: "CVC",
|
||||||
|
Size: 3,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"hipercard": {
|
||||||
|
Display: "Hipercard",
|
||||||
|
Patterns: []uint{606282},
|
||||||
|
Gaps: []uint{4, 8, 12},
|
||||||
|
Lengths: []uint{16},
|
||||||
|
Code: CreditCardCode{
|
||||||
|
Name: "CVC",
|
||||||
|
Size: 3,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,171 @@
|
||||||
|
package data
|
||||||
|
|
||||||
|
var Product = map[string][]string{
|
||||||
|
"category": {
|
||||||
|
"electronics", "clothing", "home appliances", "furniture",
|
||||||
|
"automotive parts", "beauty and personal care", "books", "sports equipment",
|
||||||
|
"toys and games", "outdoor gear", "pet supplies", "kitchenware",
|
||||||
|
"health and wellness", "tools and hardware", "office supplies",
|
||||||
|
"baby products", "jewelry", "home decor", "musical instruments",
|
||||||
|
"fitness equipment", "mobile phones", "computer accessories", "cameras and photography",
|
||||||
|
"gardening supplies", "bedding and linens", "food and groceries", "party supplies",
|
||||||
|
"craft and diy supplies", "camping gear", "watches", "luggage and travel accessories",
|
||||||
|
"board games", "art supplies", "stationery", "bath and shower products",
|
||||||
|
"sunglasses", "educational toys", "headphones and earbuds", "sneakers and athletic shoes",
|
||||||
|
"coffee and tea products", "bicycles and accessories", "cookware", "cosmetics",
|
||||||
|
"home improvement", "pet food", "laptop bags and cases", "home security systems",
|
||||||
|
"musical accessories", "skincare products", "smart home devices",
|
||||||
|
},
|
||||||
|
|
||||||
|
"adjective": {
|
||||||
|
"bold", "swift", "pure", "smart", "fresh",
|
||||||
|
"cool", "sharp", "zen", "bright", "quick",
|
||||||
|
"robust", "sleek", "versatile", "innovative", "compact",
|
||||||
|
"luxe", "modular", "precision", "stream",
|
||||||
|
},
|
||||||
|
|
||||||
|
"name": {
|
||||||
|
"phone", "laptop", "tablet", "watch", "camera",
|
||||||
|
"headphones", "speaker", "drone", "car", "bike",
|
||||||
|
"appliance", "gadget", "tool", "toy", "game",
|
||||||
|
"computer", "console", "smartwatch", "fitness tracker", "smart home device",
|
||||||
|
"robot", "router", "television", "smart speaker", "vr headset",
|
||||||
|
"earbuds", "printer", "mouse", "keyboard", "monitor",
|
||||||
|
"microwave", "blender", "vacuum", "fan", "toaster",
|
||||||
|
"clock", "lamp", "shaver", "scale", "thermometer",
|
||||||
|
"fridge", "oven", "mixer", "iron", "hair dryer",
|
||||||
|
"fan", "scale", "thermostat", "router", "lightbulb",
|
||||||
|
},
|
||||||
|
|
||||||
|
"feature": {
|
||||||
|
"wireless", "smart", "eco-friendly", "advanced", "compact",
|
||||||
|
"high-performance", "energy-efficient", "portable", "durable", "stylish",
|
||||||
|
"touchscreen", "water-resistant", "noise-canceling", "voice-controlled", "ultra-lightweight",
|
||||||
|
"multi-functional", "user-friendly", "fast-charging", "biometric", "gps-enabled",
|
||||||
|
},
|
||||||
|
|
||||||
|
"material": {
|
||||||
|
"titanium", "carbon", "alloy", "bamboo", "leather",
|
||||||
|
"glass", "ceramic", "aluminum", "stainless", "wood",
|
||||||
|
"plastic", "rubber", "silicon", "fabric", "paper",
|
||||||
|
"gold", "silver", "brass", "copper", "bronze",
|
||||||
|
"chrome", "marble", "granite", "porcelain", "plexiglass",
|
||||||
|
"quartz", "felt", "suede",
|
||||||
|
},
|
||||||
|
|
||||||
|
"suffix": {
|
||||||
|
"tech", "pro", "x", "plus", "elite",
|
||||||
|
"spark", "nexus", "nova", "fusion", "sync",
|
||||||
|
"edge", "boost", "max", "link", "prime",
|
||||||
|
"zoom", "pulse", "dash", "connect", "blaze",
|
||||||
|
"quantum", "spark", "vertex", "core", "flux",
|
||||||
|
"turbo", "shift", "wave", "matrix",
|
||||||
|
},
|
||||||
|
|
||||||
|
"benefit": {
|
||||||
|
"comfort", "efficiency", "safety", "reliability",
|
||||||
|
"versatility", "ease of use", "long battery life",
|
||||||
|
"precision", "enhanced connectivity", "portability",
|
||||||
|
"durability", "energy savings", "aesthetic appeal",
|
||||||
|
"health benefits", "convenience", "time-saving",
|
||||||
|
"high performance", "noise reduction", "user satisfaction",
|
||||||
|
"customizability", "sustainability", "cost-effectiveness",
|
||||||
|
"innovative features", "improved productivity", "enhanced experience",
|
||||||
|
"robust construction", "weather resistance", "minimal maintenance",
|
||||||
|
"increased functionality", "advanced technology", "ergonomic design",
|
||||||
|
},
|
||||||
|
|
||||||
|
"use_case": {
|
||||||
|
"home", "office", "outdoors", "fitness", "travel", "gaming",
|
||||||
|
"cooking", "music", "learning", "entertainment", "professional work",
|
||||||
|
"healthcare", "educational purposes", "commuting", "camping", "hiking",
|
||||||
|
"sports", "art and craft", "gardening", "cleaning", "personal grooming",
|
||||||
|
"relaxation", "home security", "pet care", "smart automation", "food preparation",
|
||||||
|
"baking", "social gatherings", "productivity", "collaboration", "DIY projects",
|
||||||
|
"childcare", "remote work", "photography", "videography", "wellness routines",
|
||||||
|
},
|
||||||
|
|
||||||
|
"target_audience": {
|
||||||
|
"children", "adults", "seniors", "students", "professionals", "athletes",
|
||||||
|
"travelers", "families", "pet owners", "homeowners", "gamers", "cooks", "DIY enthusiasts",
|
||||||
|
"musicians", "artists",
|
||||||
|
},
|
||||||
|
|
||||||
|
"dimension": {
|
||||||
|
"small", "medium", "large", "extra-large", "compact", "lightweight",
|
||||||
|
"heavy", "mini", "standard", "oversized",
|
||||||
|
},
|
||||||
|
|
||||||
|
"description": {
|
||||||
|
"This {adjectivedescriptive} {productname} is perfect for {productusecase}, offering {productfeature} and {productbenefit}. Made from {productmaterial}, it's designed for {productaudience} who value {productbenefit}.",
|
||||||
|
"Introducing the {adjectivedescriptive} {productname} {productsuffix}, featuring {productfeature} technology and made from {productmaterial}. It ensures {productbenefit} for {productaudience}, making it ideal for {productusecase}.",
|
||||||
|
"Perfect for {productusecase}, the {productname} is crafted with {adjectivedescriptive} {productmaterial} and features {productfeature} for {productaudience}. Enjoy {productbenefit} every day.",
|
||||||
|
"Designed with {productaudience} in mind, this {adjectivedescriptive} {productname} offers {productbenefit}. It's equipped with {productfeature} and made from {productmaterial} for maximum {productbenefit}.",
|
||||||
|
"The {productname} {productsuffix} combines {adjectivedescriptive} design and {productmaterial} build to deliver {productfeature}. Its {productdimension} size makes it perfect for {productusecase} and ideal for {productaudience}.",
|
||||||
|
"With a focus on {productaudience}, the {productname} is built with {adjectivedescriptive} {productmaterial} for {productbenefit} and features {productfeature} to meet the needs of {productusecase}.",
|
||||||
|
"Experience the {productbenefit} of the {productname} {productsuffix}, made from {productmaterial} with a {adjectivedescriptive} design. It's ideal for {productusecase} and loved by {productaudience}.",
|
||||||
|
"Whether you're using it at {productusecase} or on the go, this {adjectivedescriptive} {productname} offers {productfeature} and ensures {productbenefit}. Crafted from {productmaterial}, it's perfect for {productaudience}.",
|
||||||
|
"The {productname} is a {adjectivedescriptive} solution for {productusecase}, featuring {productfeature} technology and built with {productmaterial} for {productbenefit}. Suitable for {productaudience}.",
|
||||||
|
"For {productaudience} who need {productbenefit}, the {productname} {productsuffix} delivers with {productfeature}, {adjectivedescriptive} design, and durable {productmaterial} construction. Ideal for {productusecase}.",
|
||||||
|
"Built with {adjectivedescriptive} {productmaterial}, this item is ideal for {productusecase} and provides {productaudience} with {productbenefit} through its {productfeature}.",
|
||||||
|
"Experience {productbenefit} with this {adjectivedescriptive} product, featuring {productfeature} and made from {productmaterial}, perfect for {productusecase}.",
|
||||||
|
"Designed for {productaudience}, this {adjectivedescriptive} product ensures {productbenefit} and is equipped with {productfeature} for the best {productusecase} experience.",
|
||||||
|
"For those who need {productbenefit}, this {adjectivedescriptive} product, made of {productmaterial}, offers {productfeature} and is perfect for {productusecase}.",
|
||||||
|
"Take your {productusecase} to the next level with this {adjectivedescriptive} product. Built from {productmaterial}, it features {productfeature} for {productaudience}.",
|
||||||
|
"Crafted from {productmaterial}, this product is ideal for {productaudience} seeking {productbenefit}. Its {adjectivedescriptive} design and {productfeature} make it perfect for {productusecase}.",
|
||||||
|
"This product, made with {productmaterial}, is designed for {productaudience} who value {productbenefit}. Its {adjectivedescriptive} design includes {productfeature}, making it ideal for {productusecase}.",
|
||||||
|
"Enjoy {productbenefit} with this {adjectivedescriptive} item, featuring {productfeature} technology. Made from {productmaterial}, it's perfect for {productusecase}.",
|
||||||
|
"With {productfeature} and {adjectivedescriptive} {productmaterial}, this product offers {productbenefit} for {productaudience}, ideal for {productusecase}.",
|
||||||
|
"The perfect solution for {productusecase}, this {adjectivedescriptive} product provides {productbenefit} with its {productfeature}, crafted from {productmaterial} for {productaudience}.",
|
||||||
|
"Built for {productaudience}, this product features {productfeature} and ensures {productbenefit}. Made from {productmaterial}, it's an {adjectivedescriptive} choice for {productusecase}.",
|
||||||
|
"Achieve {productbenefit} with this {adjectivedescriptive} product. Crafted from {productmaterial}, it features {productfeature}, perfect for {productaudience} during {productusecase}.",
|
||||||
|
"For {productaudience}, this {adjectivedescriptive} item offers {productfeature} and is made of {productmaterial}, providing {productbenefit} for {productusecase}.",
|
||||||
|
"This {adjectivedescriptive} product is crafted from {productmaterial} and includes {productfeature}, making it perfect for {productusecase} and delivering {productbenefit} for {productaudience}.",
|
||||||
|
"Featuring {productfeature} and made from {productmaterial}, this {adjectivedescriptive} product is ideal for {productaudience} looking for {productbenefit} in {productusecase}.",
|
||||||
|
"For {productusecase}, this {adjectivedescriptive} product provides {productbenefit} with its {productfeature}, crafted for {productaudience} from high-quality {productmaterial}.",
|
||||||
|
"This {adjectivedescriptive} product is perfect for {productaudience} who need {productbenefit}. Built from {productmaterial} and featuring {productfeature}, it's ideal for {productusecase}.",
|
||||||
|
"Delivering {productbenefit}, this product is made from {productmaterial} and designed for {productaudience}. Its {adjectivedescriptive} design includes {productfeature}, perfect for {productusecase}.",
|
||||||
|
"For those interested in {productusecase}, this {adjectivedescriptive} product offers {productfeature} and is made of {productmaterial} to provide {productbenefit} for {productaudience}.",
|
||||||
|
"This product is crafted for {productaudience}, featuring {adjectivedescriptive} {productmaterial} and equipped with {productfeature} to ensure {productbenefit} during {productusecase}.",
|
||||||
|
"Transform your {productusecase} with this {adjectivedescriptive} product, featuring {productfeature} and made from high-quality {productmaterial} to provide {productbenefit}.",
|
||||||
|
"This {adjectivedescriptive} item, built for {productaudience}, uses {productfeature} technology to deliver {productbenefit} during {productusecase}.",
|
||||||
|
"Enjoy the luxury of {productbenefit} with this product, crafted from {productmaterial}. Its {adjectivedescriptive} design and {productfeature} make it ideal for {productusecase}.",
|
||||||
|
"Made from {productmaterial} and designed with {productaudience} in mind, this product offers {productbenefit} and features {productfeature} for excellent {productusecase}.",
|
||||||
|
"Achieve seamless {productusecase} with this {adjectivedescriptive} product. Built using {productmaterial}, it delivers {productbenefit} with the help of {productfeature}.",
|
||||||
|
"This product, made for {productaudience}, offers {productbenefit} with its {adjectivedescriptive} {productmaterial} build and advanced {productfeature}, perfect for {productusecase}.",
|
||||||
|
"Built with {productmaterial}, this {adjectivedescriptive} product is designed to provide {productbenefit} for {productaudience} through its {productfeature}, ideal for {productusecase}.",
|
||||||
|
"Elevate your {productusecase} experience with this {adjectivedescriptive} product, made from {productmaterial} and offering {productfeature} to ensure {productbenefit}.",
|
||||||
|
"Perfect for {productaudience} who value {productbenefit}, this product features {productfeature} and is crafted from {adjectivedescriptive} {productmaterial}, ideal for {productusecase}.",
|
||||||
|
"With a focus on {productusecase}, this {adjectivedescriptive} product, made from {productmaterial}, ensures {productbenefit} with its {productfeature} for {productaudience}.",
|
||||||
|
"Whether for {productusecase} or everyday use, this product delivers {productbenefit} with its {adjectivedescriptive} {productmaterial} construction and {productfeature}, crafted for {productaudience}.",
|
||||||
|
"This {adjectivedescriptive} product is perfect for {productusecase}, made with {productmaterial} and offering {productfeature} to ensure {productbenefit} for {productaudience}.",
|
||||||
|
"Featuring state-of-the-art {productfeature}, this product is designed from {productmaterial} to deliver {productbenefit} for {productaudience}, ideal for {productusecase}.",
|
||||||
|
"For {productusecase}, this {adjectivedescriptive} product is crafted from {productmaterial} to provide {productfeature}, ensuring {productbenefit} for {productaudience}.",
|
||||||
|
"Built for {productaudience}, this item features {adjectivedescriptive} {productmaterial} and advanced {productfeature} to deliver {productbenefit} during {productusecase}.",
|
||||||
|
"With {productfeature} and a {adjectivedescriptive} design, this product is made from {productmaterial} to provide {productbenefit} for {productaudience}, ideal for {productusecase}.",
|
||||||
|
"This {adjectivedescriptive} item, crafted from {productmaterial}, offers {productfeature} for {productusecase}, ensuring {productbenefit} for {productaudience}.",
|
||||||
|
"For those who value {productbenefit}, this product, made from {productmaterial}, includes {productfeature} and is perfect for {productusecase}, designed for {productaudience}.",
|
||||||
|
"Achieve superior {productusecase} with this product, featuring {productfeature} and made from {adjectivedescriptive} {productmaterial}, offering {productbenefit} to {productaudience}.",
|
||||||
|
"Delivering {productbenefit}, this product is crafted from {productmaterial} and equipped with {productfeature}, making it ideal for {productaudience} during {productusecase}.",
|
||||||
|
"Revolutionize your {productusecase} with this {adjectivedescriptive} item, featuring {productfeature} and crafted from {productmaterial} for {productaudience} seeking {productbenefit}.",
|
||||||
|
"This {adjectivedescriptive} item, designed for {productaudience}, is built from {productmaterial} and includes {productfeature} to ensure {productbenefit} for {productusecase}.",
|
||||||
|
"Enjoy enhanced {productusecase} with this product, featuring {productfeature} and made with {adjectivedescriptive} {productmaterial}, delivering {productbenefit}.",
|
||||||
|
"Perfect for {productaudience}, this {adjectivedescriptive} product includes {productfeature} and is crafted from {productmaterial} to provide {productbenefit} during {productusecase}.",
|
||||||
|
"Take your {productusecase} to new heights with this product, made from {productmaterial} and featuring {productfeature} for {productaudience} who value {productbenefit}.",
|
||||||
|
"Crafted from premium {productmaterial}, this item is designed for {productaudience} to provide {productbenefit} with its {adjectivedescriptive} build and {productfeature}.",
|
||||||
|
"This {adjectivedescriptive} product, made from {productmaterial}, offers {productbenefit} through its {productfeature}, ideal for {productaudience} engaging in {productusecase}.",
|
||||||
|
"Elevate your {productusecase} with this {adjectivedescriptive} product. It features {productfeature} and is crafted from {productmaterial} for {productaudience}.",
|
||||||
|
"Designed for {productaudience}, this product includes {productfeature} and a {adjectivedescriptive} {productmaterial} construction, ensuring {productbenefit} during {productusecase}.",
|
||||||
|
"This {adjectivedescriptive} item, featuring {productfeature}, is crafted from {productmaterial} to provide {productbenefit} for {productusecase}, perfect for {productaudience}.",
|
||||||
|
"Achieve exceptional {productusecase} with this product, featuring advanced {productfeature} and made from durable {productmaterial}, delivering {productbenefit} for {productaudience}.",
|
||||||
|
"Whether it's for {productusecase} or daily use, this {adjectivedescriptive} item is crafted from {productmaterial} and offers {productfeature} to deliver {productbenefit} for {productaudience}.",
|
||||||
|
"This product, ideal for {productaudience}, features {adjectivedescriptive} {productmaterial} and incorporates {productfeature} to ensure {productbenefit} during {productusecase}.",
|
||||||
|
"Built with {productmaterial}, this {adjectivedescriptive} item is perfect for {productusecase} and features {productfeature} to provide {productbenefit} to {productaudience}.",
|
||||||
|
"With {productfeature} and made from {adjectivedescriptive} {productmaterial}, this product ensures {productbenefit} for {productaudience}, ideal for {productusecase}.",
|
||||||
|
"This {adjectivedescriptive} item is built for {productaudience}, providing {productbenefit} with its {productmaterial} construction and advanced {productfeature}, perfect for {productusecase}.",
|
||||||
|
"For {productusecase}, this product delivers {productbenefit} to {productaudience} with its {adjectivedescriptive} design and {productfeature}, made from quality {productmaterial}.",
|
||||||
|
"Experience the benefits of {productfeature} with this {adjectivedescriptive} item, crafted from {productmaterial} and ideal for {productaudience} seeking {productbenefit} during {productusecase}.",
|
||||||
|
"This {adjectivedescriptive} product is crafted from {productmaterial} and includes {productfeature}, making it perfect for {productusecase} and providing {productbenefit} for {productaudience}.",
|
||||||
|
"For those who value {productbenefit}, this product is made from {productmaterial} and features {adjectivedescriptive} {productfeature}, ideal for {productaudience} during {productusecase}.",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,56 @@
|
||||||
|
package data
|
||||||
|
|
||||||
|
// School type and names
|
||||||
|
var School = map[string][]string{
|
||||||
|
"type": {"Elementary School", "Middle School", "University", "High School", "Kindergarten", "Academy", "College", "Institute"},
|
||||||
|
"isPrivate": {"Private", "State"},
|
||||||
|
"name": {"Maplewood",
|
||||||
|
"Pineville",
|
||||||
|
"Riverside",
|
||||||
|
"Willowbrook",
|
||||||
|
"Crestwood",
|
||||||
|
"Sunset",
|
||||||
|
"Greenfield",
|
||||||
|
"Oakwood",
|
||||||
|
"Willowbrook",
|
||||||
|
"Hawthorn",
|
||||||
|
"Brookside",
|
||||||
|
"Pleasant View",
|
||||||
|
"Crescent Valley",
|
||||||
|
"Sycamore",
|
||||||
|
"Springfield",
|
||||||
|
"Meadowbrook",
|
||||||
|
"Greenwood",
|
||||||
|
"Riverbend",
|
||||||
|
"Valley Forge",
|
||||||
|
"Ridgeview",
|
||||||
|
"Cottonwood",
|
||||||
|
"Cedarwood",
|
||||||
|
"Golden Oak",
|
||||||
|
"Stonebridge",
|
||||||
|
"Harborview",
|
||||||
|
"Windsor",
|
||||||
|
"Northbrook",
|
||||||
|
"Sunset",
|
||||||
|
"Redwood Valley",
|
||||||
|
"Liberty",
|
||||||
|
"Washington Central",
|
||||||
|
"Franklin",
|
||||||
|
"Jefferson",
|
||||||
|
"Lincoln Park",
|
||||||
|
"Madison",
|
||||||
|
"Roosevelt",
|
||||||
|
"Westwood",
|
||||||
|
"Central Lakeside",
|
||||||
|
"Fairview",
|
||||||
|
"Heritage Hills",
|
||||||
|
"Kingsbridge",
|
||||||
|
"Harrisonville",
|
||||||
|
"Valley View",
|
||||||
|
"Hillside",
|
||||||
|
"Northridge",
|
||||||
|
"Brooklyn Heights",
|
||||||
|
"Oakridge",
|
||||||
|
"Countryside",
|
||||||
|
},
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,83 @@
|
||||||
|
package data
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sort"
|
||||||
|
)
|
||||||
|
|
||||||
|
var WordKeys []string
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
// Loop through Word and put togther a list of keys
|
||||||
|
for key := range Word {
|
||||||
|
WordKeys = append(WordKeys, key)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort the keys
|
||||||
|
sort.Strings(WordKeys)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Word consists of common english words
|
||||||
|
var Word = map[string][]string{
|
||||||
|
// Nouns
|
||||||
|
"noun_common": {"time", "person", "year", "way", "day", "thing", "man", "world", "life", "hand", "part", "child", "eye", "woman", "place", "work", "week", "case", "point", "government", "company", "number", "group", "problem", "fact"},
|
||||||
|
"noun_concrete": {"apple", "air", "conditioner", "airport", "ambulance", "aircraft", "apartment", "arrow", "antlers", "apro", "alligator", "architect", "ankle", "armchair", "aunt", "ball", "bermudas", "beans", "balloon", "bear", "blouse", "bed", "bow", "bread", "black", "board", "bones", "bill", "bitterness", "boxers", "belt", "brain", "buffalo", "bird", "baby", "book", "back", "butter", "bulb", "buckles", "bat", "bank", "bag", "bra", "boots", "blazer", "bikini", "bookcase", "bookstore", "bus stop", "brass", "brother", "boy", "blender", "bucket", "bakery", "bow", "bridge", "boat", "car", "cow", "cap", "cooker", "cheeks", "cheese", "credenza", "carpet", "crow", "crest", "chest", "chair", "candy", "cabinet", "cat", "coffee", "children", "cookware", "chaise longue", "chicken", "casino", "cabin", "castle", "church", "cafe", "cinema", "choker", "cravat", "cane", "costume", "cardigan", "chocolate", "crib", "couch", "cello", "cashier", "composer", "cave", "country", "computer", "canoe", "clock", "dog", "deer", "donkey", "desk", "desktop", "dress", "dolphin", "doctor", "dentist", "drum", "dresser", "designer", "detective", "daughter", "egg", "elephant", "earrings", "ears", "eyes", "estate", "finger", "fox", "frock", "frog", "fan", "freezer", "fish", "film", "foot", "flag", "factory", "father", "farm", "forest", "flower", "fruit", "fork", "grapes", "goat", "gown", "garlic", "ginger", "giraffe", "gauva", "grains", "gas station", "garage", "gloves", "glasses", "gift", "galaxy", "guitar", "grandmother", "grandfather", "governor", "girl", "guest", "hamburger", "hand", "head", "hair", "heart", "house", "horse", "hen", "horn", "hat", "hammer", "hostel", "hospital", "hotel", "heels", "herbs", "host", "jacket", "jersey", "jewelry", "jaw", "jumper", "judge", "juicer", "keyboard", "kid", "kangaroo", "koala", "knife", "lemon", "lion", "leggings", "leg", "laptop", "library", "lamb", "london", "lips", "lung", "lighter", "luggage", "lamp", "lawyer", "mouse", "monkey", "mouth", "mango", "mobile", "milk", "music", "mirror", "musician", "mother", "man", "model", "mall", "museum", "market", "moonlight", "medicine", "microscope", "newspaper", "nose", "notebook", "neck", "noodles", "nurse", "necklace", "noise", "ocean", "ostrich", "oil", "orange", "onion", "oven", "owl", "paper", "panda", "pants", "palm", "pasta", "pumpkin", "pharmacist", "potato", "parfume", "panther", "pad", "pencil", "pipe", "police", "pen", "pharmacy", "police station", "parrot", "plane", "pigeon", "phone", "peacock", "pencil", "pig", "pouch", "pagoda", "pyramid", "purse", "pancake", "popcorn", "piano", "physician", "photographer", "professor", "painter", "park", "plant", "parfume", "radio", "razor", "ribs", "rainbow", "ring", "rabbit", "rice", "refrigerator", "remote", "restaurant", "road", "surgeon", "scale", "shampoo", "sink", "salt", "shark", "sandals", "shoulder", "spoon", "soap", "sand", "sheep", "sari", "stomach", "stairs", "soup", "shoes", "scissors", "sparrow", "shirt", "suitcase", "stove", "stairs", "snowman", "shower", "swan", "suit", "sweater", "smoke", "skirt", "sofa", "socks", "stadium", "skyscraper", "school", "sunglasses", "sandals", "slippers", "shorts", "sandwich", "strawberry", "spaghetti", "shrimp", "saxophone", "sister", "son", "singer", "senator", "street", "supermarket", "swimming pool", "star", "sky", "sun", "spoon", "ship", "smile", "table", "turkey", "tie", "toes", "truck", "train", "taxi", "tiger", "trousers", "tongue", "television", "teacher", "turtle", "tablet", "train station", "toothpaste", "tail", "theater", "trench coat", "tea", "tomato", "teen", "tunnel", "temple", "town", "toothbrush", "tree", "toy", "tissue", "telephone", "underwear", "uncle", "umbrella", "vest", "voice", "veterinarian", "villa", "violin", "village", "vehicle", "vase", "wallet", "wolf", "waist", "wrist", "water melon", "whale", "water", "wings", "whisker", "watch", "woman", "washing machine", "wheelchair", "waiter", "wound", "xylophone", "zebra", "zoo"},
|
||||||
|
"noun_abstract": {"fiction", "horror", "dream", "luck", "movement", "right", "clarity", "joy", "care", "trend", "belief", "sorrow", "joy", "failure", "slavery", "riches", "fashion", "envy", "success", "fear", "union", "luxury", "freedom", "generosity", "wit", "peace", "hatred", "thrill", "brilliance", "care", "wealth", "religion", "divorce", "goal", "stupidity", "friendship", "goodness", "rhythm", "timing", "infancy", "disregard", "riches", "appetite", "loneliness", "pleasure", "love", "beauty", "annoyance", "kindness", "nap", "gain", "talent", "religion", "lie", "truth", "solitude", "justice", "bravery", "calm", "childhood", "confusion", "ability", "loss", "thought", "growth", "cleverness", "anger", "horror", "marriage", "delay", "philosophy", "generation", "wisdom", "dishonesty", "happiness", "coldness", "poverty", "brilliance", "luxuty", "sleep", "awareness", "idea", "disregard", "slavery", "growth", "company", "irritation", "advantage", "mercy", "speed", "pain", "gossip", "crime", "comfort", "frailty", "life", "patience", "omen", "deceit", "elegance"},
|
||||||
|
"noun_collective_people": {"band", "troupe", "dynasty", "group", "bevy", "staff", "crowd", "party", "board", "regiment", "crew", "tribe", "body", "patrol", "congregation", "pack", "bunch", "company", "team", "mob", "caravan", "line", "troop", "choir", "host", "posse", "class", "gang", "horde"},
|
||||||
|
"noun_collective_animal": {"cackle", "mustering", "mob", "wisp", "pod", "bale", "murder", "muster", "brace", "exaltation", "party", "flock", "cast", "sedge", "stand", "scold", "team", "covey", "trip", "army", "school", "nest", "leap", "host", "troop"},
|
||||||
|
"noun_collective_thing": {"wad", "pair", "album", "string", "anthology", "reel", "outfit", "fleet", "comb", "archipelago", "quiver", "bale", "packet", "hedge", "basket", "orchard", "batch", "library", "battery", "set", "harvest", "block", "forest", "book", "group", "bouquet", "collection", "bowl", "stack", "bunch", "hand", "bundle", "catalog", "shower", "ream", "chest", "heap", "range", "cluster", "pack", "hail", "cloud", "galaxy", "sheaf", "clump"},
|
||||||
|
"noun_countable": {"camp", "hospital", "shirt", "sock", "plant", "cup", "fork", "spoon", "plate", "straw", "town", "box", "bird", "father", "answer", "egg", "purse", "mirror", "mistake", "toilet", "toothbrush", "shower", "towel", "pool", "corner", "card", "lawn", "city", "egg", "yard", "burger", "kilometer", "mile", "father", "film", "actor", "issue", "machine", "liter", "room", "station", "journey", "castle", "hour", "finger", "boy", "book", "year", "second", "son", "month", "group", "hall", "cat", "week", "picture", "day", "village", "effect", "baby", "weekend", "class", "meal", "river", "grade", "bush", "desk", "stream", "method", "brother", "sister", "factory", "aunt", "bush", "program", "uncle", "ball", "cousin", "wall", "grandmother", "cup", "grandfather", "week", "school", "shirt", "child", "king", "road", "judge", "bridge", "car", "line", "book", "eye", "teacher", "foot", "party", "face", "day", "chest", "handle", "week", "hotel", "eye", "animal", "doctor", "adult", "village", "key", "bird", "bank", "program", "idea", "gun", "card", "brother", "dress", "room", "door", "mouth", "club", "game", "ring", "project", "sister", "road", "coat", "account", "group", "cigarette", "farm", "river", "college", "computer", "walk", "corner", "cat", "head", "street", "election", "country", "chair", "crowd", "cup", "plant", "farm", "handle", "model", "book", "message", "battle", "pen", "pencil", "elephant", "carrot", "onion", "garden", "country", "engine", "bill", "apple", "noun", "club", "crowd", "window", "field", "friend", "verb", "class", "flower", "seed", "lake", "plant", "animal", "ocean", "whale", "fish", "stream", "cloud", "couch", "steak", "problem", "light", "door", "room", "painting", "shop", "apartment", "candle", "adult", "building", "plan", "page", "ball", "game", "animal", "apartment", "box", "thought", "walk", "lady", "bottle", "article", "game", "kettle", "car", "house", "hoses", "orange", "phone", "app", "window", "door", "dollar", "foot", "cent", "library", "cat", "bed", "pound", "gate", "tomatoes", "gun", "holiday", "woman", "job", "shock", "salary", "tax", "coat", "scooter", "dog", "problem", "field", "answer", "ear", "camp", "case", "road", "woman", "product", "bridge", "man", "dream", "idea", "scheme", "invention", "cigarette", "mother", "friend", "chapter", "computer", "dream", "father", "child", "motor", "deskpath", "factory", "park", "newspaper", "hat", "dream", "table", "kitchen", "student", "captain", "doctor", "bus", "neck", "class", "list", "member", "chest", "valley", "product", "horse", "captain", "star", "hour", "page", "bus", "girl", "month", "child", "house", "boy", "bill", "kitchen", "chapter", "boat", "hand", "dress", "table", "wall", "chair", "train", "minute", "magazine", "bus", "party", "bird", "lake", "job", "nation", "bike", "election", "hand", "box", "beach", "address", "project", "task", "park", "face", "college", "bell", "plane", "store", "hall", "accident", "daughter", "ship", "candy", "smile", "city", "island", "case", "spot", "film", "husband", "artist", "tour", "bag", "boat", "driver", "office", "chair", "path", "dog", "bag", "finger", "apartment", "garden", "heart", "year", "engine", "girl", "day", "castle", "plane", "ring", "brother", "edge", "picture", "meeting", "tent", "dog", "hat", "head", "bottle", "hill"},
|
||||||
|
"noun_uncountable": {"accommodation", "advertising", "air", "aid", "advice", "anger", "art", "assistance", "bread", "business", "butter", "calm", "cash", "chaos", "cheese", "childhood", "clothing", "coffee", "content", "corruption", "courage", "currency", "damage", "danger", "darkness", "data", "determination", "economics", "education", "electricity", "employment", "energy", "entertainment", "enthusiasm", "equipment", "evidence", "failure", "fame", "fire", "flour", "food", "freedom", "friendship", "fuel", "furniture", "fun", "genetics", "gold", "grammar", "guilt", "hair", "happiness", "harm", "health", "heat", "help", "homework", "honesty", "hospitality", "housework", "humour", "imagination", "importance", "information", "innocence", "intelligence", "jealousy", "juice", "justice", "kindness", "knowledge", "labour", "lack", "laughter", "leisure", "literature", "litter", "logic", "love", "luck", "magic", "management", "metal", "milk", "money", "motherhood", "motivation", "music", "nature", "news", "nutrition", "obesity", "oil", "old age", "oxygen", "paper", "patience", "permission", "pollution", "poverty", "power", "pride", "production", "progress", "pronunciation", "publicity", "punctuation", "quality", "quantity", "racism", "rain", "relaxation", "research", "respect", "rice", "room (space)", "rubbish", "safety", "salt", "sand", "seafood", "shopping", "silence", "smoke", "snow", "software", "soup", "speed", "spelling", "stress", "sugar", "sunshine", "tea", "tennis", "time", "tolerance", "trade", "traffic", "transportation", "travel", "trust", "understanding", "unemployment", "usage", "violence", "vision", "warmth", "water", "wealth", "weather", "weight", "welfare", "wheat", "width", "wildlife", "wisdom", "wood", "work", "yoga", "youth"},
|
||||||
|
"noun_determiner": {"the", "a", "an", "this", "that", "these", "those", "my", "your", "his", "her", "its", "our", "their", "some", "any", "each", "every", "certain"},
|
||||||
|
//"noun_proper": {}, // This refers to an actual person(John Doe), place(Chipotle, Tennessee)
|
||||||
|
|
||||||
|
// Verbs
|
||||||
|
"verb_action": {"ride", "sit", "stand", "fight", "laugh", "read", "play", "listen", "cry", "think", "sing", "watch", "dance", "turn", "win", "fly", "cut", "throw", "sleep", "close", "open", "write", "give", "jump", "eat", "drink", "cook", "wash", "wait", "climb", "talk", "crawl", "dream", "dig", "clap", "knit", "sew", "smell", "kiss", "hug", "snore", "bathe", "bow", "paint", "dive", "ski", "stack", "buy", "shake"},
|
||||||
|
"verb_transitive": {"accept", "acknowledge", "admit", "aggravate", "answer", "ask", "avoid", "beat", "bend", "bless", "bother", "break", "brush", "build", "cancel", "capture", "carry", "catch", "change", "chase", "chastise", "clean", "collect", "comfort", "contradict", "convert", "crack", "dazzle", "deceive", "define", "describe", "destroy", "discover", "distinguish", "drag", "dress", "dunk", "edify", "embarrass", "embrace", "enable", "encourage", "enlist", "entertain", "execute", "fascinate", "finish", "flick", "follow", "forget", "forgive", "freeze", "frighten", "furnish", "gather", "grab", "grasp", "grease", "grip", "handle", "hang", "head", "help", "highlight", "honour", "hurry", "hurt", "imitate", "impress", "indulge", "insert", "inspect", "interest", "interrupt", "intimidate", "involve", "irritate", "join", "judge", "keep", "key", "kill", "kiss", "knock", "lag", "lay", "lead", "lean", "leave", "lighten", "limit", "link", "load", "love", "lower", "maintain", "marry", "massage", "melt", "mock", "munch", "murder", "notice", "number", "offend", "order", "page", "paralyze", "persuade", "petrify", "pierce", "place", "please", "poison", "possess", "prepare", "promise", "protect", "punch", "purchase", "puzzle", "question", "quit", "raise", "reassure", "recognise", "refill", "remind", "remove", "repel", "research", "retard", "ring", "run", "satisfy", "scold", "select", "slap", "smell", "soften", "specify", "spell", "spit", "spread", "strike", "surprise", "swallow", "switch", "taste", "teach", "tickle", "tighten", "toast", "toss", "transform", "try", "turn", "tweak", "twist", "understand", "understimate", "unload", "unlock", "untie", "upgrade", "use", "vacate", "videotape", "vilify", "viplate", "wake", "want", "warm", "warn", "wash", "watch", "wear", "weep", "widen", "win", "wipe", "wrack", "wrap", "wreck"},
|
||||||
|
"verb_intransitive": {"agree", "appear", "arrive", "become", "belong", "collapse", "consist", "cost", "cough", "cry", "depend", "die", "disappear", "emerge", "exist", "explode", "fade", "fall", "fast", "float", "fly", "gallop", "go", "grow", "happen", "have", "hiccup", "inquire", "jump", "kneel", "knock", "last", "laugh", "lead", "lean", "leap", "learn", "left", "lie", "limp", "listen", "live", "look", "march", "mourn", "move", "occur", "panic", "party", "pause", "peep", "pose", "pounce", "pout", "pray", "preen", "read", "recline", "relax", "relent", "remain", "respond", "result", "revolt", "rise", "roll", "run", "rush", "sail", "scream", "shake", "shout", "sigh", "sit", "skip", "sleep", "slide", "smell", "smile", "snarl", "sneeze", "soak", "spin", "spit", "sprint", "squeak", "stagger", "stand", "stay", "swim", "swing", "twist", "vanish", "vomit", "wade", "wait", "wake", "walk", "wander", "wave", "whirl", "wiggle", "work", "yell"},
|
||||||
|
"verb_linking": {"am", "is", "was", "are", "were", "being", "been", "be", "have", "has", "had", "do", "does", "did", "shall", "will", "should", "would", "may", "might", "must", "can", "could"},
|
||||||
|
"verb_helping": {"is", "can", "be", "do", "may", "had", "should", "was", "has", "could", "are", "will", "been", "did", "might", "were", "does", "must", "have", "would", "am", "shall", "being"},
|
||||||
|
|
||||||
|
// Adverbs
|
||||||
|
"adverb_manner": {"accidentally", "angrily", "anxiously", "awkwardly", "badly", "beautifully", "blindly", "boldly", "bravely", "brightly", "busily", "calmly", "carefully", "carelessly", "cautiously", "cheerfully", "clearly", "closely", "correctly", "courageously", "cruelly", "daringly", "deliberately", "doubtfully", "eagerly", "easily", "elegantly", "enormously", "enthusiastically", "equally", "eventually", "exactly", "faithfully", "fast", "fatally", "fiercely", "fondly", "foolishly", "fortunately", "frankly", "frantically", "generously", "gently", "gladly", "gracefully", "greedily", "happily", "hard", "hastily", "healthily", "honestly", "hungrily", "hurriedly", "inadequately", "ingeniously", "innocently", "inquisitively", "irritably", "joyously", "justly", "kindly", "lazily", "loosely", "loudly", "madly", "mortally", "mysteriously", "neatly", "nervously", "noisily", "obediently", "openly", "painfully", "patiently", "perfectly", "politely", "poorly", "powerfully", "promptly", "punctually", "quickly", "quietly", "rapidly", "rarely", "really", "recklessly", "regularly", "reluctantly", "repeatedly", "rightfully", "roughly", "rudely", "sadly", "safely", "selfishly", "sensibly", "seriously", "sharply", "shyly", "silently", "sleepily", "slowly", "smoothly", "so", "softly", "solemnly", "speedily", "stealthily", "sternly", "straight", "stupidly", "successfully", "suddenly", "suspiciously", "swiftly", "tenderly", "tensely", "thoughtfully", "tightly", "truthfully", "unexpectedly", "victoriously", "violently", "vivaciously", "warmly", "weakly", "wearily", "well", "wildly", "wisely"},
|
||||||
|
"adverb_degree": {"almost", "absolutely", "awfully", "badly", "barely", "completely", "decidedly", "deeply", "enough", "enormously", "entirely", "extremely", "fairly", "far", "fully", "greatly", "hardly", "highly", "how", "incredibly", "indeed", "intensely", "just", "least", "less", "little", "lots", "most", "much", "nearly", "perfectly", "positively", "practically", "pretty", "purely", "quite", "rather", "really", "scarcely", "simply", "so", "somewhat", "strongly", "terribly", "thoroughly", "too", "totally", "utterly", "very", "virtually", "well"},
|
||||||
|
"adverb_place": {"about", "above", "abroad", "anywhere", "away", "back", "backwards", "behind", "below", "down", "downstairs", "east", "elsewhere", "far", "here", "in", "indoors", "inside", "near", "nearby", "off", "on", "out", "outside", "over", "there", "towards", "under", "up", "upstairs", "where"},
|
||||||
|
"adverb_time_definite": {"now", "then", "today", "tomorrow", "tonight", "yesterday"},
|
||||||
|
"adverb_time_indefinite": {"already", "before", "early", "earlier", "eventually", "finally", "first", "formerly", "just", "last", "late", "later", "lately", "next", "previously", "recently", "since", "soon", "still", "yet"},
|
||||||
|
"adverb_frequency_definite": {"annually", "daily", "fortnightly", "hourly", "monthly", "nightly", "quarterly", "weekly", "yearly"},
|
||||||
|
"adverb_frequency_indefinite": {"always", "constantly", "ever", "frequently", "generally", "infrequently", "never", "normally", "occasionally", "often", "rarely", "regularly", "seldom", "sometimes", "regularly", "usually"},
|
||||||
|
|
||||||
|
// Prepositions
|
||||||
|
"preposition_simple": {"at", "by", "as", "but", "from", "for", "into", "in", "than", "of", "off", "on", "out", "over", "till", "to", "up", "upon", "with", "under", "down"},
|
||||||
|
"preposition_double": {"outside of", "out of", "upon", "within", "inside", "without", "onto", "from behind", "because of", "out of", "throughout", "up to", "before", "due to", "according to", "from beneath", "next to", "from above"},
|
||||||
|
"preposition_compound": {"according to", "as to", "onto", "across", "after", "beyond", "without", "opposite to", "away from", "aside from", "in favor of", "in front of", "because of", "as for", "near to", "behind", "along", "outside", "on account of", "on behalf of", "but for", "ahead of", "close to", "despite", "depending on", "due to", "in addition to", "next to", "in between", "in case of", "owing to", "along with", "around", "between", "apart from", "in return for", "out of", "instead of", "outside of", "other than", "together with", "up to", "above", "about"},
|
||||||
|
|
||||||
|
// Adjectives
|
||||||
|
"adjective_descriptive": {"adorable", "adventurous", "agreeable", "alive", "aloof", "amused", "angry", "annoying", "anxious", "arrogant", "ashamed", "attractive", "auspicious", "awful", "bad", "beautiful", "black", "blue", "blushing", "bored", "brave", "bright", "brown", "busy", "calm", "careful", "cautious", "charming", "cheerful", "clean", "clear", "clever", "clumsy", "colorful", "comfortable", "concerning", "condemned", "confusing", "cooperative", "courageous", "creepy", "crowded", "cruel", "curios", "cute", "dangerous", "dark", "defiant", "delightful", "difficult", "disgusting", "distinct", "disturbed", "dizzying", "drab", "dull", "eager", "easy", "elated", "elegant", "embarrassed", "enchanted", "encouraging", "energetic", "enthusiastic", "envious", "evil", "exciting", "expensive", "exuberant", "faithful", "famous", "fancy", "fantastic", "fierce", "filthy", "fine", "foolish", "fragile", "frail", "frantic", "friendly", "frightening", "funny", "gentle", "gifted", "glamorous", "gleaming", "glorious", "good", "gorgeous", "graceful", "green", "grieving", "grumpy", "handsome", "happy", "healthy", "helpful", "helpless", "hilarious", "homeless", "horrible", "hungry", "hurt", "ill", "important", "impossible", "impromptu", "improvised", "inexpensive", "innocent", "inquiring", "itchy", "jealous", "jittery", "joyous", "kind", "knightly", "lazy", "lemony", "light", "lingering", "lively", "lonely", "long", "lovely", "lucky", "magnificent", "modern", "motionless", "muddy", "mushy", "mysterious", "naughty", "niche", "nervous", "nice", "nutty", "obedient", "obnoxious", "odd", "open", "orange", "outrageous", "outstanding", "panicked", "perfect", "pink", "plain", "pleasant", "poised", "poor", "powerless", "precious", "prickling", "proud", "purple", "puzzled", "quaint", "queer", "quizzical", "realistic", "red", "relieved", "repelling", "repulsive", "rich", "scary", "scenic", "selfish", "shiny", "shy", "silly", "sleepy", "smiling", "smoggy", "sore", "sparkly", "splendid", "spotted", "stormy", "strange", "stupid", "successful", "super", "talented", "tame", "tasty", "tender", "tense", "terse", "terrible", "thankful", "thoughtful", "tired", "tough", "troubling", "ugly", "uninterested", "unusual", "upset", "uptight", "varied", "vast", "victorious", "wandering", "weary", "white", "wicked", "wide", "wild", "witty", "worrisome", "wrong", "yellow", "young", "zealous"},
|
||||||
|
"adjective_quantitative": {"a little", "a little bit", "a lot", "abundant", "all", "any", "couple", "double", "each", "either", "empty", "enough", "enough of", "every", "few", "full", "great", "half", "heavily", "heavy", "huge", "hundred", "hundreds", "insufficient", "light", "little", "lots of", "many", "most", "much", "neither", "no", "numerous", "plenty of", "several", "significant", "single", "so few", "some", "sparse", "substantial", "sufficient", "too", "whole"},
|
||||||
|
"adjective_proper": {"Afghan", "African", "Alaskan", "Alpine", "Amazonian", "American", "Antarctic", "Aristotelian", "Asian", "Atlantean", "Atlantic", "Bahamian", "Bahrainean", "Balinese", "Bangladeshi", "Barbadian", "Barcelonian", "Beethovenian", "Belgian", "Beninese", "Bismarckian", "Brazilian", "British", "Buddhist", "Burkinese", "Burmese", "Caesarian", "Californian", "Cambodian", "Canadian", "Chinese", "Christian", "Colombian", "Confucian", "Congolese", "Cormoran", "Costa Rican", "Cypriot", "Danish", "Darwinian", "Diabolical", "Dutch", "Ecuadorian", "Egyptian", "Einsteinian", "Elizabethan", "English", "Finnish", "French", "Freudian", "Gabonese", "Gaussian", "German", "Greek", "Guyanese", "Himalayan", "Hindu", "Hitlerian", "Honduran", "Icelandic", "Indian", "Indonesian", "Intelligent", "Iranian", "Iraqi", "Italian", "Japanese", "Jungian", "Kazakh", "Korean", "kuban", "Kyrgyz", "Laotian", "Lebanese", "Lilliputian", "Lincolnian", "Machiavellian", "Madagascan", "Malagasy", "Marxist", "Mayan", "Mexican", "Middle Eastern", "Monacan", "Mozartian", "Muscovite", "Nepalese", "Newtonian", "Norwegian", "Orwellian", "Pacific", "Parisian", "Peruvian", "Philippine", "Plutonian", "Polish", "Polynesian", "Portuguese", "Putinist", "Roman", "Romanian", "Rooseveltian", "Russian", "Salvadorean", "Sammarinese", "Senegalese", "Shakespearean", "Slovak", "Somali", "South American", "Spanish", "Spanish", "Sri-Lankan", "Sudanese", "Swazi", "Swiss", "Taiwanese", "Thai", "Thatcherite", "Tibetan", "Torontonian", "Turkish", "Turkishish", "Turkmen", "Uzbek", "Victorian", "Viennese", "Vietnamese", "Welsh"},
|
||||||
|
"adjective_demonstrative": {"this", "that", "these", "those", "it", "here", "there", "over there"},
|
||||||
|
"adjective_possessive": {"my", "your", "his", "her", "its", "our", "their"},
|
||||||
|
"adjective_interrogative": {"what", "whose", "where", "why", "how", "which"},
|
||||||
|
"adjective_indefinite": {"all", "any", "anything", "everyone", "few", "nobody", "one", "some", "someone", "everybody", "anyone", "each", "everything", "many", "none", "several", "somebody"},
|
||||||
|
|
||||||
|
// Pronouns
|
||||||
|
"pronoun_personal": {"I", "we", "you", "he", "she", "it", "they"},
|
||||||
|
"pronoun_object": {"me", "us", "you", "her", "him", "it", "them"},
|
||||||
|
"pronoun_possessive": {"mine", "ours", "yours", "hers", "his", "theirs"},
|
||||||
|
"pronoun_reflective": {"myself", "yourself", "herself", "himself", "itself", "ourselves", "yourselves", "themselves"},
|
||||||
|
"pronoun_indefinite": {"all", "another", "any", "anybody", "anyone", "anything", "both", "each", "either", "everybody", "everyone", "everything", "few", "many", "most", "neither", "nobody", "none", "no one", "nothing", "one", "other", "others", "several", "some", "somebody", "someone", "something", "such"},
|
||||||
|
"pronoun_demonstrative": {"this", "that", "these", "those"},
|
||||||
|
"pronoun_interrogative": {"who", "whom", "which", "what", "whose", "where", "when", "why", "how"},
|
||||||
|
"pronoun_relative": {"as", "that", "what", "whatever", "which", "whichever", "who", "whoever", "whom", "whomever", "whose"},
|
||||||
|
|
||||||
|
// Connectives
|
||||||
|
"connective_time": {"after a while", "afterwards", "at once", "at this moment", "at this point", "before that", "finally", "first", "here", "in the end", "lastly", "later on", "meanwhile", "next", "next time", "now", "on another occasion", "previously", "since", "soon", "straightaway", "then", "until then", "when", "whenever", "while"},
|
||||||
|
"connective_comparative": {"additionally", "also", "as well", "even", "furthermore", "in addition", "indeed", "let alone", "moreover", "not only", "alternatively", "anyway", "but", "by contrast", "differs from", "elsewhere", "even so", "however", "in contrast", "in fact", "in other respects", "in spite of this", "in that respect", "instead", "nevertheless", "on the contrary", "on the other hand", "rather", "though", "whereas", "yet", "after all", "anyway", "besides", "moreover"},
|
||||||
|
"connective_complaint": {"besides", "e.g.", "for example", "for instance", "i.e.", "in other words", "in that", "that is to say"},
|
||||||
|
"connective_listing": {"firstly", "secondly", "first of all", "finally", "lastly", "for one thing", "for another", "in the first place", "to begin with", "next", "in summation", "to conclude"},
|
||||||
|
"connective_casual": {"accordingly", "all the same", "an effect of", "an outcome of", "an upshot of", "as a consequence of", "as a result of", "because", "caused by", "consequently", "despite this", "even though", "hence", "however", "in that case", "moreover", "nevertheless", "otherwise", "so", "so as", "stemmed from", "still", "then", "therefore", "though", "under the circumstances", "yet"},
|
||||||
|
"connective_examplify": {"accordingly", "as a result", "as exemplified by", "consequently", "for example", "for instance", "for one thing", "including", "provided that", "since", "so", "such as", "then", "therefore", "these include", "through", "unless", "without"},
|
||||||
|
|
||||||
|
// Misc
|
||||||
|
"interjection": {"wow", "hey", "oops", "ouch", "yay", "aha", "eek", "huh", "hmm", "whoa", "yikes", "phew", "gee", "alas", "bravo"},
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
/*
|
||||||
|
Package gofakeit provides a set of functions that generate random data
|
||||||
|
*/
|
||||||
|
package gofakeit
|
||||||
|
|
@ -0,0 +1,98 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
// Emoji will return a random fun emoji
|
||||||
|
func Emoji() string { return emoji(GlobalFaker) }
|
||||||
|
|
||||||
|
// Emoji will return a random fun emoji
|
||||||
|
func (f *Faker) Emoji() string { return emoji(f) }
|
||||||
|
|
||||||
|
func emoji(f *Faker) string { return getRandValue(f, []string{"emoji", "emoji"}) }
|
||||||
|
|
||||||
|
// EmojiDescription will return a random fun emoji description
|
||||||
|
func EmojiDescription() string { return emojiDescription(GlobalFaker) }
|
||||||
|
|
||||||
|
// EmojiDescription will return a random fun emoji description
|
||||||
|
func (f *Faker) EmojiDescription() string { return emojiDescription(f) }
|
||||||
|
|
||||||
|
func emojiDescription(f *Faker) string { return getRandValue(f, []string{"emoji", "description"}) }
|
||||||
|
|
||||||
|
// EmojiCategory will return a random fun emoji category
|
||||||
|
func EmojiCategory() string { return emojiCategory(GlobalFaker) }
|
||||||
|
|
||||||
|
// EmojiCategory will return a random fun emoji category
|
||||||
|
func (f *Faker) EmojiCategory() string { return emojiCategory(f) }
|
||||||
|
|
||||||
|
func emojiCategory(f *Faker) string { return getRandValue(f, []string{"emoji", "category"}) }
|
||||||
|
|
||||||
|
// EmojiAlias will return a random fun emoji alias
|
||||||
|
func EmojiAlias() string { return emojiAlias(GlobalFaker) }
|
||||||
|
|
||||||
|
// EmojiAlias will return a random fun emoji alias
|
||||||
|
func (f *Faker) EmojiAlias() string { return emojiAlias(f) }
|
||||||
|
|
||||||
|
func emojiAlias(f *Faker) string { return getRandValue(f, []string{"emoji", "alias"}) }
|
||||||
|
|
||||||
|
// EmojiTag will return a random fun emoji tag
|
||||||
|
func EmojiTag() string { return emojiTag(GlobalFaker) }
|
||||||
|
|
||||||
|
// EmojiTag will return a random fun emoji tag
|
||||||
|
func (f *Faker) EmojiTag() string { return emojiTag(f) }
|
||||||
|
|
||||||
|
func emojiTag(f *Faker) string { return getRandValue(f, []string{"emoji", "tag"}) }
|
||||||
|
|
||||||
|
func addEmojiLookup() {
|
||||||
|
AddFuncLookup("emoji", Info{
|
||||||
|
Display: "Emoji",
|
||||||
|
Category: "emoji",
|
||||||
|
Description: "Digital symbol expressing feelings or ideas in text messages and online chats",
|
||||||
|
Example: "🤣",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return emoji(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("emojidescription", Info{
|
||||||
|
Display: "Emoji Description",
|
||||||
|
Category: "emoji",
|
||||||
|
Description: "Brief explanation of the meaning or emotion conveyed by an emoji",
|
||||||
|
Example: "face vomiting",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return emojiDescription(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("emojicategory", Info{
|
||||||
|
Display: "Emoji Category",
|
||||||
|
Category: "emoji",
|
||||||
|
Description: "Group or classification of emojis based on their common theme or use, like 'smileys' or 'animals'",
|
||||||
|
Example: "Smileys & Emotion",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return emojiCategory(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("emojialias", Info{
|
||||||
|
Display: "Emoji Alias",
|
||||||
|
Category: "emoji",
|
||||||
|
Description: "Alternative name or keyword used to represent a specific emoji in text or code",
|
||||||
|
Example: "smile",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return emojiAlias(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("emojitag", Info{
|
||||||
|
Display: "Emoji Tag",
|
||||||
|
Category: "emoji",
|
||||||
|
Description: "Label or keyword associated with an emoji to categorize or search for it easily",
|
||||||
|
Example: "happy",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return emojiTag(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,241 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Error will return a random generic error
|
||||||
|
func Error() error {
|
||||||
|
return err(GlobalFaker)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error will return a random generic error
|
||||||
|
func (f *Faker) Error() error {
|
||||||
|
return err(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func err(f *Faker) error {
|
||||||
|
genStr, _ := generate(f, getRandValue(f, []string{"error", "generic"}))
|
||||||
|
return errors.New(genStr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorObject will return a random error object word
|
||||||
|
func ErrorObject() error {
|
||||||
|
return errorObject(GlobalFaker)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorObject will return a random error object word
|
||||||
|
func (f *Faker) ErrorObject() error {
|
||||||
|
return errorObject(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func errorObject(f *Faker) error {
|
||||||
|
genStr, _ := generate(f, getRandValue(f, []string{"error", "object"}))
|
||||||
|
return errors.New(genStr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorDatabase will return a random database error
|
||||||
|
func ErrorDatabase() error {
|
||||||
|
return errorDatabase(GlobalFaker)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorDatabase will return a random database error
|
||||||
|
func (f *Faker) ErrorDatabase() error {
|
||||||
|
return errorDatabase(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func errorDatabase(f *Faker) error {
|
||||||
|
genStr, _ := generate(f, getRandValue(f, []string{"error", "database"}))
|
||||||
|
return errors.New(genStr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorGRPC will return a random gRPC error
|
||||||
|
func ErrorGRPC() error {
|
||||||
|
return errorGRPC(GlobalFaker)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorGRPC will return a random gRPC error
|
||||||
|
func (f *Faker) ErrorGRPC() error {
|
||||||
|
return errorGRPC(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func errorGRPC(f *Faker) error {
|
||||||
|
genStr, _ := generate(f, getRandValue(f, []string{"error", "grpc"}))
|
||||||
|
return errors.New(genStr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorHTTP will return a random HTTP error
|
||||||
|
func ErrorHTTP() error {
|
||||||
|
return errorHTTP(GlobalFaker)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorHTTP will return a random HTTP error
|
||||||
|
func (f *Faker) ErrorHTTP() error {
|
||||||
|
return errorHTTP(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func errorHTTP(f *Faker) error {
|
||||||
|
genStr, _ := generate(f, getRandValue(f, []string{"error", "http"}))
|
||||||
|
return errors.New(genStr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorHTTPClient will return a random HTTP client error response (400-418)
|
||||||
|
func ErrorHTTPClient() error {
|
||||||
|
return errorHTTPClient(GlobalFaker)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorHTTPClient will return a random HTTP client error response (400-418)
|
||||||
|
func (f *Faker) ErrorHTTPClient() error {
|
||||||
|
return errorHTTPClient(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func errorHTTPClient(f *Faker) error {
|
||||||
|
genStr, _ := generate(f, getRandValue(f, []string{"error", "http_client"}))
|
||||||
|
return errors.New(genStr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorHTTPServer will return a random HTTP server error response (500-511)
|
||||||
|
func ErrorHTTPServer() error {
|
||||||
|
return errorHTTPServer(GlobalFaker)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorHTTPServer will return a random HTTP server error response (500-511)
|
||||||
|
func (f *Faker) ErrorHTTPServer() error {
|
||||||
|
return errorHTTPServer(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func errorHTTPServer(f *Faker) error {
|
||||||
|
genStr, _ := generate(f, getRandValue(f, []string{"error", "http_server"}))
|
||||||
|
return errors.New(genStr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorRuntime will return a random runtime error
|
||||||
|
func ErrorRuntime() error {
|
||||||
|
return errorRuntime(GlobalFaker)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorRuntime will return a random runtime error
|
||||||
|
func (f *Faker) ErrorRuntime() error {
|
||||||
|
return errorRuntime(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func errorRuntime(f *Faker) error {
|
||||||
|
genStr, _ := generate(f, getRandValue(f, []string{"error", "runtime"}))
|
||||||
|
return errors.New(genStr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorValidation will return a random validation error
|
||||||
|
func ErrorValidation() error {
|
||||||
|
return errorValidation(GlobalFaker)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorValidation will return a random validation error
|
||||||
|
func (f *Faker) ErrorValidation() error {
|
||||||
|
return errorValidation(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func errorValidation(f *Faker) error {
|
||||||
|
genStr, _ := generate(f, getRandValue(f, []string{"error", "validation"}))
|
||||||
|
return errors.New(genStr)
|
||||||
|
}
|
||||||
|
|
||||||
|
func addErrorLookup() {
|
||||||
|
AddFuncLookup("error", Info{
|
||||||
|
Display: "Error",
|
||||||
|
Category: "error",
|
||||||
|
Description: "Message displayed by a computer or software when a problem or mistake is encountered",
|
||||||
|
Example: "syntax error",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return err(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("errorobject", Info{
|
||||||
|
Display: "Error object word",
|
||||||
|
Category: "error",
|
||||||
|
Description: "Various categories conveying details about encountered errors",
|
||||||
|
Example: "protocol",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return errorObject(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("errordatabase", Info{
|
||||||
|
Display: "Database error",
|
||||||
|
Category: "error",
|
||||||
|
Description: "A problem or issue encountered while accessing or managing a database",
|
||||||
|
Example: "sql error",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return errorDatabase(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("errorgrpc", Info{
|
||||||
|
Display: "gRPC error",
|
||||||
|
Category: "error",
|
||||||
|
Description: "Communication failure in the high-performance, open-source universal RPC framework",
|
||||||
|
Example: "client protocol error",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return errorGRPC(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("errorhttp", Info{
|
||||||
|
Display: "HTTP error",
|
||||||
|
Category: "error",
|
||||||
|
Description: "A problem with a web http request",
|
||||||
|
Example: "invalid method",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return errorHTTP(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("errorhttpclient", Info{
|
||||||
|
Display: "HTTP client error",
|
||||||
|
Category: "error",
|
||||||
|
Description: "Failure or issue occurring within a client software that sends requests to web servers",
|
||||||
|
Example: "request timeout",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return errorHTTPClient(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("errorhttpserver", Info{
|
||||||
|
Display: "HTTP server error",
|
||||||
|
Category: "error",
|
||||||
|
Description: "Failure or issue occurring within a server software that recieves requests from clients",
|
||||||
|
Example: "internal server error",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return errorHTTPServer(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("errorruntime", Info{
|
||||||
|
Display: "Runtime error",
|
||||||
|
Category: "error",
|
||||||
|
Description: "Malfunction occuring during program execution, often causing abrupt termination or unexpected behavior",
|
||||||
|
Example: "address out of bounds",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return errorRuntime(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("errorvalidation", Info{
|
||||||
|
Display: "Validation error",
|
||||||
|
Category: "error",
|
||||||
|
Description: "Occurs when input data fails to meet required criteria or format specifications",
|
||||||
|
Example: "missing required field",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return errorValidation(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,84 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Fakeable is an interface that can be implemented by a type to provide a custom fake value.
|
||||||
|
type Fakeable interface {
|
||||||
|
// Fake returns a fake value for the type.
|
||||||
|
Fake(faker *Faker) (any, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
func isFakeable(t reflect.Type) bool {
|
||||||
|
fakeableTyp := reflect.TypeOf((*Fakeable)(nil)).Elem()
|
||||||
|
|
||||||
|
return t.Implements(fakeableTyp) || reflect.PointerTo(t).Implements(fakeableTyp)
|
||||||
|
}
|
||||||
|
|
||||||
|
func callFake(faker *Faker, v reflect.Value, possibleKinds ...reflect.Kind) (any, error) {
|
||||||
|
f, ok := v.Addr().Interface().(Fakeable)
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New("not a Fakeable type")
|
||||||
|
}
|
||||||
|
|
||||||
|
fakedValue, err := f.Fake(faker)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error calling Fake: %w", err)
|
||||||
|
}
|
||||||
|
k := reflect.TypeOf(fakedValue).Kind()
|
||||||
|
if !containsKind(possibleKinds, k) {
|
||||||
|
return nil, fmt.Errorf("returned value kind %q is not amongst the valid ones: %v", k, possibleKinds)
|
||||||
|
}
|
||||||
|
|
||||||
|
switch k {
|
||||||
|
case reflect.String:
|
||||||
|
return reflect.ValueOf(fakedValue).String(), nil
|
||||||
|
case reflect.Bool:
|
||||||
|
return reflect.ValueOf(fakedValue).Bool(), nil
|
||||||
|
case reflect.Int:
|
||||||
|
return int(reflect.ValueOf(fakedValue).Int()), nil
|
||||||
|
case reflect.Int8:
|
||||||
|
return int8(reflect.ValueOf(fakedValue).Int()), nil
|
||||||
|
case reflect.Int16:
|
||||||
|
return int16(reflect.ValueOf(fakedValue).Int()), nil
|
||||||
|
case reflect.Int32:
|
||||||
|
return int32(reflect.ValueOf(fakedValue).Int()), nil
|
||||||
|
case reflect.Int64:
|
||||||
|
return int64(reflect.ValueOf(fakedValue).Int()), nil
|
||||||
|
case reflect.Uint:
|
||||||
|
return uint(reflect.ValueOf(fakedValue).Uint()), nil
|
||||||
|
case reflect.Uint8:
|
||||||
|
return uint8(reflect.ValueOf(fakedValue).Uint()), nil
|
||||||
|
case reflect.Uint16:
|
||||||
|
return uint16(reflect.ValueOf(fakedValue).Uint()), nil
|
||||||
|
case reflect.Uint32:
|
||||||
|
return uint32(reflect.ValueOf(fakedValue).Uint()), nil
|
||||||
|
case reflect.Uint64:
|
||||||
|
return uint64(reflect.ValueOf(fakedValue).Uint()), nil
|
||||||
|
case reflect.Float32:
|
||||||
|
return float32(reflect.ValueOf(fakedValue).Float()), nil
|
||||||
|
case reflect.Float64:
|
||||||
|
return float64(reflect.ValueOf(fakedValue).Float()), nil
|
||||||
|
case reflect.Slice, reflect.Array:
|
||||||
|
return reflect.ValueOf(fakedValue).Interface(), nil
|
||||||
|
case reflect.Map:
|
||||||
|
return reflect.ValueOf(fakedValue).Interface(), nil
|
||||||
|
case reflect.Struct:
|
||||||
|
return reflect.ValueOf(fakedValue).Interface(), nil
|
||||||
|
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unsupported type %q", k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func containsKind(possibleKinds []reflect.Kind, kind reflect.Kind) bool {
|
||||||
|
for _, k := range possibleKinds {
|
||||||
|
if k == kind {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,112 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"math/rand/v2"
|
||||||
|
"reflect"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/brianvoe/gofakeit/v7/source"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Create global variable to deal with global function call
|
||||||
|
var GlobalFaker *Faker = New(0)
|
||||||
|
|
||||||
|
// Faker struct is the primary struct for using localized
|
||||||
|
type Faker struct {
|
||||||
|
Rand rand.Source
|
||||||
|
|
||||||
|
// Lock to make thread safe
|
||||||
|
Locked bool
|
||||||
|
mu sync.Mutex
|
||||||
|
}
|
||||||
|
|
||||||
|
// New creates and returns a new Faker struct seeded with a given seed
|
||||||
|
// using the PCG algorithm in lock mode for thread safety
|
||||||
|
func New(seed uint64) *Faker {
|
||||||
|
// If seed is 0, use a random crypto seed
|
||||||
|
if seed == 0 {
|
||||||
|
faker := NewFaker(source.NewCrypto(), false)
|
||||||
|
seed = faker.Uint64()
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Faker{
|
||||||
|
Rand: rand.NewPCG(seed, seed),
|
||||||
|
Locked: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewFaker takes in a rand.Source and thread lock state and returns a new Faker struct
|
||||||
|
func NewFaker(src rand.Source, lock bool) *Faker {
|
||||||
|
return &Faker{
|
||||||
|
Rand: src,
|
||||||
|
Locked: lock,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Seed attempts to seed the Faker with the given seed
|
||||||
|
func (f *Faker) Seed(args ...any) error {
|
||||||
|
// Lock if locked
|
||||||
|
if f.Locked {
|
||||||
|
f.mu.Lock()
|
||||||
|
defer f.mu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure GlobalFaker is not nil and Rand is initialized
|
||||||
|
if GlobalFaker == nil || GlobalFaker.Rand == nil {
|
||||||
|
return errors.New("GlobalFaker or GlobalFaker.Rand is nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
// If args is empty or 0, seed with a random crypto seed
|
||||||
|
if len(args) == 0 {
|
||||||
|
faker := NewFaker(source.NewCrypto(), false)
|
||||||
|
args = append(args, faker.Uint64())
|
||||||
|
}
|
||||||
|
|
||||||
|
if args[0] == 0 {
|
||||||
|
faker := NewFaker(source.NewCrypto(), false)
|
||||||
|
args[0] = faker.Uint64()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve the Seed method
|
||||||
|
method := reflect.ValueOf(GlobalFaker.Rand).MethodByName("Seed")
|
||||||
|
if !method.IsValid() {
|
||||||
|
return errors.New("Seed method not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adjust args if method requires exactly 2 args but only 1 was provided
|
||||||
|
if method.Type().NumIn() == 2 && len(args) == 1 {
|
||||||
|
args = append(args, args[0]) // Duplicate the first value if only one is provided
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get array of function argument types and prepare converted arguments
|
||||||
|
argTypes := make([]reflect.Type, method.Type().NumIn())
|
||||||
|
convertedArgs := make([]reflect.Value, len(args))
|
||||||
|
for i := 0; i < method.Type().NumIn(); i++ {
|
||||||
|
argTypes[i] = method.Type().In(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert args to the expected type by the Seed method
|
||||||
|
for i, arg := range args {
|
||||||
|
if i < len(argTypes) { // Ensure arg index is within argTypes bounds
|
||||||
|
argValue := reflect.ValueOf(arg)
|
||||||
|
// Check if conversion is necessary
|
||||||
|
if argValue.Type().ConvertibleTo(argTypes[i]) {
|
||||||
|
convertedArgs[i] = argValue.Convert(argTypes[i])
|
||||||
|
} else {
|
||||||
|
// If not convertible, use the argument as is (reflectively)
|
||||||
|
convertedArgs[i] = argValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dynamically call the Seed method with converted arguments
|
||||||
|
method.Call(convertedArgs)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Seed attempts to seed the GlobalFaker with the given seed
|
||||||
|
func Seed(args ...any) error {
|
||||||
|
return GlobalFaker.Seed(args...)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
// FileExtension will generate a random file extension
|
||||||
|
func FileExtension() string { return fileExtension(GlobalFaker) }
|
||||||
|
|
||||||
|
// FileExtension will generate a random file extension
|
||||||
|
func (f *Faker) FileExtension() string { return fileExtension(f) }
|
||||||
|
|
||||||
|
func fileExtension(f *Faker) string { return getRandValue(f, []string{"file", "extension"}) }
|
||||||
|
|
||||||
|
// FileMimeType will generate a random mime file type
|
||||||
|
func FileMimeType() string { return fileMimeType(GlobalFaker) }
|
||||||
|
|
||||||
|
// FileMimeType will generate a random mime file type
|
||||||
|
func (f *Faker) FileMimeType() string { return fileMimeType(f) }
|
||||||
|
|
||||||
|
func fileMimeType(f *Faker) string { return getRandValue(f, []string{"file", "mime_type"}) }
|
||||||
|
|
||||||
|
func addFileLookup() {
|
||||||
|
AddFuncLookup("fileextension", Info{
|
||||||
|
Display: "File Extension",
|
||||||
|
Category: "file",
|
||||||
|
Description: "Suffix appended to a filename indicating its format or type",
|
||||||
|
Example: "nes",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return fileExtension(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("filemimetype", Info{
|
||||||
|
Display: "File Mime Type",
|
||||||
|
Category: "file",
|
||||||
|
Description: "Defines file format and nature for browsers and email clients using standardized identifiers",
|
||||||
|
Example: "application/json",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return fileMimeType(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,127 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strconv"
|
||||||
|
"unicode"
|
||||||
|
)
|
||||||
|
|
||||||
|
const cusipStr = upperStr + numericStr
|
||||||
|
|
||||||
|
// CUSIP
|
||||||
|
func Cusip() string {
|
||||||
|
return cusip(GlobalFaker)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *Faker) Cusip() string {
|
||||||
|
return cusip(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func cusip(f *Faker) string {
|
||||||
|
cusipBytes := make([]byte, 8)
|
||||||
|
for i := 0; i < len(cusipBytes); i++ {
|
||||||
|
cusipBytes[i] = byte(cusipStr[f.IntN(len(cusipStr))])
|
||||||
|
}
|
||||||
|
|
||||||
|
baseCusip := string(cusipBytes)
|
||||||
|
|
||||||
|
chkDigit := cusipChecksumDigit(baseCusip)
|
||||||
|
return baseCusip + chkDigit
|
||||||
|
}
|
||||||
|
|
||||||
|
// ISIN
|
||||||
|
func Isin() string {
|
||||||
|
return isin(GlobalFaker)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *Faker) Isin() string {
|
||||||
|
return isin(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func isin(f *Faker) string {
|
||||||
|
countryCode := countryAbr(f)
|
||||||
|
nsin := cusip(f)
|
||||||
|
isinChkDig := isinChecksumDigit(countryCode + nsin)
|
||||||
|
return countryCode + nsin + isinChkDig
|
||||||
|
}
|
||||||
|
|
||||||
|
// cusipChecksumDigit returns the checksum digit for a CUSIP
|
||||||
|
func cusipChecksumDigit(cusip string) string {
|
||||||
|
sum := 0
|
||||||
|
for i, c := range cusip {
|
||||||
|
v := 0
|
||||||
|
if unicode.IsDigit(c) {
|
||||||
|
v = int(c - '0')
|
||||||
|
}
|
||||||
|
if unicode.IsLetter(c) {
|
||||||
|
//0-indexed ordinal position of Letter + 10
|
||||||
|
v = int(c-'A') + 10
|
||||||
|
}
|
||||||
|
if i%2 != 0 {
|
||||||
|
// Multiply odd digits by two
|
||||||
|
v = v * 2
|
||||||
|
}
|
||||||
|
|
||||||
|
sum = sum + int(v/10) + v%10
|
||||||
|
}
|
||||||
|
|
||||||
|
return strconv.Itoa((10 - (sum % 10)) % 10)
|
||||||
|
}
|
||||||
|
|
||||||
|
// isinChecksumDigit returns the checksum digit for an ISIN
|
||||||
|
func isinChecksumDigit(isin string) string {
|
||||||
|
isinDigits := make([]int, 0)
|
||||||
|
for _, c := range isin {
|
||||||
|
if unicode.IsLetter(c) {
|
||||||
|
letterVal := int(c) - 55
|
||||||
|
// Each digit is added as a separate value
|
||||||
|
isinDigits = append(isinDigits, letterVal/10)
|
||||||
|
isinDigits = append(isinDigits, letterVal%10)
|
||||||
|
}
|
||||||
|
if unicode.IsDigit(c) {
|
||||||
|
isinDigits = append(isinDigits, int(c-'0'))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
oddSum := 0
|
||||||
|
evenSum := 0
|
||||||
|
|
||||||
|
// Take the per digit sum of the digitized ISIN, doubling even indexed digits
|
||||||
|
for i, d := range isinDigits {
|
||||||
|
if i%2 == 0 {
|
||||||
|
elem := 2 * d
|
||||||
|
if elem > 9 {
|
||||||
|
// If the element now has two digits, sum those digits
|
||||||
|
elem = (elem % 10) + (elem / 10)
|
||||||
|
}
|
||||||
|
evenSum += elem
|
||||||
|
} else {
|
||||||
|
oddSum += d
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return strconv.Itoa((10 - (oddSum+evenSum)%10) % 10)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lookup Adds
|
||||||
|
func addFinanceLookup() {
|
||||||
|
AddFuncLookup("cusip", Info{
|
||||||
|
Display: "CUSIP",
|
||||||
|
Category: "finance",
|
||||||
|
Description: "Unique identifier for securities, especially bonds, in the United States and Canada",
|
||||||
|
Example: "38259P508",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return cusip(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
AddFuncLookup("isin", Info{
|
||||||
|
Display: "ISIN",
|
||||||
|
Category: "finance",
|
||||||
|
Description: "International standard code for uniquely identifying securities worldwide",
|
||||||
|
Example: "CVLRQCZBXQ97",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return isin(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,177 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Fruit will return a random fruit name
|
||||||
|
func Fruit() string { return fruit(GlobalFaker) }
|
||||||
|
|
||||||
|
// Fruit will return a random fruit name
|
||||||
|
func (f *Faker) Fruit() string { return fruit(f) }
|
||||||
|
|
||||||
|
func fruit(f *Faker) string { return getRandValue(f, []string{"food", "fruit"}) }
|
||||||
|
|
||||||
|
// Vegetable will return a random vegetable name
|
||||||
|
func Vegetable() string { return vegetable(GlobalFaker) }
|
||||||
|
|
||||||
|
// Vegetable will return a random vegetable name
|
||||||
|
func (f *Faker) Vegetable() string { return vegetable(f) }
|
||||||
|
|
||||||
|
func vegetable(f *Faker) string { return getRandValue(f, []string{"food", "vegetable"}) }
|
||||||
|
|
||||||
|
// Breakfast will return a random breakfast name
|
||||||
|
func Breakfast() string { return breakfast(GlobalFaker) }
|
||||||
|
|
||||||
|
// Breakfast will return a random breakfast name
|
||||||
|
func (f *Faker) Breakfast() string { return breakfast(f) }
|
||||||
|
|
||||||
|
func breakfast(f *Faker) string {
|
||||||
|
v := getRandValue(f, []string{"food", "breakfast"})
|
||||||
|
return strings.ToUpper(v[:1]) + v[1:]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lunch will return a random lunch name
|
||||||
|
func Lunch() string { return lunch(GlobalFaker) }
|
||||||
|
|
||||||
|
// Lunch will return a random lunch name
|
||||||
|
func (f *Faker) Lunch() string { return lunch(f) }
|
||||||
|
|
||||||
|
func lunch(f *Faker) string {
|
||||||
|
v := getRandValue(f, []string{"food", "lunch"})
|
||||||
|
return strings.ToUpper(v[:1]) + v[1:]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dinner will return a random dinner name
|
||||||
|
func Dinner() string { return dinner(GlobalFaker) }
|
||||||
|
|
||||||
|
// Dinner will return a random dinner name
|
||||||
|
func (f *Faker) Dinner() string { return dinner(f) }
|
||||||
|
|
||||||
|
func dinner(f *Faker) string {
|
||||||
|
v := getRandValue(f, []string{"food", "dinner"})
|
||||||
|
return strings.ToUpper(v[:1]) + v[1:]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Drink will return a random drink name
|
||||||
|
func Drink() string { return drink(GlobalFaker) }
|
||||||
|
|
||||||
|
// Drink will return a random drink name
|
||||||
|
func (f *Faker) Drink() string { return drink(f) }
|
||||||
|
|
||||||
|
func drink(f *Faker) string {
|
||||||
|
v := getRandValue(f, []string{"food", "drink"})
|
||||||
|
return strings.ToUpper(v[:1]) + v[1:]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Snack will return a random snack name
|
||||||
|
func Snack() string { return snack(GlobalFaker) }
|
||||||
|
|
||||||
|
// Snack will return a random snack name
|
||||||
|
func (f *Faker) Snack() string { return snack(f) }
|
||||||
|
|
||||||
|
func snack(f *Faker) string {
|
||||||
|
v := getRandValue(f, []string{"food", "snack"})
|
||||||
|
return strings.ToUpper(v[:1]) + v[1:]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dessert will return a random dessert name
|
||||||
|
func Dessert() string { return dessert(GlobalFaker) }
|
||||||
|
|
||||||
|
// Dessert will return a random dessert name
|
||||||
|
func (f *Faker) Dessert() string { return dessert(f) }
|
||||||
|
|
||||||
|
func dessert(f *Faker) string {
|
||||||
|
v := getRandValue(f, []string{"food", "dessert"})
|
||||||
|
return strings.ToUpper(v[:1]) + v[1:]
|
||||||
|
}
|
||||||
|
|
||||||
|
func addFoodLookup() {
|
||||||
|
AddFuncLookup("fruit", Info{
|
||||||
|
Display: "Fruit",
|
||||||
|
Category: "food",
|
||||||
|
Description: "Edible plant part, typically sweet, enjoyed as a natural snack or dessert",
|
||||||
|
Example: "Peach",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return fruit(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("vegetable", Info{
|
||||||
|
Display: "Vegetable",
|
||||||
|
Category: "food",
|
||||||
|
Description: "Edible plant or part of a plant, often used in savory cooking or salads",
|
||||||
|
Example: "Amaranth Leaves",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return vegetable(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("breakfast", Info{
|
||||||
|
Display: "Breakfast",
|
||||||
|
Category: "food",
|
||||||
|
Description: "First meal of the day, typically eaten in the morning",
|
||||||
|
Example: "Blueberry banana happy face pancakes",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return breakfast(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("lunch", Info{
|
||||||
|
Display: "Lunch",
|
||||||
|
Category: "food",
|
||||||
|
Description: "Midday meal, often lighter than dinner, eaten around noon",
|
||||||
|
Example: "No bake hersheys bar pie",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return lunch(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("dinner", Info{
|
||||||
|
Display: "Dinner",
|
||||||
|
Category: "food",
|
||||||
|
Description: "Evening meal, typically the day's main and most substantial meal",
|
||||||
|
Example: "Wild addicting dip",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return dinner(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("drink", Info{
|
||||||
|
Display: "Drink",
|
||||||
|
Category: "food",
|
||||||
|
Description: "Liquid consumed for hydration, pleasure, or nutritional benefits",
|
||||||
|
Example: "Soda",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return drink(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("snack", Info{
|
||||||
|
Display: "Snack",
|
||||||
|
Category: "food",
|
||||||
|
Description: "Random snack",
|
||||||
|
Example: "Small, quick food item eaten between meals",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return snack(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("dessert", Info{
|
||||||
|
Display: "Dessert",
|
||||||
|
Category: "food",
|
||||||
|
Description: "Sweet treat often enjoyed after a meal",
|
||||||
|
Example: "French napoleons",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return dessert(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,101 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Gamertag will generate a random video game username
|
||||||
|
func Gamertag() string { return gamertag(GlobalFaker) }
|
||||||
|
|
||||||
|
// Gamertag will generate a random video game username
|
||||||
|
func (f *Faker) Gamertag() string { return gamertag(f) }
|
||||||
|
|
||||||
|
func gamertag(f *Faker) string {
|
||||||
|
str := ""
|
||||||
|
num := number(f, 1, 4)
|
||||||
|
switch num {
|
||||||
|
case 1:
|
||||||
|
str = fmt.Sprintf("%s%ser", title(nounConcrete(f)), title(verbAction(f)))
|
||||||
|
case 2:
|
||||||
|
str = fmt.Sprintf("%s%s", title(adjectiveDescriptive(f)), title(animal(f)))
|
||||||
|
case 3:
|
||||||
|
str = fmt.Sprintf("%s%s", title(adjectiveDescriptive(f)), title(nounConcrete(f)))
|
||||||
|
case 4:
|
||||||
|
str = fmt.Sprintf("%s%s", title(fruit(f)), title(adjectiveDescriptive(f)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Randomly determine if we should add a number
|
||||||
|
if f.IntN(3) == 1 {
|
||||||
|
str += digitN(f, uint(number(f, 1, 3)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove any spaces
|
||||||
|
str = strings.Replace(str, " ", "", -1)
|
||||||
|
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dice will generate a random set of dice
|
||||||
|
func Dice(numDice uint, sides []uint) []uint { return dice(GlobalFaker, numDice, sides) }
|
||||||
|
|
||||||
|
// Dice will generate a random set of dice
|
||||||
|
func (f *Faker) Dice(numDice uint, sides []uint) []uint { return dice(f, numDice, sides) }
|
||||||
|
|
||||||
|
func dice(f *Faker, numDice uint, sides []uint) []uint {
|
||||||
|
dice := make([]uint, numDice)
|
||||||
|
|
||||||
|
// If we dont have any sides well set the sides to 6
|
||||||
|
if len(sides) == 0 {
|
||||||
|
sides = []uint{6}
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := range dice {
|
||||||
|
// If sides[i] doesnt exist use the first side
|
||||||
|
if len(sides)-1 < i {
|
||||||
|
dice[i] = uint(number(f, 1, int(sides[0])))
|
||||||
|
} else {
|
||||||
|
dice[i] = uint(number(f, 1, int(sides[i])))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dice
|
||||||
|
}
|
||||||
|
|
||||||
|
func addGameLookup() {
|
||||||
|
AddFuncLookup("gamertag", Info{
|
||||||
|
Display: "Gamertag",
|
||||||
|
Category: "game",
|
||||||
|
Description: "User-selected online username or alias used for identification in games",
|
||||||
|
Example: "footinterpret63",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return gamertag(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("dice", Info{
|
||||||
|
Display: "Dice",
|
||||||
|
Category: "game",
|
||||||
|
Description: "Small, cube-shaped objects used in games of chance for random outcomes",
|
||||||
|
Example: "[5, 2, 3]",
|
||||||
|
Output: "[]uint",
|
||||||
|
Params: []Param{
|
||||||
|
{Field: "numdice", Display: "Number of Dice", Type: "uint", Default: "1", Description: "Number of dice to roll"},
|
||||||
|
{Field: "sides", Display: "Number of Sides", Type: "[]uint", Default: "[6]", Description: "Number of sides on each dice"},
|
||||||
|
},
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
numDice, err := info.GetUint(m, "numdice")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
sides, err := info.GetUintArray(m, "sides")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return dice(f, numDice, sides), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,600 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
"regexp/syntax"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Generate fake information from given string.
|
||||||
|
// Replaceable values should be within {}
|
||||||
|
//
|
||||||
|
// Functions
|
||||||
|
// Ex: {firstname} - billy
|
||||||
|
// Ex: {sentence:3} - Record river mind.
|
||||||
|
// Ex: {number:1,10} - 4
|
||||||
|
// Ex: {uuid} - 590c1440-9888-45b0-bd51-a817ee07c3f2
|
||||||
|
//
|
||||||
|
// Letters/Numbers
|
||||||
|
// Ex: ### - 481 - random numbers
|
||||||
|
// Ex: ??? - fda - random letters
|
||||||
|
//
|
||||||
|
// For a complete list of runnable functions use FuncsLookup
|
||||||
|
func Generate(dataVal string) (string, error) { return generate(GlobalFaker, dataVal) }
|
||||||
|
|
||||||
|
// Generate fake information from given string.
|
||||||
|
// Replaceable values should be within {}
|
||||||
|
//
|
||||||
|
// Functions
|
||||||
|
// Ex: {firstname} - billy
|
||||||
|
// Ex: {sentence:3} - Record river mind.
|
||||||
|
// Ex: {number:1,10} - 4
|
||||||
|
// Ex: {uuid} - 590c1440-9888-45b0-bd51-a817ee07c3f2
|
||||||
|
//
|
||||||
|
// Letters/Numbers
|
||||||
|
// Ex: ### - 481 - random numbers
|
||||||
|
// Ex: ??? - fda - random letters
|
||||||
|
//
|
||||||
|
// For a complete list of runnable functions use FuncsLookup
|
||||||
|
func (f *Faker) Generate(dataVal string) (string, error) { return generate(f, dataVal) }
|
||||||
|
|
||||||
|
func generate(f *Faker, dataVal string) (string, error) {
|
||||||
|
// Replace # with numbers and ? with letters
|
||||||
|
dataVal = replaceWithNumbers(f, dataVal)
|
||||||
|
dataVal = replaceWithLetters(f, dataVal)
|
||||||
|
|
||||||
|
// Check if string has any replaceable values
|
||||||
|
// Even if it doesnt its ok we will just return the string
|
||||||
|
if !strings.Contains(dataVal, "{") && !strings.Contains(dataVal, "}") {
|
||||||
|
return dataVal, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Variables to identify the index in which it exists
|
||||||
|
startCurly := -1
|
||||||
|
startCurlyIgnore := []int{}
|
||||||
|
endCurly := -1
|
||||||
|
endCurlyIgnore := []int{}
|
||||||
|
|
||||||
|
// Loop through string characters
|
||||||
|
for i := 0; i < len(dataVal); i++ {
|
||||||
|
// Check for ignores if equal skip
|
||||||
|
shouldSkip := false
|
||||||
|
for _, igs := range startCurlyIgnore {
|
||||||
|
if i == igs {
|
||||||
|
shouldSkip = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, ige := range endCurlyIgnore {
|
||||||
|
if i == ige {
|
||||||
|
shouldSkip = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if shouldSkip {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Identify items between brackets. Ex: {firstname}
|
||||||
|
if string(dataVal[i]) == "{" {
|
||||||
|
startCurly = i
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if startCurly != -1 && string(dataVal[i]) == "}" {
|
||||||
|
endCurly = i
|
||||||
|
}
|
||||||
|
if startCurly == -1 || endCurly == -1 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the value between brackets
|
||||||
|
fParts := dataVal[startCurly+1 : endCurly]
|
||||||
|
|
||||||
|
// Check if has params separated by :
|
||||||
|
fNameSplit := strings.SplitN(fParts, ":", 2)
|
||||||
|
fName := ""
|
||||||
|
fParams := ""
|
||||||
|
if len(fNameSplit) >= 1 {
|
||||||
|
fName = fNameSplit[0]
|
||||||
|
}
|
||||||
|
if len(fNameSplit) >= 2 {
|
||||||
|
fParams = fNameSplit[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check to see if its a replaceable lookup function
|
||||||
|
if info := GetFuncLookup(fName); info != nil {
|
||||||
|
// Get parameters, make sure params and the split both have values
|
||||||
|
mapParams := NewMapParams()
|
||||||
|
paramsLen := len(info.Params)
|
||||||
|
|
||||||
|
// If just one param and its a string simply just pass it
|
||||||
|
if paramsLen == 1 && info.Params[0].Type == "string" {
|
||||||
|
mapParams.Add(info.Params[0].Field, fParams)
|
||||||
|
} else if paramsLen > 0 && fParams != "" {
|
||||||
|
var err error
|
||||||
|
splitVals, err := funcLookupSplit(fParams)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
mapParams, err = addSplitValsToMapParams(splitVals, info, mapParams)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if mapParams.Size() == 0 {
|
||||||
|
mapParams = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call function
|
||||||
|
fValue, err := info.Generate(f, mapParams, info)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Successfully found, run replace with new value
|
||||||
|
dataVal = strings.Replace(dataVal, "{"+fParts+"}", fmt.Sprintf("%v", fValue), 1)
|
||||||
|
|
||||||
|
// Reset the curly index back to -1 and reset ignores
|
||||||
|
startCurly = -1
|
||||||
|
startCurlyIgnore = []int{}
|
||||||
|
endCurly = -1
|
||||||
|
endCurlyIgnore = []int{}
|
||||||
|
i = -1 // Reset back to the start of the string
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Couldnt find anything - mark curly brackets to skip and rerun
|
||||||
|
startCurlyIgnore = append(startCurlyIgnore, startCurly)
|
||||||
|
endCurlyIgnore = append(endCurlyIgnore, endCurly)
|
||||||
|
|
||||||
|
// Reset the curly index back to -1
|
||||||
|
startCurly = -1
|
||||||
|
endCurly = -1
|
||||||
|
i = -1 // Reset back to the start of the string
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
return dataVal, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FixedWidthOptions defines values needed for csv generation
|
||||||
|
type FixedWidthOptions struct {
|
||||||
|
RowCount int `json:"row_count" xml:"row_count" fake:"{number:1,10}"`
|
||||||
|
Fields []Field `json:"fields" xml:"fields" fake:"{fields}"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// FixedWidth generates an table of random data in fixed width format
|
||||||
|
// A nil FixedWidthOptions returns a randomly structured FixedWidth.
|
||||||
|
func FixedWidth(co *FixedWidthOptions) (string, error) { return fixeWidthFunc(GlobalFaker, co) }
|
||||||
|
|
||||||
|
// FixedWidth generates an table of random data in fixed width format
|
||||||
|
// A nil FixedWidthOptions returns a randomly structured FixedWidth.
|
||||||
|
func (f *Faker) FixedWidth(co *FixedWidthOptions) (string, error) { return fixeWidthFunc(f, co) }
|
||||||
|
|
||||||
|
// Function to generate a fixed width document
|
||||||
|
func fixeWidthFunc(f *Faker, co *FixedWidthOptions) (string, error) {
|
||||||
|
// If we didn't get FixedWidthOptions, create a new random one
|
||||||
|
if co == nil {
|
||||||
|
co = &FixedWidthOptions{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure you set a row count
|
||||||
|
if co.RowCount <= 0 {
|
||||||
|
co.RowCount = f.IntN(10) + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check fields
|
||||||
|
if len(co.Fields) <= 0 {
|
||||||
|
// Create random fields
|
||||||
|
co.Fields = []Field{
|
||||||
|
{Name: "Name", Function: "{firstname} {lastname}"},
|
||||||
|
{Name: "Email", Function: "email"},
|
||||||
|
{Name: "Password", Function: "password", Params: MapParams{"special": {"false"}, "space": {"false"}}},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data := [][]string{}
|
||||||
|
hasHeader := false
|
||||||
|
|
||||||
|
// Loop through fields, generate data and add to data array
|
||||||
|
for _, field := range co.Fields {
|
||||||
|
// Start new row
|
||||||
|
row := []string{}
|
||||||
|
|
||||||
|
// Add name to first value
|
||||||
|
if field.Name != "" {
|
||||||
|
hasHeader = true
|
||||||
|
}
|
||||||
|
row = append(row, field.Name)
|
||||||
|
|
||||||
|
// Get function
|
||||||
|
funcInfo := GetFuncLookup(field.Function)
|
||||||
|
var value any
|
||||||
|
if funcInfo == nil {
|
||||||
|
// Try to run the function through generate
|
||||||
|
for i := 0; i < co.RowCount; i++ {
|
||||||
|
genStr, err := generate(f, field.Function)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
row = append(row, genStr)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Generate function value
|
||||||
|
var err error
|
||||||
|
for i := 0; i < co.RowCount; i++ {
|
||||||
|
value, err = funcInfo.Generate(f, &field.Params, funcInfo)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add value to row
|
||||||
|
row = append(row, anyToString(value))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add row to data
|
||||||
|
data = append(data, row)
|
||||||
|
}
|
||||||
|
|
||||||
|
var result strings.Builder
|
||||||
|
|
||||||
|
// Calculate column widths
|
||||||
|
colWidths := make([]int, len(data))
|
||||||
|
for i, row := range data {
|
||||||
|
for _, value := range row {
|
||||||
|
width := len(value) + 5
|
||||||
|
if width > colWidths[i] {
|
||||||
|
colWidths[i] = width
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Append table rows to the string, excluding the entire row if the first value is empty
|
||||||
|
for i := 0; i < len(data[0]); i++ {
|
||||||
|
if !hasHeader && i == 0 {
|
||||||
|
continue // Skip the entire column if the first value is empty
|
||||||
|
}
|
||||||
|
|
||||||
|
var resultRow strings.Builder
|
||||||
|
for j, row := range data {
|
||||||
|
resultRow.WriteString(fmt.Sprintf("%-*s", colWidths[j], row[i]))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trim trailing spaces
|
||||||
|
result.WriteString(strings.TrimRight(resultRow.String(), " "))
|
||||||
|
|
||||||
|
// Only add new line if not the last row
|
||||||
|
if i != len(data[0])-1 {
|
||||||
|
result.WriteString("\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.String(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Regex will generate a string based upon a RE2 syntax
|
||||||
|
func Regex(regexStr string) string { return regex(GlobalFaker, regexStr) }
|
||||||
|
|
||||||
|
// Regex will generate a string based upon a RE2 syntax
|
||||||
|
func (f *Faker) Regex(regexStr string) string { return regex(f, regexStr) }
|
||||||
|
|
||||||
|
func regex(f *Faker, regexStr string) (gen string) {
|
||||||
|
re, err := syntax.Parse(regexStr, syntax.Perl)
|
||||||
|
if err != nil {
|
||||||
|
return "Could not parse regex string"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Panic catch
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
gen = fmt.Sprint(f)
|
||||||
|
return
|
||||||
|
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
return regexGenerate(f, re, len(regexStr)*100)
|
||||||
|
}
|
||||||
|
|
||||||
|
func regexGenerate(f *Faker, re *syntax.Regexp, limit int) string {
|
||||||
|
if limit <= 0 {
|
||||||
|
panic("Length limit reached when generating output")
|
||||||
|
}
|
||||||
|
|
||||||
|
op := re.Op
|
||||||
|
switch op {
|
||||||
|
case syntax.OpNoMatch: // matches no strings
|
||||||
|
// Do Nothing
|
||||||
|
case syntax.OpEmptyMatch: // matches empty string
|
||||||
|
return ""
|
||||||
|
case syntax.OpLiteral: // matches Runes sequence
|
||||||
|
var b strings.Builder
|
||||||
|
for _, ru := range re.Rune {
|
||||||
|
b.WriteRune(ru)
|
||||||
|
}
|
||||||
|
return b.String()
|
||||||
|
case syntax.OpCharClass: // matches Runes interpreted as range pair list
|
||||||
|
// number of possible chars
|
||||||
|
sum := 0
|
||||||
|
for i := 0; i < len(re.Rune); i += 2 {
|
||||||
|
sum += int(re.Rune[i+1]-re.Rune[i]) + 1
|
||||||
|
if re.Rune[i+1] == 0x10ffff { // rune range end
|
||||||
|
sum = -1
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// pick random char in range (inverse match group)
|
||||||
|
if sum == -1 {
|
||||||
|
chars := []uint8{}
|
||||||
|
for j := 0; j < len(allStr); j++ {
|
||||||
|
c := allStr[j]
|
||||||
|
|
||||||
|
// Check c in range
|
||||||
|
for i := 0; i < len(re.Rune); i += 2 {
|
||||||
|
if rune(c) >= re.Rune[i] && rune(c) <= re.Rune[i+1] {
|
||||||
|
chars = append(chars, c)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(chars) > 0 {
|
||||||
|
return string([]byte{chars[f.IntN(len(chars))]})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
r := f.IntN(int(sum))
|
||||||
|
var ru rune
|
||||||
|
sum = 0
|
||||||
|
for i := 0; i < len(re.Rune); i += 2 {
|
||||||
|
gap := int(re.Rune[i+1]-re.Rune[i]) + 1
|
||||||
|
if sum+gap > r {
|
||||||
|
ru = re.Rune[i] + rune(r-sum)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
sum += gap
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(ru)
|
||||||
|
case syntax.OpAnyCharNotNL, syntax.OpAnyChar: // matches any character(and except newline)
|
||||||
|
return randCharacter(f, allStr)
|
||||||
|
case syntax.OpBeginLine: // matches empty string at beginning of line
|
||||||
|
case syntax.OpEndLine: // matches empty string at end of line
|
||||||
|
case syntax.OpBeginText: // matches empty string at beginning of text
|
||||||
|
case syntax.OpEndText: // matches empty string at end of text
|
||||||
|
case syntax.OpWordBoundary: // matches word boundary `\b`
|
||||||
|
case syntax.OpNoWordBoundary: // matches word non-boundary `\B`
|
||||||
|
case syntax.OpCapture: // capturing subexpression with index Cap, optional name Name
|
||||||
|
return regexGenerate(f, re.Sub0[0], limit)
|
||||||
|
case syntax.OpStar: // matches Sub[0] zero or more times
|
||||||
|
var b strings.Builder
|
||||||
|
for i := 0; i < number(f, 0, 10); i++ {
|
||||||
|
for _, rs := range re.Sub {
|
||||||
|
b.WriteString(regexGenerate(f, rs, limit-b.Len()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return b.String()
|
||||||
|
case syntax.OpPlus: // matches Sub[0] one or more times
|
||||||
|
var b strings.Builder
|
||||||
|
for i := 0; i < number(f, 1, 10); i++ {
|
||||||
|
for _, rs := range re.Sub {
|
||||||
|
b.WriteString(regexGenerate(f, rs, limit-b.Len()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return b.String()
|
||||||
|
case syntax.OpQuest: // matches Sub[0] zero or one times
|
||||||
|
var b strings.Builder
|
||||||
|
for i := 0; i < number(f, 0, 1); i++ {
|
||||||
|
for _, rs := range re.Sub {
|
||||||
|
b.WriteString(regexGenerate(f, rs, limit-b.Len()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return b.String()
|
||||||
|
case syntax.OpRepeat: // matches Sub[0] at least Min times, at most Max (Max == -1 is no limit)
|
||||||
|
var b strings.Builder
|
||||||
|
count := 0
|
||||||
|
re.Max = int(math.Min(float64(re.Max), float64(10)))
|
||||||
|
if re.Max > re.Min {
|
||||||
|
count = f.IntN(re.Max - re.Min + 1)
|
||||||
|
}
|
||||||
|
for i := 0; i < re.Min || i < (re.Min+count); i++ {
|
||||||
|
for _, rs := range re.Sub {
|
||||||
|
b.WriteString(regexGenerate(f, rs, limit-b.Len()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return b.String()
|
||||||
|
case syntax.OpConcat: // matches concatenation of Subs
|
||||||
|
var b strings.Builder
|
||||||
|
for _, rs := range re.Sub {
|
||||||
|
b.WriteString(regexGenerate(f, rs, limit-b.Len()))
|
||||||
|
}
|
||||||
|
return b.String()
|
||||||
|
case syntax.OpAlternate: // matches alternation of Subs
|
||||||
|
return regexGenerate(f, re.Sub[number(f, 0, len(re.Sub)-1)], limit)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// Map will generate a random set of map data
|
||||||
|
func Map() map[string]any { return mapFunc(GlobalFaker) }
|
||||||
|
|
||||||
|
// Map will generate a random set of map data
|
||||||
|
func (f *Faker) Map() map[string]any { return mapFunc(f) }
|
||||||
|
|
||||||
|
func mapFunc(f *Faker) map[string]any {
|
||||||
|
m := map[string]any{}
|
||||||
|
|
||||||
|
randWordType := func() string {
|
||||||
|
s := randomString(f, []string{"lorem", "bs", "job", "name", "address"})
|
||||||
|
switch s {
|
||||||
|
case "bs":
|
||||||
|
return bs(f)
|
||||||
|
case "job":
|
||||||
|
return jobTitle(f)
|
||||||
|
case "name":
|
||||||
|
return name(f)
|
||||||
|
case "address":
|
||||||
|
return street(f) + ", " + city(f) + ", " + state(f) + " " + zip(f)
|
||||||
|
}
|
||||||
|
return word(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
randSlice := func() []string {
|
||||||
|
var sl []string
|
||||||
|
for ii := 0; ii < number(f, 3, 10); ii++ {
|
||||||
|
sl = append(sl, word(f))
|
||||||
|
}
|
||||||
|
return sl
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < number(f, 3, 10); i++ {
|
||||||
|
t := randomString(f, []string{"string", "int", "float", "slice", "map"})
|
||||||
|
switch t {
|
||||||
|
case "string":
|
||||||
|
m[word(f)] = randWordType()
|
||||||
|
case "int":
|
||||||
|
m[word(f)] = number(f, 1, 10000000)
|
||||||
|
case "float":
|
||||||
|
m[word(f)] = float32Range(f, 1, 1000000)
|
||||||
|
case "slice":
|
||||||
|
m[word(f)] = randSlice()
|
||||||
|
case "map":
|
||||||
|
mm := map[string]any{}
|
||||||
|
tt := randomString(f, []string{"string", "int", "float", "slice"})
|
||||||
|
switch tt {
|
||||||
|
case "string":
|
||||||
|
mm[word(f)] = randWordType()
|
||||||
|
case "int":
|
||||||
|
mm[word(f)] = number(f, 1, 10000000)
|
||||||
|
case "float":
|
||||||
|
mm[word(f)] = float32Range(f, 1, 1000000)
|
||||||
|
case "slice":
|
||||||
|
mm[word(f)] = randSlice()
|
||||||
|
}
|
||||||
|
m[word(f)] = mm
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
|
func addGenerateLookup() {
|
||||||
|
AddFuncLookup("generate", Info{
|
||||||
|
Display: "Generate",
|
||||||
|
Category: "generate",
|
||||||
|
Description: "Random string generated from string value based upon available data sets",
|
||||||
|
Example: "{firstname} {lastname} {email} - Markus Moen markusmoen@pagac.net",
|
||||||
|
Output: "string",
|
||||||
|
Params: []Param{
|
||||||
|
{Field: "str", Display: "String", Type: "string", Description: "String value to generate from"},
|
||||||
|
},
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
str, err := info.GetString(m, "str")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit the length of the string passed
|
||||||
|
if len(str) > 1000 {
|
||||||
|
return nil, errors.New("string length is too large. limit to 1000 characters")
|
||||||
|
}
|
||||||
|
|
||||||
|
return generate(f, str)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("fixed_width", Info{
|
||||||
|
Display: "Fixed Width",
|
||||||
|
Category: "generate",
|
||||||
|
Description: "Fixed width rows of output data based on input fields",
|
||||||
|
Example: `Name Email Password Age
|
||||||
|
Markus Moen sylvanmraz@murphy.net 6VlvH6qqXc7g 13
|
||||||
|
Alayna Wuckert santinostanton@carroll.biz g7sLrS0gEwLO 46
|
||||||
|
Lura Lockman zacherykuhic@feil.name S8gV7Z64KlHG 12`,
|
||||||
|
Output: "[]byte",
|
||||||
|
ContentType: "text/plain",
|
||||||
|
Params: []Param{
|
||||||
|
{Field: "rowcount", Display: "Row Count", Type: "int", Default: "10", Description: "Number of rows"},
|
||||||
|
{Field: "fields", Display: "Fields", Type: "[]Field", Description: "Fields name, function and params"},
|
||||||
|
},
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
co := FixedWidthOptions{}
|
||||||
|
|
||||||
|
rowCount, err := info.GetInt(m, "rowcount")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
co.RowCount = rowCount
|
||||||
|
|
||||||
|
fields, _ := info.GetStringArray(m, "fields")
|
||||||
|
|
||||||
|
// Check to make sure fields has length
|
||||||
|
if len(fields) > 0 {
|
||||||
|
co.Fields = make([]Field, len(fields))
|
||||||
|
for i, f := range fields {
|
||||||
|
// Unmarshal fields string into fields array
|
||||||
|
err = json.Unmarshal([]byte(f), &co.Fields[i])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return nil, errors.New("missing fields")
|
||||||
|
}
|
||||||
|
|
||||||
|
out, err := fixeWidthFunc(f, &co)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return out, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("regex", Info{
|
||||||
|
Display: "Regex",
|
||||||
|
Category: "generate",
|
||||||
|
Description: "Pattern-matching tool used in text processing to search and manipulate strings",
|
||||||
|
Example: "[abcdef]{5} - affec",
|
||||||
|
Output: "string",
|
||||||
|
Params: []Param{
|
||||||
|
{Field: "str", Display: "String", Type: "string", Description: "Regex RE2 syntax string"},
|
||||||
|
},
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
str, err := info.GetString(m, "str")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit the length of the string passed
|
||||||
|
if len(str) > 500 {
|
||||||
|
return nil, errors.New("string length is too large. limit to 500 characters")
|
||||||
|
}
|
||||||
|
|
||||||
|
return regex(f, str), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("map", Info{
|
||||||
|
Display: "Map",
|
||||||
|
Category: "generate",
|
||||||
|
Description: "Data structure that stores key-value pairs",
|
||||||
|
Example: `{
|
||||||
|
"software": 7518355,
|
||||||
|
"that": ["despite", "pack", "whereas", "recently", "there", "anyone", "time", "read"],
|
||||||
|
"use": 683598,
|
||||||
|
"whom": "innovate",
|
||||||
|
"yourselves": 1987784
|
||||||
|
}`,
|
||||||
|
Output: "map[string]any",
|
||||||
|
ContentType: "application/json",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return mapFunc(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,137 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// HackerPhrase will return a random hacker sentence
|
||||||
|
func HackerPhrase() string { return hackerPhrase(GlobalFaker) }
|
||||||
|
|
||||||
|
// HackerPhrase will return a random hacker sentence
|
||||||
|
func (f *Faker) HackerPhrase() string { return hackerPhrase(f) }
|
||||||
|
|
||||||
|
func hackerPhrase(f *Faker) string {
|
||||||
|
genStr, _ := generate(f, getRandValue(f, []string{"hacker", "phrase"}))
|
||||||
|
|
||||||
|
words := strings.Split(genStr, " ")
|
||||||
|
words[0] = strings.ToUpper(words[0][0:1]) + words[0][1:]
|
||||||
|
return strings.Join(words, " ")
|
||||||
|
}
|
||||||
|
|
||||||
|
// HackerAbbreviation will return a random hacker abbreviation
|
||||||
|
func HackerAbbreviation() string { return hackerAbbreviation(GlobalFaker) }
|
||||||
|
|
||||||
|
// HackerAbbreviation will return a random hacker abbreviation
|
||||||
|
func (f *Faker) HackerAbbreviation() string { return hackerAbbreviation(f) }
|
||||||
|
|
||||||
|
func hackerAbbreviation(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"hacker", "abbreviation"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HackerAdjective will return a random hacker adjective
|
||||||
|
func HackerAdjective() string { return hackerAdjective(GlobalFaker) }
|
||||||
|
|
||||||
|
// HackerAdjective will return a random hacker adjective
|
||||||
|
func (f *Faker) HackerAdjective() string { return hackerAdjective(f) }
|
||||||
|
|
||||||
|
func hackerAdjective(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"hacker", "adjective"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HackerNoun will return a random hacker noun
|
||||||
|
func HackerNoun() string { return hackerNoun(GlobalFaker) }
|
||||||
|
|
||||||
|
// HackerNoun will return a random hacker noun
|
||||||
|
func (f *Faker) HackerNoun() string { return hackerNoun(f) }
|
||||||
|
|
||||||
|
func hackerNoun(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"hacker", "noun"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HackerVerb will return a random hacker verb
|
||||||
|
func HackerVerb() string { return hackerVerb(GlobalFaker) }
|
||||||
|
|
||||||
|
// HackerVerb will return a random hacker verb
|
||||||
|
func (f *Faker) HackerVerb() string { return hackerVerb(f) }
|
||||||
|
|
||||||
|
func hackerVerb(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"hacker", "verb"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HackeringVerb will return a random hacker ingverb
|
||||||
|
func HackeringVerb() string { return hackeringVerb(GlobalFaker) }
|
||||||
|
|
||||||
|
// HackeringVerb will return a random hacker ingverb
|
||||||
|
func (f *Faker) HackeringVerb() string { return hackeringVerb(f) }
|
||||||
|
|
||||||
|
func hackeringVerb(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"hacker", "ingverb"})
|
||||||
|
}
|
||||||
|
|
||||||
|
func addHackerLookup() {
|
||||||
|
AddFuncLookup("hackerphrase", Info{
|
||||||
|
Display: "Hacker Phrase",
|
||||||
|
Category: "hacker",
|
||||||
|
Description: "Informal jargon and slang used in the hacking and cybersecurity community",
|
||||||
|
Example: "If we calculate the program, we can get to the AI pixel through the redundant XSS matrix!",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return hackerPhrase(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("hackerabbreviation", Info{
|
||||||
|
Display: "Hacker Abbreviation",
|
||||||
|
Category: "hacker",
|
||||||
|
Description: "Abbreviations and acronyms commonly used in the hacking and cybersecurity community",
|
||||||
|
Example: "ADP",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return hackerAbbreviation(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("hackeradjective", Info{
|
||||||
|
Display: "Hacker Adjective",
|
||||||
|
Category: "hacker",
|
||||||
|
Description: "Adjectives describing terms often associated with hackers and cybersecurity experts",
|
||||||
|
Example: "wireless",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return hackerAdjective(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("hackernoun", Info{
|
||||||
|
Display: "Hacker Noun",
|
||||||
|
Category: "hacker",
|
||||||
|
Description: "Noun representing an element, tool, or concept within the realm of hacking and cybersecurity",
|
||||||
|
Example: "driver",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return hackerNoun(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("hackerverb", Info{
|
||||||
|
Display: "Hacker Verb",
|
||||||
|
Category: "hacker",
|
||||||
|
Description: "Verbs associated with actions and activities in the field of hacking and cybersecurity",
|
||||||
|
Example: "synthesize",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return hackerVerb(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("hackeringverb", Info{
|
||||||
|
Display: "Hackering Verb",
|
||||||
|
Category: "hacker",
|
||||||
|
Description: "Verb describing actions and activities related to hacking, often involving computer systems and security",
|
||||||
|
Example: "connecting",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return hackeringVerb(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,374 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
"reflect"
|
||||||
|
"strings"
|
||||||
|
"unicode"
|
||||||
|
|
||||||
|
"github.com/brianvoe/gofakeit/v7/data"
|
||||||
|
)
|
||||||
|
|
||||||
|
const lowerStr = "abcdefghijklmnopqrstuvwxyz"
|
||||||
|
const upperStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
|
const numericStr = "0123456789"
|
||||||
|
const specialStr = "@#$%&?|!(){}<>=*+-_:;,."
|
||||||
|
const specialSafeStr = "!@.-_*" // https://github.com/1Password/spg/pull/22
|
||||||
|
const spaceStr = " "
|
||||||
|
const allStr = lowerStr + upperStr + numericStr + specialStr + spaceStr
|
||||||
|
const vowels = "aeiou"
|
||||||
|
const hashtag = '#'
|
||||||
|
const questionmark = '?'
|
||||||
|
const dash = '-'
|
||||||
|
const base58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
||||||
|
const minUint = 0
|
||||||
|
const maxUint = ^uint(0)
|
||||||
|
const minInt = -maxInt - 1
|
||||||
|
const maxInt = int(^uint(0) >> 1)
|
||||||
|
const is32bit = ^uint(0)>>32 == 0
|
||||||
|
|
||||||
|
// Check if in lib
|
||||||
|
func dataCheck(dataVal []string) bool {
|
||||||
|
var checkOk bool
|
||||||
|
|
||||||
|
if len(dataVal) == 2 {
|
||||||
|
_, checkOk = data.Data[dataVal[0]]
|
||||||
|
if checkOk {
|
||||||
|
_, checkOk = data.Data[dataVal[0]][dataVal[1]]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return checkOk
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get Random Value
|
||||||
|
func getRandValue(f *Faker, dataVal []string) string {
|
||||||
|
if !dataCheck(dataVal) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return data.Data[dataVal[0]][dataVal[1]][f.IntN(len(data.Data[dataVal[0]][dataVal[1]]))]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace # with numbers
|
||||||
|
func replaceWithNumbers(f *Faker, str string) string {
|
||||||
|
if str == "" {
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
bytestr := []byte(str)
|
||||||
|
for i := 0; i < len(bytestr); i++ {
|
||||||
|
if bytestr[i] == hashtag {
|
||||||
|
bytestr[i] = byte(randDigit(f))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if bytestr[0] == '0' {
|
||||||
|
bytestr[0] = byte(f.IntN(8)+1) + '0'
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(bytestr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace ? with ASCII lowercase letters
|
||||||
|
func replaceWithLetters(f *Faker, str string) string {
|
||||||
|
if str == "" {
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
bytestr := []byte(str)
|
||||||
|
for i := 0; i < len(bytestr); i++ {
|
||||||
|
if bytestr[i] == questionmark {
|
||||||
|
bytestr[i] = byte(randLetter(f))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(bytestr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace ? with ASCII lowercase letters between a and f
|
||||||
|
func replaceWithHexLetters(f *Faker, str string) string {
|
||||||
|
if str == "" {
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
bytestr := []byte(str)
|
||||||
|
for i := 0; i < len(bytestr); i++ {
|
||||||
|
if bytestr[i] == questionmark {
|
||||||
|
bytestr[i] = byte(randHexLetter(f))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(bytestr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate random lowercase ASCII letter
|
||||||
|
func randLetter(f *Faker) rune {
|
||||||
|
allLetters := upperStr + lowerStr
|
||||||
|
return rune(allLetters[f.IntN(len(allLetters))])
|
||||||
|
}
|
||||||
|
|
||||||
|
func randCharacter(f *Faker, s string) string {
|
||||||
|
return string(s[f.Int64()%int64(len(s))])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate random lowercase ASCII letter between a and f
|
||||||
|
func randHexLetter(f *Faker) rune {
|
||||||
|
return rune(byte(f.IntN(6)) + 'a')
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate random ASCII digit
|
||||||
|
func randDigit(f *Faker) rune {
|
||||||
|
return rune(byte(f.IntN(10)) + '0')
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate random integer between min and max
|
||||||
|
func randIntRange(f *Faker, min, max int) int {
|
||||||
|
if min == max {
|
||||||
|
return min
|
||||||
|
}
|
||||||
|
|
||||||
|
if min > max {
|
||||||
|
min, max = max, min // Swap if min is greater than max
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use f.IntN to generate a random number in [0, rangeSize) and shift it into [min, max].
|
||||||
|
return f.IntN(max-min+1) + min
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate random uint between min and max
|
||||||
|
func randUintRange(f *Faker, min, max uint) uint {
|
||||||
|
if min == max {
|
||||||
|
return min // Immediate return if range is zero
|
||||||
|
}
|
||||||
|
|
||||||
|
if min > max {
|
||||||
|
min, max = max, min // Swap if min is greater than max
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use f.UintN to generate a random number in [0, rangeSize) and shift it into [min, max].
|
||||||
|
return f.UintN(max-min+1) + min
|
||||||
|
}
|
||||||
|
|
||||||
|
func toFixed(num float64, precision int) float64 {
|
||||||
|
output := math.Pow(10, float64(precision))
|
||||||
|
return float64(math.Floor(num*output)) / output
|
||||||
|
}
|
||||||
|
|
||||||
|
func equalSliceString(a, b []string) bool {
|
||||||
|
sizeA, sizeB := len(a), len(b)
|
||||||
|
if sizeA != sizeB {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, va := range a {
|
||||||
|
vb := b[i]
|
||||||
|
|
||||||
|
if va != vb {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func equalSliceInt(a, b []int) bool {
|
||||||
|
sizeA, sizeB := len(a), len(b)
|
||||||
|
if sizeA != sizeB {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, va := range a {
|
||||||
|
vb := b[i]
|
||||||
|
|
||||||
|
if va != vb {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func equalSliceInterface(a, b []any) bool {
|
||||||
|
sizeA, sizeB := len(a), len(b)
|
||||||
|
if sizeA != sizeB {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, va := range a {
|
||||||
|
if !reflect.DeepEqual(va, b[i]) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func stringInSlice(a string, list []string) bool {
|
||||||
|
for _, b := range list {
|
||||||
|
if b == a {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func anyToString(a any) string {
|
||||||
|
if a == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// If it's a slice of bytes or struct, unmarshal it into an interface
|
||||||
|
if bytes, ok := a.([]byte); ok {
|
||||||
|
return string(bytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// If it's a struct, map, or slice, convert to JSON
|
||||||
|
switch reflect.TypeOf(a).Kind() {
|
||||||
|
case reflect.Struct, reflect.Map, reflect.Slice:
|
||||||
|
b, err := json.Marshal(a)
|
||||||
|
if err == nil {
|
||||||
|
return string(b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("%v", a)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Title returns a copy of the string s with all Unicode letters that begin words
|
||||||
|
// mapped to their Unicode title case
|
||||||
|
func title(s string) string {
|
||||||
|
// isSeparator reports whether the rune could mark a word boundary
|
||||||
|
isSeparator := func(r rune) bool {
|
||||||
|
// ASCII alphanumerics and underscore are not separators
|
||||||
|
if r <= 0x7F {
|
||||||
|
switch {
|
||||||
|
case '0' <= r && r <= '9':
|
||||||
|
return false
|
||||||
|
case 'a' <= r && r <= 'z':
|
||||||
|
return false
|
||||||
|
case 'A' <= r && r <= 'Z':
|
||||||
|
return false
|
||||||
|
case r == '_':
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Letters and digits are not separators
|
||||||
|
if unicode.IsLetter(r) || unicode.IsDigit(r) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, all we can do for now is treat spaces as separators.
|
||||||
|
return unicode.IsSpace(r)
|
||||||
|
}
|
||||||
|
|
||||||
|
prev := ' '
|
||||||
|
return strings.Map(
|
||||||
|
func(r rune) rune {
|
||||||
|
if isSeparator(prev) {
|
||||||
|
prev = r
|
||||||
|
return unicode.ToTitle(r)
|
||||||
|
}
|
||||||
|
prev = r
|
||||||
|
return r
|
||||||
|
},
|
||||||
|
s)
|
||||||
|
}
|
||||||
|
|
||||||
|
func funcLookupSplit(str string) ([]string, error) {
|
||||||
|
out := []string{}
|
||||||
|
for str != "" {
|
||||||
|
if strings.HasPrefix(str, "[") {
|
||||||
|
startIndex := strings.Index(str, "[")
|
||||||
|
endIndex := strings.Index(str, "]")
|
||||||
|
if endIndex == -1 {
|
||||||
|
return nil, fmt.Errorf("invalid lookup split missing ending ] bracket")
|
||||||
|
}
|
||||||
|
|
||||||
|
val := str[(startIndex) : endIndex+1]
|
||||||
|
out = append(out, strings.TrimSpace(val))
|
||||||
|
str = strings.Replace(str, val, "", 1)
|
||||||
|
|
||||||
|
// Trim off comma if it has it
|
||||||
|
if strings.HasPrefix(str, ",") {
|
||||||
|
str = strings.Replace(str, ",", "", 1)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
strSplit := strings.SplitN(str, ",", 2)
|
||||||
|
strSplitLen := len(strSplit)
|
||||||
|
if strSplitLen >= 1 {
|
||||||
|
out = append(out, strings.TrimSpace(strSplit[0]))
|
||||||
|
}
|
||||||
|
if strSplitLen >= 2 {
|
||||||
|
str = strSplit[1]
|
||||||
|
} else {
|
||||||
|
str = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Used for parsing the tag in a struct
|
||||||
|
func parseNameAndParamsFromTag(tag string) (string, string) {
|
||||||
|
// Trim the curly on the beginning and end
|
||||||
|
tag = strings.TrimLeft(tag, "{")
|
||||||
|
tag = strings.TrimRight(tag, "}")
|
||||||
|
// Check if has params separated by :
|
||||||
|
fNameSplit := strings.SplitN(tag, ":", 2)
|
||||||
|
fName := ""
|
||||||
|
fParams := ""
|
||||||
|
if len(fNameSplit) >= 1 {
|
||||||
|
fName = fNameSplit[0]
|
||||||
|
}
|
||||||
|
if len(fNameSplit) >= 2 {
|
||||||
|
fParams = fNameSplit[1]
|
||||||
|
}
|
||||||
|
return fName, fParams
|
||||||
|
}
|
||||||
|
|
||||||
|
// Used for parsing map params
|
||||||
|
func parseMapParams(info *Info, fParams string) (*MapParams, error) {
|
||||||
|
// Get parameters, make sure params and the split both have values
|
||||||
|
mapParams := NewMapParams()
|
||||||
|
paramsLen := len(info.Params)
|
||||||
|
|
||||||
|
// If just one param and its a string simply just pass it
|
||||||
|
if paramsLen == 1 && info.Params[0].Type == "string" {
|
||||||
|
mapParams.Add(info.Params[0].Field, fParams)
|
||||||
|
} else if paramsLen > 0 && fParams != "" {
|
||||||
|
splitVals, err := funcLookupSplit(fParams)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mapParams, err = addSplitValsToMapParams(splitVals, info, mapParams)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If mapParams doesnt have a size then return nil
|
||||||
|
if mapParams.Size() == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return mapParams, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Used for splitting the values
|
||||||
|
func addSplitValsToMapParams(splitVals []string, info *Info, mapParams *MapParams) (*MapParams, error) {
|
||||||
|
for ii := 0; ii < len(splitVals); ii++ {
|
||||||
|
if len(info.Params)-1 >= ii {
|
||||||
|
if strings.HasPrefix(splitVals[ii], "[") {
|
||||||
|
lookupSplits, err := funcLookupSplit(strings.TrimRight(strings.TrimLeft(splitVals[ii], "["), "]"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, v := range lookupSplits {
|
||||||
|
mapParams.Add(info.Params[ii].Field, v)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mapParams.Add(info.Params[ii].Field, splitVals[ii])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mapParams, nil
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,130 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
// HipsterWord will return a single hipster word
|
||||||
|
func HipsterWord() string { return hipsterWord(GlobalFaker) }
|
||||||
|
|
||||||
|
// HipsterWord will return a single hipster word
|
||||||
|
func (f *Faker) HipsterWord() string { return hipsterWord(f) }
|
||||||
|
|
||||||
|
func hipsterWord(f *Faker) string { return getRandValue(f, []string{"hipster", "word"}) }
|
||||||
|
|
||||||
|
// HipsterSentence will generate a random sentence
|
||||||
|
func HipsterSentence(wordCount int) string { return hipsterSentence(GlobalFaker, wordCount) }
|
||||||
|
|
||||||
|
// HipsterSentence will generate a random sentence
|
||||||
|
func (f *Faker) HipsterSentence(wordCount int) string { return hipsterSentence(f, wordCount) }
|
||||||
|
|
||||||
|
func hipsterSentence(f *Faker, wordCount int) string {
|
||||||
|
return sentenceGen(f, wordCount, hipsterWord)
|
||||||
|
}
|
||||||
|
|
||||||
|
// HipsterParagraph will generate a random paragraphGenerator
|
||||||
|
// Set Paragraph Count
|
||||||
|
// Set Sentence Count
|
||||||
|
// Set Word Count
|
||||||
|
// Set Paragraph Separator
|
||||||
|
func HipsterParagraph(paragraphCount int, sentenceCount int, wordCount int, separator string) string {
|
||||||
|
return hipsterParagraph(GlobalFaker, paragraphCount, sentenceCount, wordCount, separator)
|
||||||
|
}
|
||||||
|
|
||||||
|
// HipsterParagraph will generate a random paragraphGenerator
|
||||||
|
// Set Paragraph Count
|
||||||
|
// Set Sentence Count
|
||||||
|
// Set Word Count
|
||||||
|
// Set Paragraph Separator
|
||||||
|
func (f *Faker) HipsterParagraph(paragraphCount int, sentenceCount int, wordCount int, separator string) string {
|
||||||
|
return hipsterParagraph(f, paragraphCount, sentenceCount, wordCount, separator)
|
||||||
|
}
|
||||||
|
|
||||||
|
func hipsterParagraph(f *Faker, paragraphCount int, sentenceCount int, wordCount int, separator string) string {
|
||||||
|
return paragraphGen(f, paragrapOptions{paragraphCount, sentenceCount, wordCount, separator}, hipsterSentence)
|
||||||
|
}
|
||||||
|
|
||||||
|
func addHipsterLookup() {
|
||||||
|
AddFuncLookup("hipsterword", Info{
|
||||||
|
Display: "Hipster Word",
|
||||||
|
Category: "hipster",
|
||||||
|
Description: "Trendy and unconventional vocabulary used by hipsters to express unique cultural preferences",
|
||||||
|
Example: "microdosing",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return hipsterWord(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("hipstersentence", Info{
|
||||||
|
Display: "Hipster Sentence",
|
||||||
|
Category: "hipster",
|
||||||
|
Description: "Sentence showcasing the use of trendy and unconventional vocabulary associated with hipster culture",
|
||||||
|
Example: "Microdosing roof chia echo pickled.",
|
||||||
|
Output: "string",
|
||||||
|
Params: []Param{
|
||||||
|
{Field: "wordcount", Display: "Word Count", Type: "int", Default: "5", Description: "Number of words in a sentence"},
|
||||||
|
},
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
wordCount, err := info.GetInt(m, "wordcount")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if wordCount <= 0 || wordCount > 50 {
|
||||||
|
return nil, errors.New("invalid word count, must be greater than 0, less than 50")
|
||||||
|
}
|
||||||
|
|
||||||
|
return hipsterSentence(f, wordCount), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("hipsterparagraph", Info{
|
||||||
|
Display: "Hipster Paragraph",
|
||||||
|
Category: "hipster",
|
||||||
|
Description: "Paragraph showcasing the use of trendy and unconventional vocabulary associated with hipster culture",
|
||||||
|
Example: `Microdosing roof chia echo pickled meditation cold-pressed raw denim fingerstache normcore sriracha pork belly. Wolf try-hard pop-up blog tilde hashtag health butcher waistcoat paleo portland vinegar. Microdosing sartorial blue bottle slow-carb freegan five dollar toast you probably haven't heard of them asymmetrical chia farm-to-table narwhal banjo. Gluten-free blog authentic literally synth vinyl meh ethical health fixie banh mi Yuccie. Try-hard drinking squid seitan cray VHS echo chillwave hammock kombucha food truck sustainable.
|
||||||
|
|
||||||
|
Pug bushwick hella tote bag cliche direct trade waistcoat yr waistcoat knausgaard pour-over master. Pitchfork jean shorts franzen flexitarian distillery hella meggings austin knausgaard crucifix wolf heirloom. Crucifix food truck you probably haven't heard of them trust fund fixie gentrify pitchfork stumptown mlkshk umami chambray blue bottle. 3 wolf moon swag +1 biodiesel knausgaard semiotics taxidermy meh artisan hoodie +1 blue bottle. Fashion axe forage mixtape Thundercats pork belly whatever 90's beard selfies chambray cred mlkshk.
|
||||||
|
|
||||||
|
Shabby chic typewriter VHS readymade lo-fi bitters PBR&B gentrify lomo raw denim freegan put a bird on it. Raw denim cliche dreamcatcher pug fixie park trust fund migas fingerstache sriracha +1 mustache. Tilde shoreditch kickstarter franzen dreamcatcher green juice mustache neutra polaroid stumptown organic schlitz. Flexitarian ramps chicharrones kogi lo-fi mustache tilde forage street church-key williamsburg taxidermy. Chia mustache plaid mumblecore squid slow-carb disrupt Thundercats goth shoreditch master direct trade.`,
|
||||||
|
Output: "string",
|
||||||
|
Params: []Param{
|
||||||
|
{Field: "paragraphcount", Display: "Paragraph Count", Type: "int", Default: "2", Description: "Number of paragraphs"},
|
||||||
|
{Field: "sentencecount", Display: "Sentence Count", Type: "int", Default: "2", Description: "Number of sentences in a paragraph"},
|
||||||
|
{Field: "wordcount", Display: "Word Count", Type: "int", Default: "5", Description: "Number of words in a sentence"},
|
||||||
|
{Field: "paragraphseparator", Display: "Paragraph Separator", Type: "string", Default: "<br />", Description: "String value to add between paragraphs"},
|
||||||
|
},
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
paragraphCount, err := info.GetInt(m, "paragraphcount")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if paragraphCount <= 0 || paragraphCount > 20 {
|
||||||
|
return nil, errors.New("invalid paragraph count, must be greater than 0, less than 20")
|
||||||
|
}
|
||||||
|
|
||||||
|
sentenceCount, err := info.GetInt(m, "sentencecount")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if sentenceCount <= 0 || sentenceCount > 20 {
|
||||||
|
return nil, errors.New("invalid sentence count, must be greater than 0, less than 20")
|
||||||
|
}
|
||||||
|
|
||||||
|
wordCount, err := info.GetInt(m, "wordcount")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if wordCount <= 0 || wordCount > 50 {
|
||||||
|
return nil, errors.New("invalid word count, must be greater than 0, less than 50")
|
||||||
|
}
|
||||||
|
|
||||||
|
paragraphSeparator, err := info.GetString(m, "paragraphseparator")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return hipsterParagraph(f, paragraphCount, sentenceCount, wordCount, paragraphSeparator), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,174 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/brianvoe/gofakeit/v7/data"
|
||||||
|
)
|
||||||
|
|
||||||
|
// InputName will return a random input field name
|
||||||
|
func InputName() string {
|
||||||
|
return inputName(GlobalFaker)
|
||||||
|
}
|
||||||
|
|
||||||
|
// InputName will return a random input field name
|
||||||
|
func (f *Faker) InputName() string {
|
||||||
|
return inputName(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func inputName(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"html", "input_name"})
|
||||||
|
}
|
||||||
|
|
||||||
|
type SVGOptions struct {
|
||||||
|
Height int
|
||||||
|
Width int
|
||||||
|
Type string
|
||||||
|
Colors []string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate a random svg generator
|
||||||
|
func Svg(options *SVGOptions) string { return svg(GlobalFaker, options) }
|
||||||
|
|
||||||
|
// Generate a random svg generator
|
||||||
|
func (f *Faker) Svg(options *SVGOptions) string { return svg(f, options) }
|
||||||
|
|
||||||
|
func svg(f *Faker, options *SVGOptions) string {
|
||||||
|
// If options is nil, set it to empty struct
|
||||||
|
if options == nil {
|
||||||
|
options = &SVGOptions{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If options height and weight is not set, set it to random number between 100 and 500
|
||||||
|
if options.Width == 0 {
|
||||||
|
options.Width = number(f, 100, 500)
|
||||||
|
}
|
||||||
|
widthStr := strconv.Itoa(options.Width)
|
||||||
|
if options.Height == 0 {
|
||||||
|
options.Height = number(f, 100, 500)
|
||||||
|
}
|
||||||
|
heightStr := strconv.Itoa(options.Height)
|
||||||
|
|
||||||
|
// Check if type is set, if not set to random type
|
||||||
|
if options.Type == "" {
|
||||||
|
options.Type = randomString(f, data.GetSubData("html", "svg"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the colors are not set, set it to a set of nice colors
|
||||||
|
if len(options.Colors) == 0 {
|
||||||
|
options.Colors = niceColors(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start svg string
|
||||||
|
svgStr := `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ` + widthStr + ` ` + heightStr + `" width="` + widthStr + `" height="` + heightStr + `">`
|
||||||
|
|
||||||
|
// Add a rect for the background
|
||||||
|
svgStr += `<rect x="0" y="0" width="100%" height="100%" fill="` + randomString(f, options.Colors) + `" />`
|
||||||
|
|
||||||
|
// Add a random number of shapes
|
||||||
|
for i := 0; i < number(f, 10, 20); i++ {
|
||||||
|
// Add a random shape
|
||||||
|
switch options.Type {
|
||||||
|
case "rect":
|
||||||
|
svgStr += `<rect x="` + strconv.Itoa(number(f, 0, options.Width)) + `" y="` + strconv.Itoa(number(f, 0, options.Height)) + `" width="` + strconv.Itoa(number(f, 0, options.Width)) + `" height="` + strconv.Itoa(number(f, 0, options.Height)) + `" fill="` + randomString(f, options.Colors) + `" />`
|
||||||
|
case "circle":
|
||||||
|
svgStr += `<circle cx="` + strconv.Itoa(number(f, 0, options.Width)) + `" cy="` + strconv.Itoa(number(f, 0, options.Height)) + `" r="` + strconv.Itoa(number(f, 0, options.Width)) + `" fill="` + randomString(f, options.Colors) + `" />`
|
||||||
|
case "ellipse":
|
||||||
|
svgStr += `<ellipse cx="` + strconv.Itoa(number(f, 0, options.Width)) + `" cy="` + strconv.Itoa(number(f, 0, options.Height)) + `" rx="` + strconv.Itoa(number(f, 0, options.Width)) + `" ry="` + strconv.Itoa(number(f, 0, options.Height)) + `" fill="` + randomString(f, options.Colors) + `" />`
|
||||||
|
case "line":
|
||||||
|
svgStr += `<line x1="` + strconv.Itoa(number(f, 0, options.Width)) + `" y1="` + strconv.Itoa(number(f, 0, options.Height)) + `" x2="` + strconv.Itoa(number(f, 0, options.Width)) + `" y2="` + strconv.Itoa(number(f, 0, options.Height)) + `" stroke="` + randomString(f, options.Colors) + `" />`
|
||||||
|
case "polyline":
|
||||||
|
svgStr += `<polyline points="` + strconv.Itoa(number(f, 0, options.Width)) + `,` + strconv.Itoa(number(f, 0, options.Height)) + ` ` + strconv.Itoa(number(f, 0, options.Width)) + `,` + strconv.Itoa(number(f, 0, options.Height)) + ` ` + strconv.Itoa(number(f, 0, options.Width)) + `,` + strconv.Itoa(number(f, 0, options.Height)) + `" fill="` + randomString(f, options.Colors) + `" />`
|
||||||
|
case "polygon":
|
||||||
|
svgStr += `<polygon points="` + strconv.Itoa(number(f, 0, options.Width)) + `,` + strconv.Itoa(number(f, 0, options.Height)) + ` ` + strconv.Itoa(number(f, 0, options.Width)) + `,` + strconv.Itoa(number(f, 0, options.Height)) + ` ` + strconv.Itoa(number(f, 0, options.Width)) + `,` + strconv.Itoa(number(f, 0, options.Height)) + `" fill="` + randomString(f, options.Colors) + `" />`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// End svg string
|
||||||
|
svgStr += `</svg>`
|
||||||
|
|
||||||
|
return svgStr
|
||||||
|
}
|
||||||
|
|
||||||
|
func addHtmlLookup() {
|
||||||
|
AddFuncLookup("inputname", Info{
|
||||||
|
Display: "Input Name",
|
||||||
|
Category: "html",
|
||||||
|
Description: "Attribute used to define the name of an input element in web forms",
|
||||||
|
Example: "first_name",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return inputName(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("svg", Info{
|
||||||
|
Display: "Image SVG",
|
||||||
|
Category: "html",
|
||||||
|
Description: "Scalable Vector Graphics used to display vector images in web content",
|
||||||
|
Example: `<svg width="369" height="289">
|
||||||
|
<rect fill="#4f2958" />
|
||||||
|
<polygon points="382,87 418,212 415,110" fill="#fffbb7" />
|
||||||
|
</svg>`,
|
||||||
|
Output: "string",
|
||||||
|
ContentType: "image/svg+xml",
|
||||||
|
Params: []Param{
|
||||||
|
{Field: "width", Display: "Width", Type: "int", Default: "500", Description: "Width in px"},
|
||||||
|
{Field: "height", Display: "Height", Type: "int", Default: "500", Description: "Height in px"},
|
||||||
|
{Field: "type", Display: "Type", Type: "string", Optional: true, Options: data.GetSubData("html", "svg"), Description: "Sub child element type"},
|
||||||
|
{Field: "colors", Display: "Colors", Type: "[]string", Optional: true, Description: "Hex or RGB array of colors to use"},
|
||||||
|
},
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
// Setup new options
|
||||||
|
options := SVGOptions{}
|
||||||
|
var err error
|
||||||
|
|
||||||
|
options.Width, err = info.GetInt(m, "width")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if options.Width < 10 || options.Width >= 1000 {
|
||||||
|
return nil, errors.New("invalid image width, must be greater than 10, less than 1000")
|
||||||
|
}
|
||||||
|
|
||||||
|
options.Height, err = info.GetInt(m, "height")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if options.Height < 10 || options.Height >= 1000 {
|
||||||
|
return nil, errors.New("invalid image height, must be greater than 10, less than 1000")
|
||||||
|
}
|
||||||
|
|
||||||
|
options.Type, err = info.GetString(m, "type")
|
||||||
|
svgData := data.GetSubData("html", "svg")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// If type is empty, set with random type
|
||||||
|
if options.Type == "" {
|
||||||
|
options.Type = randomString(f, svgData)
|
||||||
|
}
|
||||||
|
|
||||||
|
// If not in date html svg type array, return error
|
||||||
|
if !stringInSlice(options.Type, svgData) {
|
||||||
|
return nil, errors.New("invalid svg type, must be one of " + strings.Join(svgData, ","))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get colors
|
||||||
|
options.Colors, err = info.GetStringArray(m, "colors")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// If colors is empty, set with random colors
|
||||||
|
if len(options.Colors) == 0 {
|
||||||
|
options.Colors = niceColors(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
return svg(f, &options), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,122 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"errors"
|
||||||
|
img "image"
|
||||||
|
imgCol "image/color"
|
||||||
|
"image/jpeg"
|
||||||
|
"image/png"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Image generates a random rgba image
|
||||||
|
func Image(width int, height int) *img.RGBA { return image(GlobalFaker, width, height) }
|
||||||
|
|
||||||
|
// Image generates a random rgba image
|
||||||
|
func (f *Faker) Image(width int, height int) *img.RGBA { return image(f, width, height) }
|
||||||
|
|
||||||
|
func image(f *Faker, width int, height int) *img.RGBA {
|
||||||
|
upLeft := img.Point{0, 0}
|
||||||
|
lowRight := img.Point{width, height}
|
||||||
|
|
||||||
|
img := img.NewRGBA(img.Rectangle{upLeft, lowRight})
|
||||||
|
|
||||||
|
// Set color for each pixel
|
||||||
|
for x := 0; x < width; x++ {
|
||||||
|
for y := 0; y < height; y++ {
|
||||||
|
img.Set(x, y, imgCol.RGBA{uint8(number(f, 0, 255)), uint8(number(f, 0, 255)), uint8(number(f, 0, 255)), 0xff})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return img
|
||||||
|
}
|
||||||
|
|
||||||
|
// ImageJpeg generates a random rgba jpeg image
|
||||||
|
func ImageJpeg(width int, height int) []byte { return imageJpeg(GlobalFaker, width, height) }
|
||||||
|
|
||||||
|
// ImageJpeg generates a random rgba jpeg image
|
||||||
|
func (f *Faker) ImageJpeg(width int, height int) []byte { return imageJpeg(f, width, height) }
|
||||||
|
|
||||||
|
func imageJpeg(f *Faker, width int, height int) []byte {
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
jpeg.Encode(buf, image(f, width, height), nil)
|
||||||
|
return buf.Bytes()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ImagePng generates a random rgba png image
|
||||||
|
func ImagePng(width int, height int) []byte { return imagePng(GlobalFaker, width, height) }
|
||||||
|
|
||||||
|
// ImagePng generates a random rgba png image
|
||||||
|
func (f *Faker) ImagePng(width int, height int) []byte { return imagePng(f, width, height) }
|
||||||
|
|
||||||
|
func imagePng(f *Faker, width int, height int) []byte {
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
png.Encode(buf, image(f, width, height))
|
||||||
|
return buf.Bytes()
|
||||||
|
}
|
||||||
|
|
||||||
|
func addImageLookup() {
|
||||||
|
AddFuncLookup("imagejpeg", Info{
|
||||||
|
Display: "Image JPEG",
|
||||||
|
Category: "image",
|
||||||
|
Description: "Image file format known for its efficient compression and compatibility",
|
||||||
|
Example: "file.jpeg - bytes",
|
||||||
|
Output: "[]byte",
|
||||||
|
ContentType: "image/jpeg",
|
||||||
|
Params: []Param{
|
||||||
|
{Field: "width", Display: "Width", Type: "int", Default: "500", Description: "Image width in px"},
|
||||||
|
{Field: "height", Display: "Height", Type: "int", Default: "500", Description: "Image height in px"},
|
||||||
|
},
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
width, err := info.GetInt(m, "width")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if width < 10 || width >= 1000 {
|
||||||
|
return nil, errors.New("invalid image width, must be greater than 10, less than 1000")
|
||||||
|
}
|
||||||
|
|
||||||
|
height, err := info.GetInt(m, "height")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if height < 10 || height >= 1000 {
|
||||||
|
return nil, errors.New("invalid image height, must be greater than 10, less than 1000")
|
||||||
|
}
|
||||||
|
|
||||||
|
return imageJpeg(f, width, height), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("imagepng", Info{
|
||||||
|
Display: "Image PNG",
|
||||||
|
Category: "image",
|
||||||
|
Description: "Image file format known for its lossless compression and support for transparency",
|
||||||
|
Example: "file.png - bytes",
|
||||||
|
Output: "[]byte",
|
||||||
|
ContentType: "image/png",
|
||||||
|
Params: []Param{
|
||||||
|
{Field: "width", Display: "Width", Type: "int", Default: "500", Description: "Image width in px"},
|
||||||
|
{Field: "height", Display: "Height", Type: "int", Default: "500", Description: "Image height in px"},
|
||||||
|
},
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
width, err := info.GetInt(m, "width")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if width < 10 || width >= 1000 {
|
||||||
|
return nil, errors.New("invalid image width, must be greater than 10, less than 1000")
|
||||||
|
}
|
||||||
|
|
||||||
|
height, err := info.GetInt(m, "height")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if height < 10 || height >= 1000 {
|
||||||
|
return nil, errors.New("invalid image height, must be greater than 10, less than 1000")
|
||||||
|
}
|
||||||
|
|
||||||
|
return imagePng(f, width, height), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,440 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/brianvoe/gofakeit/v7/data"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DomainName will generate a random url domain name
|
||||||
|
func DomainName() string { return domainName(GlobalFaker) }
|
||||||
|
|
||||||
|
// DomainName will generate a random url domain name
|
||||||
|
func (f *Faker) DomainName() string { return domainName(f) }
|
||||||
|
|
||||||
|
func domainName(f *Faker) string {
|
||||||
|
name := strings.Replace(strings.ToLower(jobDescriptor(f)+bs(f)), " ", "", -1)
|
||||||
|
|
||||||
|
return fmt.Sprintf("%s.%s", name, domainSuffix(f))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DomainSuffix will generate a random domain suffix
|
||||||
|
func DomainSuffix() string { return domainSuffix(GlobalFaker) }
|
||||||
|
|
||||||
|
// DomainSuffix will generate a random domain suffix
|
||||||
|
func (f *Faker) DomainSuffix() string { return domainSuffix(f) }
|
||||||
|
|
||||||
|
func domainSuffix(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"internet", "domain_suffix"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// URL will generate a random url string
|
||||||
|
func URL() string { return url(GlobalFaker) }
|
||||||
|
|
||||||
|
// URL will generate a random url string
|
||||||
|
func (f *Faker) URL() string { return url(f) }
|
||||||
|
|
||||||
|
func url(f *Faker) string {
|
||||||
|
// Slugs
|
||||||
|
num := number(f, 1, 4)
|
||||||
|
slug := make([]string, num)
|
||||||
|
for i := 0; i < num; i++ {
|
||||||
|
slug[i] = bs(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
scheme := randomString(f, []string{"https", "http"})
|
||||||
|
path := strings.ToLower(strings.Join(slug, "/"))
|
||||||
|
|
||||||
|
url := fmt.Sprintf("%s://www.%s/%s", scheme, domainName(f), path)
|
||||||
|
url = strings.Replace(url, " ", "", -1)
|
||||||
|
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
|
||||||
|
// HTTPMethod will generate a random http method
|
||||||
|
func HTTPMethod() string { return httpMethod(GlobalFaker) }
|
||||||
|
|
||||||
|
// HTTPMethod will generate a random http method
|
||||||
|
func (f *Faker) HTTPMethod() string { return httpMethod(f) }
|
||||||
|
|
||||||
|
func httpMethod(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"internet", "http_method"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IPv4Address will generate a random version 4 ip address
|
||||||
|
func IPv4Address() string { return ipv4Address(GlobalFaker) }
|
||||||
|
|
||||||
|
// IPv4Address will generate a random version 4 ip address
|
||||||
|
func (f *Faker) IPv4Address() string { return ipv4Address(f) }
|
||||||
|
|
||||||
|
func ipv4Address(f *Faker) string {
|
||||||
|
num := func() int { return f.IntN(256) }
|
||||||
|
|
||||||
|
return fmt.Sprintf("%d.%d.%d.%d", num(), num(), num(), num())
|
||||||
|
}
|
||||||
|
|
||||||
|
// IPv6Address will generate a random version 6 ip address
|
||||||
|
func IPv6Address() string { return ipv6Address(GlobalFaker) }
|
||||||
|
|
||||||
|
// IPv6Address will generate a random version 6 ip address
|
||||||
|
func (f *Faker) IPv6Address() string { return ipv6Address(f) }
|
||||||
|
|
||||||
|
func ipv6Address(f *Faker) string {
|
||||||
|
num := func() int { return f.IntN(65536) }
|
||||||
|
|
||||||
|
return fmt.Sprintf("%x:%x:%x:%x:%x:%x:%x:%x", num(), num(), num(), num(), num(), num(), num(), num())
|
||||||
|
}
|
||||||
|
|
||||||
|
// MacAddress will generate a random mac address
|
||||||
|
func MacAddress() string { return macAddress(GlobalFaker) }
|
||||||
|
|
||||||
|
// MacAddress will generate a random mac address
|
||||||
|
func (f *Faker) MacAddress() string { return macAddress(f) }
|
||||||
|
|
||||||
|
func macAddress(f *Faker) string {
|
||||||
|
num := 255
|
||||||
|
|
||||||
|
return fmt.Sprintf("%02x:%02x:%02x:%02x:%02x:%02x", f.IntN(num), f.IntN(num), f.IntN(num), f.IntN(num), f.IntN(num), f.IntN(num))
|
||||||
|
}
|
||||||
|
|
||||||
|
// HTTPStatusCode will generate a random status code
|
||||||
|
func HTTPStatusCode() int { return httpStatusCode(GlobalFaker) }
|
||||||
|
|
||||||
|
// HTTPStatusCode will generate a random status code
|
||||||
|
func (f *Faker) HTTPStatusCode() int { return httpStatusCode(f) }
|
||||||
|
|
||||||
|
func httpStatusCode(f *Faker) int {
|
||||||
|
randInt, _ := strconv.Atoi(getRandValue(f, []string{"internet", "http_status_general"}))
|
||||||
|
return randInt
|
||||||
|
}
|
||||||
|
|
||||||
|
// HTTPStatusCodeSimple will generate a random simple status code
|
||||||
|
func HTTPStatusCodeSimple() int { return httpStatusCodeSimple(GlobalFaker) }
|
||||||
|
|
||||||
|
// HTTPStatusCodeSimple will generate a random simple status code
|
||||||
|
func (f *Faker) HTTPStatusCodeSimple() int { return httpStatusCodeSimple(f) }
|
||||||
|
|
||||||
|
func httpStatusCodeSimple(f *Faker) int {
|
||||||
|
randInt, _ := strconv.Atoi(getRandValue(f, []string{"internet", "http_status_simple"}))
|
||||||
|
return randInt
|
||||||
|
}
|
||||||
|
|
||||||
|
// LogLevel will generate a random log level
|
||||||
|
// See data/LogLevels for list of available levels
|
||||||
|
func LogLevel(logType string) string { return logLevel(GlobalFaker, logType) }
|
||||||
|
|
||||||
|
// LogLevel will generate a random log level
|
||||||
|
// See data/LogLevels for list of available levels
|
||||||
|
func (f *Faker) LogLevel(logType string) string { return logLevel(f, logType) }
|
||||||
|
|
||||||
|
func logLevel(f *Faker, logType string) string {
|
||||||
|
if _, ok := data.LogLevels[logType]; ok {
|
||||||
|
return getRandValue(f, []string{"log_level", logType})
|
||||||
|
}
|
||||||
|
|
||||||
|
return getRandValue(f, []string{"log_level", "general"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserAgent will generate a random broswer user agent
|
||||||
|
func UserAgent() string { return userAgent(GlobalFaker) }
|
||||||
|
|
||||||
|
// UserAgent will generate a random broswer user agent
|
||||||
|
func (f *Faker) UserAgent() string { return userAgent(f) }
|
||||||
|
|
||||||
|
func userAgent(f *Faker) string {
|
||||||
|
randNum := randIntRange(f, 0, 4)
|
||||||
|
switch randNum {
|
||||||
|
case 0:
|
||||||
|
return chromeUserAgent(f)
|
||||||
|
case 1:
|
||||||
|
return firefoxUserAgent(f)
|
||||||
|
case 2:
|
||||||
|
return safariUserAgent(f)
|
||||||
|
case 3:
|
||||||
|
return operaUserAgent(f)
|
||||||
|
default:
|
||||||
|
return chromeUserAgent(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChromeUserAgent will generate a random chrome browser user agent string
|
||||||
|
func ChromeUserAgent() string { return chromeUserAgent(GlobalFaker) }
|
||||||
|
|
||||||
|
// ChromeUserAgent will generate a random chrome browser user agent string
|
||||||
|
func (f *Faker) ChromeUserAgent() string { return chromeUserAgent(f) }
|
||||||
|
|
||||||
|
func chromeUserAgent(f *Faker) string {
|
||||||
|
randNum1 := strconv.Itoa(randIntRange(f, 531, 536)) + strconv.Itoa(randIntRange(f, 0, 2))
|
||||||
|
randNum2 := strconv.Itoa(randIntRange(f, 36, 40))
|
||||||
|
randNum3 := strconv.Itoa(randIntRange(f, 800, 899))
|
||||||
|
return "Mozilla/5.0 " + "(" + randomPlatform(f) + ") AppleWebKit/" + randNum1 + " (KHTML, like Gecko) Chrome/" + randNum2 + ".0." + randNum3 + ".0 Mobile Safari/" + randNum1
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirefoxUserAgent will generate a random firefox broswer user agent string
|
||||||
|
func FirefoxUserAgent() string { return firefoxUserAgent(GlobalFaker) }
|
||||||
|
|
||||||
|
// FirefoxUserAgent will generate a random firefox broswer user agent string
|
||||||
|
func (f *Faker) FirefoxUserAgent() string { return firefoxUserAgent(f) }
|
||||||
|
|
||||||
|
func firefoxUserAgent(f *Faker) string {
|
||||||
|
ver := "Gecko/" + date(f).Format("2006-01-02") + " Firefox/" + strconv.Itoa(randIntRange(f, 35, 37)) + ".0"
|
||||||
|
platforms := []string{
|
||||||
|
"(" + windowsPlatformToken(f) + "; " + "en-US" + "; rv:1.9." + strconv.Itoa(randIntRange(f, 0, 3)) + ".20) " + ver,
|
||||||
|
"(" + linuxPlatformToken(f) + "; rv:" + strconv.Itoa(randIntRange(f, 5, 8)) + ".0) " + ver,
|
||||||
|
"(" + macPlatformToken(f) + " rv:" + strconv.Itoa(randIntRange(f, 2, 7)) + ".0) " + ver,
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Mozilla/5.0 " + randomString(f, platforms)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SafariUserAgent will generate a random safari browser user agent string
|
||||||
|
func SafariUserAgent() string { return safariUserAgent(GlobalFaker) }
|
||||||
|
|
||||||
|
// SafariUserAgent will generate a random safari browser user agent string
|
||||||
|
func (f *Faker) SafariUserAgent() string { return safariUserAgent(f) }
|
||||||
|
|
||||||
|
func safariUserAgent(f *Faker) string {
|
||||||
|
randNum := strconv.Itoa(randIntRange(f, 531, 536)) + "." + strconv.Itoa(randIntRange(f, 1, 51)) + "." + strconv.Itoa(randIntRange(f, 1, 8))
|
||||||
|
ver := strconv.Itoa(randIntRange(f, 4, 6)) + "." + strconv.Itoa(randIntRange(f, 0, 2))
|
||||||
|
|
||||||
|
mobileDevices := []string{
|
||||||
|
"iPhone; CPU iPhone OS",
|
||||||
|
"iPad; CPU OS",
|
||||||
|
}
|
||||||
|
|
||||||
|
platforms := []string{
|
||||||
|
"(Windows; U; " + windowsPlatformToken(f) + ") AppleWebKit/" + randNum + " (KHTML, like Gecko) Version/" + ver + " Safari/" + randNum,
|
||||||
|
"(" + macPlatformToken(f) + " rv:" + strconv.Itoa(randIntRange(f, 4, 7)) + ".0; en-US) AppleWebKit/" + randNum + " (KHTML, like Gecko) Version/" + ver + " Safari/" + randNum,
|
||||||
|
"(" + randomString(f, mobileDevices) + " " + strconv.Itoa(randIntRange(f, 7, 9)) + "_" + strconv.Itoa(randIntRange(f, 0, 3)) + "_" + strconv.Itoa(randIntRange(f, 1, 3)) + " like Mac OS X; " + "en-US" + ") AppleWebKit/" + randNum + " (KHTML, like Gecko) Version/" + strconv.Itoa(randIntRange(f, 3, 5)) + ".0.5 Mobile/8B" + strconv.Itoa(randIntRange(f, 111, 120)) + " Safari/6" + randNum,
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Mozilla/5.0 " + randomString(f, platforms)
|
||||||
|
}
|
||||||
|
|
||||||
|
// OperaUserAgent will generate a random opera browser user agent string
|
||||||
|
func OperaUserAgent() string { return operaUserAgent(GlobalFaker) }
|
||||||
|
|
||||||
|
// OperaUserAgent will generate a random opera browser user agent string
|
||||||
|
func (f *Faker) OperaUserAgent() string { return operaUserAgent(f) }
|
||||||
|
|
||||||
|
func operaUserAgent(f *Faker) string {
|
||||||
|
platform := "(" + randomPlatform(f) + "; en-US) Presto/2." + strconv.Itoa(randIntRange(f, 8, 13)) + "." + strconv.Itoa(randIntRange(f, 160, 355)) + " Version/" + strconv.Itoa(randIntRange(f, 10, 13)) + ".00"
|
||||||
|
|
||||||
|
return "Opera/" + strconv.Itoa(randIntRange(f, 8, 10)) + "." + strconv.Itoa(randIntRange(f, 10, 99)) + " " + platform
|
||||||
|
}
|
||||||
|
|
||||||
|
// linuxPlatformToken will generate a random linux platform
|
||||||
|
func linuxPlatformToken(f *Faker) string {
|
||||||
|
return "X11; Linux " + getRandValue(f, []string{"computer", "linux_processor"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// macPlatformToken will generate a random mac platform
|
||||||
|
func macPlatformToken(f *Faker) string {
|
||||||
|
return "Macintosh; " + getRandValue(f, []string{"computer", "mac_processor"}) + " Mac OS X 10_" + strconv.Itoa(randIntRange(f, 5, 9)) + "_" + strconv.Itoa(randIntRange(f, 0, 10))
|
||||||
|
}
|
||||||
|
|
||||||
|
// windowsPlatformToken will generate a random windows platform
|
||||||
|
func windowsPlatformToken(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"computer", "windows_platform"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// randomPlatform will generate a random platform
|
||||||
|
func randomPlatform(f *Faker) string {
|
||||||
|
platforms := []string{
|
||||||
|
linuxPlatformToken(f),
|
||||||
|
macPlatformToken(f),
|
||||||
|
windowsPlatformToken(f),
|
||||||
|
}
|
||||||
|
|
||||||
|
return randomString(f, platforms)
|
||||||
|
}
|
||||||
|
|
||||||
|
// HTTPVersion will generate a random http version
|
||||||
|
func HTTPVersion() string { return httpVersion(GlobalFaker) }
|
||||||
|
|
||||||
|
// HTTPVersion will generate a random http version
|
||||||
|
func (f *Faker) HTTPVersion() string { return httpVersion(f) }
|
||||||
|
|
||||||
|
func httpVersion(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"internet", "http_version"})
|
||||||
|
}
|
||||||
|
|
||||||
|
func addInternetLookup() {
|
||||||
|
AddFuncLookup("url", Info{
|
||||||
|
Display: "URL",
|
||||||
|
Category: "internet",
|
||||||
|
Description: "Web address that specifies the location of a resource on the internet",
|
||||||
|
Example: "http://www.principalproductize.biz/target",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return url(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("domainname", Info{
|
||||||
|
Display: "Domain Name",
|
||||||
|
Category: "internet",
|
||||||
|
Description: "Human-readable web address used to identify websites on the internet",
|
||||||
|
Example: "centraltarget.biz",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return domainName(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("domainsuffix", Info{
|
||||||
|
Display: "Domain Suffix",
|
||||||
|
Category: "internet",
|
||||||
|
Description: "The part of a domain name that comes after the last dot, indicating its type or purpose",
|
||||||
|
Example: "org",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return domainSuffix(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("ipv4address", Info{
|
||||||
|
Display: "IPv4 Address",
|
||||||
|
Category: "internet",
|
||||||
|
Description: "Numerical label assigned to devices on a network for identification and communication",
|
||||||
|
Example: "222.83.191.222",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return ipv4Address(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("ipv6address", Info{
|
||||||
|
Display: "IPv6 Address",
|
||||||
|
Category: "internet",
|
||||||
|
Description: "Numerical label assigned to devices on a network, providing a larger address space than IPv4 for internet communication",
|
||||||
|
Example: "2001:cafe:8898:ee17:bc35:9064:5866:d019",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return ipv6Address(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("httpmethod", Info{
|
||||||
|
Display: "HTTP Method",
|
||||||
|
Category: "internet",
|
||||||
|
Description: "Verb used in HTTP requests to specify the desired action to be performed on a resource",
|
||||||
|
Example: "HEAD",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return httpMethod(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("loglevel", Info{
|
||||||
|
Display: "Log Level",
|
||||||
|
Category: "internet",
|
||||||
|
Description: "Classification used in logging to indicate the severity or priority of a log entry",
|
||||||
|
Example: "error",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return logLevel(f, ""), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("useragent", Info{
|
||||||
|
Display: "User Agent",
|
||||||
|
Category: "internet",
|
||||||
|
Description: "String sent by a web browser to identify itself when requesting web content",
|
||||||
|
Example: "Mozilla/5.0 (Windows NT 5.0) AppleWebKit/5362 (KHTML, like Gecko) Chrome/37.0.834.0 Mobile Safari/5362",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return userAgent(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("chromeuseragent", Info{
|
||||||
|
Display: "Chrome User Agent",
|
||||||
|
Category: "internet",
|
||||||
|
Description: "The specific identification string sent by the Google Chrome web browser when making requests on the internet",
|
||||||
|
Example: "Mozilla/5.0 (X11; Linux i686) AppleWebKit/5312 (KHTML, like Gecko) Chrome/39.0.836.0 Mobile Safari/5312",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return chromeUserAgent(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("firefoxuseragent", Info{
|
||||||
|
Display: "Firefox User Agent",
|
||||||
|
Category: "internet",
|
||||||
|
Description: "The specific identification string sent by the Firefox web browser when making requests on the internet",
|
||||||
|
Example: "Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_8_3 rv:7.0) Gecko/1900-07-01 Firefox/37.0",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return firefoxUserAgent(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("operauseragent", Info{
|
||||||
|
Display: "Opera User Agent",
|
||||||
|
Category: "internet",
|
||||||
|
Description: "The specific identification string sent by the Opera web browser when making requests on the internet",
|
||||||
|
Example: "Opera/8.39 (Macintosh; U; PPC Mac OS X 10_8_7; en-US) Presto/2.9.335 Version/10.00",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return operaUserAgent(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("safariuseragent", Info{
|
||||||
|
Display: "Safari User Agent",
|
||||||
|
Category: "internet",
|
||||||
|
Description: "The specific identification string sent by the Safari web browser when making requests on the internet",
|
||||||
|
Example: "Mozilla/5.0 (iPad; CPU OS 8_3_2 like Mac OS X; en-US) AppleWebKit/531.15.6 (KHTML, like Gecko) Version/4.0.5 Mobile/8B120 Safari/6531.15.6",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return safariUserAgent(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("httpstatuscode", Info{
|
||||||
|
Display: "HTTP Status Code",
|
||||||
|
Category: "internet",
|
||||||
|
Description: "Random http status code",
|
||||||
|
Example: "200",
|
||||||
|
Output: "int",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return httpStatusCode(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("httpstatuscodesimple", Info{
|
||||||
|
Display: "HTTP Status Code Simple",
|
||||||
|
Category: "internet",
|
||||||
|
Description: "Three-digit number returned by a web server to indicate the outcome of an HTTP request",
|
||||||
|
Example: "404",
|
||||||
|
Output: "int",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return httpStatusCodeSimple(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("httpversion", Info{
|
||||||
|
Display: "HTTP Version",
|
||||||
|
Category: "internet",
|
||||||
|
Description: "Number indicating the version of the HTTP protocol used for communication between a client and a server",
|
||||||
|
Example: "HTTP/1.1",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return httpVersion(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("macaddress", Info{
|
||||||
|
Display: "MAC Address",
|
||||||
|
Category: "internet",
|
||||||
|
Description: "Unique identifier assigned to network interfaces, often used in Ethernet networks",
|
||||||
|
Example: "cb:ce:06:94:22:e9",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return macAddress(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,348 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
// JSONOptions defines values needed for json generation
|
||||||
|
type JSONOptions struct {
|
||||||
|
Type string `json:"type" xml:"type" fake:"{randomstring:[array,object]}"` // array or object
|
||||||
|
RowCount int `json:"row_count" xml:"row_count" fake:"{number:1,10}"`
|
||||||
|
Indent bool `json:"indent" xml:"indent"`
|
||||||
|
Fields []Field `json:"fields" xml:"fields" fake:"{fields}"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type jsonKeyVal struct {
|
||||||
|
Key string
|
||||||
|
Value any
|
||||||
|
}
|
||||||
|
|
||||||
|
type jsonOrderedKeyVal []*jsonKeyVal
|
||||||
|
|
||||||
|
func (okv jsonOrderedKeyVal) MarshalJSON() ([]byte, error) {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
|
||||||
|
buf.WriteString("{")
|
||||||
|
for i, kv := range okv {
|
||||||
|
// Add comma to all except last one
|
||||||
|
if i != 0 {
|
||||||
|
buf.WriteString(",")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Marshal key and write
|
||||||
|
key, err := json.Marshal(kv.Key)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
buf.Write(key)
|
||||||
|
|
||||||
|
// Write colon separator
|
||||||
|
buf.WriteString(":")
|
||||||
|
|
||||||
|
// Marshal value and write
|
||||||
|
val, err := json.Marshal(kv.Value)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
buf.Write(val)
|
||||||
|
}
|
||||||
|
buf.WriteString("}")
|
||||||
|
|
||||||
|
return buf.Bytes(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSON generates an object or an array of objects in json format.
|
||||||
|
// A nil JSONOptions returns a randomly structured JSON.
|
||||||
|
func JSON(jo *JSONOptions) ([]byte, error) { return jsonFunc(GlobalFaker, jo) }
|
||||||
|
|
||||||
|
// JSON generates an object or an array of objects in json format.
|
||||||
|
// A nil JSONOptions returns a randomly structured JSON.
|
||||||
|
func (f *Faker) JSON(jo *JSONOptions) ([]byte, error) { return jsonFunc(f, jo) }
|
||||||
|
|
||||||
|
// JSON generates an object or an array of objects in json format
|
||||||
|
func jsonFunc(f *Faker, jo *JSONOptions) ([]byte, error) {
|
||||||
|
if jo == nil {
|
||||||
|
// We didn't get a JSONOptions, so create a new random one
|
||||||
|
err := f.Struct(&jo)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check to make sure they passed in a type
|
||||||
|
if jo.Type != "array" && jo.Type != "object" {
|
||||||
|
return nil, errors.New("invalid type, must be array or object")
|
||||||
|
}
|
||||||
|
|
||||||
|
if jo.Fields == nil || len(jo.Fields) <= 0 {
|
||||||
|
return nil, errors.New("must pass fields in order to build json object(s)")
|
||||||
|
}
|
||||||
|
|
||||||
|
if jo.Type == "object" {
|
||||||
|
v := make(jsonOrderedKeyVal, len(jo.Fields))
|
||||||
|
|
||||||
|
// Loop through fields and add to them to map[string]any
|
||||||
|
for i, field := range jo.Fields {
|
||||||
|
if field.Function == "autoincrement" {
|
||||||
|
// Object only has one
|
||||||
|
v[i] = &jsonKeyVal{Key: field.Name, Value: 1}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get function info
|
||||||
|
funcInfo := GetFuncLookup(field.Function)
|
||||||
|
if funcInfo == nil {
|
||||||
|
return nil, errors.New("invalid function, " + field.Function + " does not exist")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call function value
|
||||||
|
value, err := funcInfo.Generate(f, &field.Params, funcInfo)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := value.([]byte); ok {
|
||||||
|
// If it's a slice, unmarshal it into an interface
|
||||||
|
var val any
|
||||||
|
err := json.Unmarshal(value.([]byte), &val)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
value = val
|
||||||
|
}
|
||||||
|
|
||||||
|
v[i] = &jsonKeyVal{Key: field.Name, Value: value}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Marshal into bytes
|
||||||
|
if jo.Indent {
|
||||||
|
j, _ := json.MarshalIndent(v, "", " ")
|
||||||
|
return j, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
j, _ := json.Marshal(v)
|
||||||
|
return j, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if jo.Type == "array" {
|
||||||
|
// Make sure you set a row count
|
||||||
|
if jo.RowCount <= 0 {
|
||||||
|
return nil, errors.New("must have row count")
|
||||||
|
}
|
||||||
|
|
||||||
|
v := make([]jsonOrderedKeyVal, jo.RowCount)
|
||||||
|
|
||||||
|
for i := 0; i < int(jo.RowCount); i++ {
|
||||||
|
vr := make(jsonOrderedKeyVal, len(jo.Fields))
|
||||||
|
|
||||||
|
// Loop through fields and add to them to map[string]any
|
||||||
|
for ii, field := range jo.Fields {
|
||||||
|
if field.Function == "autoincrement" {
|
||||||
|
vr[ii] = &jsonKeyVal{Key: field.Name, Value: i + 1} // +1 because index starts with 0
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get function info
|
||||||
|
funcInfo := GetFuncLookup(field.Function)
|
||||||
|
if funcInfo == nil {
|
||||||
|
return nil, errors.New("invalid function, " + field.Function + " does not exist")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call function value
|
||||||
|
value, err := funcInfo.Generate(f, &field.Params, funcInfo)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := value.([]byte); ok {
|
||||||
|
// If it's a slice, unmarshal it into an interface
|
||||||
|
var val any
|
||||||
|
err := json.Unmarshal(value.([]byte), &val)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
value = val
|
||||||
|
}
|
||||||
|
|
||||||
|
vr[ii] = &jsonKeyVal{Key: field.Name, Value: value}
|
||||||
|
}
|
||||||
|
|
||||||
|
v[i] = vr
|
||||||
|
}
|
||||||
|
|
||||||
|
// Marshal into bytes
|
||||||
|
if jo.Indent {
|
||||||
|
j, _ := json.MarshalIndent(v, "", " ")
|
||||||
|
return j, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
j, _ := json.Marshal(v)
|
||||||
|
return j, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, errors.New("invalid type, must be array or object")
|
||||||
|
}
|
||||||
|
|
||||||
|
func addFileJSONLookup() {
|
||||||
|
AddFuncLookup("json", Info{
|
||||||
|
Display: "JSON",
|
||||||
|
Category: "file",
|
||||||
|
Description: "Format for structured data interchange used in programming, returns an object or an array of objects",
|
||||||
|
Example: `[
|
||||||
|
{ "first_name": "Markus", "last_name": "Moen", "password": "Dc0VYXjkWABx" },
|
||||||
|
{ "first_name": "Osborne", "last_name": "Hilll", "password": "XPJ9OVNbs5lm" },
|
||||||
|
{ "first_name": "Mertie", "last_name": "Halvorson", "password": "eyl3bhwfV8wA" }
|
||||||
|
]`,
|
||||||
|
Output: "[]byte",
|
||||||
|
ContentType: "application/json",
|
||||||
|
Params: []Param{
|
||||||
|
{Field: "type", Display: "Type", Type: "string", Default: "object", Options: []string{"object", "array"}, Description: "Type of JSON, object or array"},
|
||||||
|
{Field: "rowcount", Display: "Row Count", Type: "int", Default: "100", Description: "Number of rows in JSON array"},
|
||||||
|
{Field: "indent", Display: "Indent", Type: "bool", Default: "false", Description: "Whether or not to add indents and newlines"},
|
||||||
|
{Field: "fields", Display: "Fields", Type: "[]Field", Description: "Fields containing key name and function to run in json format"},
|
||||||
|
},
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
jo := JSONOptions{}
|
||||||
|
|
||||||
|
typ, err := info.GetString(m, "type")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
jo.Type = typ
|
||||||
|
|
||||||
|
rowcount, err := info.GetInt(m, "rowcount")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
jo.RowCount = rowcount
|
||||||
|
|
||||||
|
indent, err := info.GetBool(m, "indent")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
jo.Indent = indent
|
||||||
|
|
||||||
|
fieldsStr, err := info.GetStringArray(m, "fields")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check to make sure fields has length
|
||||||
|
if len(fieldsStr) > 0 {
|
||||||
|
jo.Fields = make([]Field, len(fieldsStr))
|
||||||
|
|
||||||
|
for i, f := range fieldsStr {
|
||||||
|
// Unmarshal fields string into fields array
|
||||||
|
err = json.Unmarshal([]byte(f), &jo.Fields[i])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return jsonFunc(f, &jo)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// encoding/json.RawMessage is a special case of []byte
|
||||||
|
// it cannot be handled as a reflect.Array/reflect.Slice
|
||||||
|
// because it needs additional structure in the output
|
||||||
|
func rJsonRawMessage(f *Faker, v reflect.Value, tag string) error {
|
||||||
|
if tag != "" {
|
||||||
|
err := rCustom(f, v, tag)
|
||||||
|
if err == nil {
|
||||||
|
jsonData := v.Bytes()
|
||||||
|
if !json.Valid(jsonData) {
|
||||||
|
fName, _ := parseNameAndParamsFromTag(tag)
|
||||||
|
return errors.New("custom function " + fName + " returned invalid json data: " + string(jsonData))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
b, err := f.JSON(nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
v.SetBytes(b)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// encoding/json.Number is a special case of string
|
||||||
|
// that represents a JSON number literal.
|
||||||
|
// It cannot be handled as a string because it needs to
|
||||||
|
// represent an integer or a floating-point number.
|
||||||
|
func rJsonNumber(f *Faker, v reflect.Value, tag string) error {
|
||||||
|
var ret json.Number
|
||||||
|
|
||||||
|
var numberType string
|
||||||
|
|
||||||
|
if tag == "" {
|
||||||
|
numberType = f.RandomString([]string{"int", "float"})
|
||||||
|
|
||||||
|
switch numberType {
|
||||||
|
case "int":
|
||||||
|
retInt := f.Int16()
|
||||||
|
ret = json.Number(strconv.Itoa(int(retInt)))
|
||||||
|
case "float":
|
||||||
|
retFloat := f.Float64()
|
||||||
|
ret = json.Number(strconv.FormatFloat(retFloat, 'f', -1, 64))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fName, fParams := parseNameAndParamsFromTag(tag)
|
||||||
|
info := GetFuncLookup(fName)
|
||||||
|
if info == nil {
|
||||||
|
return fmt.Errorf("invalid function, %s does not exist", fName)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse map params
|
||||||
|
mapParams, err := parseMapParams(info, fParams)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
valueIface, err := info.Generate(f, mapParams, info)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
switch value := valueIface.(type) {
|
||||||
|
case int:
|
||||||
|
ret = json.Number(strconv.FormatInt(int64(value), 10))
|
||||||
|
case int8:
|
||||||
|
ret = json.Number(strconv.FormatInt(int64(value), 10))
|
||||||
|
case int16:
|
||||||
|
ret = json.Number(strconv.FormatInt(int64(value), 10))
|
||||||
|
case int32:
|
||||||
|
ret = json.Number(strconv.FormatInt(int64(value), 10))
|
||||||
|
case int64:
|
||||||
|
ret = json.Number(strconv.FormatInt(int64(value), 10))
|
||||||
|
case uint:
|
||||||
|
ret = json.Number(strconv.FormatUint(uint64(value), 10))
|
||||||
|
case uint8:
|
||||||
|
ret = json.Number(strconv.FormatUint(uint64(value), 10))
|
||||||
|
case uint16:
|
||||||
|
ret = json.Number(strconv.FormatUint(uint64(value), 10))
|
||||||
|
case uint32:
|
||||||
|
ret = json.Number(strconv.FormatUint(uint64(value), 10))
|
||||||
|
case uint64:
|
||||||
|
ret = json.Number(strconv.FormatUint(uint64(value), 10))
|
||||||
|
case float32:
|
||||||
|
ret = json.Number(strconv.FormatFloat(float64(value), 'f', -1, 64))
|
||||||
|
case float64:
|
||||||
|
ret = json.Number(strconv.FormatFloat(float64(value), 'f', -1, 64))
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("invalid type, %s is not a valid type for json.Number", reflect.TypeOf(value))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
v.Set(reflect.ValueOf(ret))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,81 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
// Language will return a random language
|
||||||
|
func Language() string { return language(GlobalFaker) }
|
||||||
|
|
||||||
|
// Language will return a random language
|
||||||
|
func (f *Faker) Language() string { return language(f) }
|
||||||
|
|
||||||
|
func language(f *Faker) string { return getRandValue(f, []string{"language", "long"}) }
|
||||||
|
|
||||||
|
// LanguageAbbreviation will return a random language abbreviation
|
||||||
|
func LanguageAbbreviation() string { return languageAbbreviation(GlobalFaker) }
|
||||||
|
|
||||||
|
// LanguageAbbreviation will return a random language abbreviation
|
||||||
|
func (f *Faker) LanguageAbbreviation() string { return languageAbbreviation(f) }
|
||||||
|
|
||||||
|
func languageAbbreviation(f *Faker) string { return getRandValue(f, []string{"language", "short"}) }
|
||||||
|
|
||||||
|
// LanguageBCP will return a random language BCP (Best Current Practices)
|
||||||
|
func LanguageBCP() string { return languageBCP(GlobalFaker) }
|
||||||
|
|
||||||
|
// LanguageBCP will return a random language BCP (Best Current Practices)
|
||||||
|
func (f *Faker) LanguageBCP() string { return languageBCP(f) }
|
||||||
|
|
||||||
|
func languageBCP(f *Faker) string { return getRandValue(f, []string{"language", "bcp"}) }
|
||||||
|
|
||||||
|
// ProgrammingLanguage will return a random programming language
|
||||||
|
func ProgrammingLanguage() string { return programmingLanguage(GlobalFaker) }
|
||||||
|
|
||||||
|
// ProgrammingLanguage will return a random programming language
|
||||||
|
func (f *Faker) ProgrammingLanguage() string { return programmingLanguage(f) }
|
||||||
|
|
||||||
|
func programmingLanguage(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"language", "programming"})
|
||||||
|
}
|
||||||
|
|
||||||
|
func addLanguagesLookup() {
|
||||||
|
AddFuncLookup("language", Info{
|
||||||
|
Display: "Language",
|
||||||
|
Category: "language",
|
||||||
|
Description: "System of communication using symbols, words, and grammar to convey meaning between individuals",
|
||||||
|
Example: "Kazakh",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return language(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("languageabbreviation", Info{
|
||||||
|
Display: "Language Abbreviation",
|
||||||
|
Category: "language",
|
||||||
|
Description: "Shortened form of a language's name",
|
||||||
|
Example: "kk",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return languageAbbreviation(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("languagebcp", Info{
|
||||||
|
Display: "Language BCP",
|
||||||
|
Category: "language",
|
||||||
|
Description: "Set of guidelines and standards for identifying and representing languages in computing and internet protocols",
|
||||||
|
Example: "en-US",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return languageBCP(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("programminglanguage", Info{
|
||||||
|
Display: "Programming Language",
|
||||||
|
Category: "language",
|
||||||
|
Description: "Formal system of instructions used to create software and perform computational tasks",
|
||||||
|
Example: "Go",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return programmingLanguage(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 26 KiB |
|
|
@ -0,0 +1,515 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
// FuncLookups is the primary map array with mapping to all available data
|
||||||
|
var FuncLookups map[string]Info
|
||||||
|
var lockFuncLookups sync.Mutex
|
||||||
|
|
||||||
|
// MapParams is the values to pass into a lookup generate
|
||||||
|
type MapParams map[string]MapParamsValue
|
||||||
|
|
||||||
|
type MapParamsValue []string
|
||||||
|
|
||||||
|
// Info structures fields to better break down what each one generates
|
||||||
|
type Info struct {
|
||||||
|
Display string `json:"display"`
|
||||||
|
Category string `json:"category"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
Example string `json:"example"`
|
||||||
|
Output string `json:"output"`
|
||||||
|
ContentType string `json:"content_type"`
|
||||||
|
Params []Param `json:"params"`
|
||||||
|
Any any `json:"any"`
|
||||||
|
Generate func(f *Faker, m *MapParams, info *Info) (any, error) `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Param is a breakdown of param requirements and type definition
|
||||||
|
type Param struct {
|
||||||
|
Field string `json:"field"`
|
||||||
|
Display string `json:"display"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Optional bool `json:"optional"`
|
||||||
|
Default string `json:"default"`
|
||||||
|
Options []string `json:"options"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Field is used for defining what name and function you to generate for file outuputs
|
||||||
|
type Field struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Function string `json:"function"`
|
||||||
|
Params MapParams `json:"params"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() { initLookup() }
|
||||||
|
|
||||||
|
// init will add all the functions to MapLookups
|
||||||
|
func initLookup() {
|
||||||
|
addAddressLookup()
|
||||||
|
addAnimalLookup()
|
||||||
|
addAppLookup()
|
||||||
|
addAuthLookup()
|
||||||
|
addBeerLookup()
|
||||||
|
addBookLookup()
|
||||||
|
addCarLookup()
|
||||||
|
addCelebrityLookup()
|
||||||
|
addColorLookup()
|
||||||
|
addCompanyLookup()
|
||||||
|
addDatabaseSQLLookup()
|
||||||
|
addDateTimeLookup()
|
||||||
|
addEmojiLookup()
|
||||||
|
addErrorLookup()
|
||||||
|
addFileCSVLookup()
|
||||||
|
addFileJSONLookup()
|
||||||
|
addFileLookup()
|
||||||
|
addFileXMLLookup()
|
||||||
|
addFinanceLookup()
|
||||||
|
addFoodLookup()
|
||||||
|
addGameLookup()
|
||||||
|
addGenerateLookup()
|
||||||
|
addHackerLookup()
|
||||||
|
addHipsterLookup()
|
||||||
|
addHtmlLookup()
|
||||||
|
addImageLookup()
|
||||||
|
addInternetLookup()
|
||||||
|
addLanguagesLookup()
|
||||||
|
addLoremLookup()
|
||||||
|
addMinecraftLookup()
|
||||||
|
addMiscLookup()
|
||||||
|
addMovieLookup()
|
||||||
|
addNumberLookup()
|
||||||
|
addPaymentLookup()
|
||||||
|
addPersonLookup()
|
||||||
|
addProductLookup()
|
||||||
|
addSchoolLookup()
|
||||||
|
addStringLookup()
|
||||||
|
addTemplateLookup()
|
||||||
|
addWeightedLookup()
|
||||||
|
addWordAdjectiveLookup()
|
||||||
|
addWordAdverbLookup()
|
||||||
|
addWordConnectiveLookup()
|
||||||
|
addWordGeneralLookup()
|
||||||
|
addWordGrammerLookup()
|
||||||
|
addWordNounLookup()
|
||||||
|
addWordPhraseLookup()
|
||||||
|
addWordPrepositionLookup()
|
||||||
|
addWordPronounLookup()
|
||||||
|
addWordSentenceLookup()
|
||||||
|
addWordVerbLookup()
|
||||||
|
addWordCommentLookup()
|
||||||
|
addWordMiscLookup()
|
||||||
|
}
|
||||||
|
|
||||||
|
// internalFuncLookups is the internal map array with mapping to all available data
|
||||||
|
var internalFuncLookups map[string]Info = map[string]Info{
|
||||||
|
"fields": {
|
||||||
|
Description: "Example fields for generating csv, json, xml, etc",
|
||||||
|
Output: "gofakeit.Field",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
function, _ := GetRandomSimpleFunc(f)
|
||||||
|
return Field{
|
||||||
|
Name: function,
|
||||||
|
Function: function,
|
||||||
|
}, nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMapParams will create a new MapParams
|
||||||
|
func NewMapParams() *MapParams {
|
||||||
|
return &MapParams{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add will take in a field and value and add it to the map params type
|
||||||
|
func (m *MapParams) Add(field string, value string) {
|
||||||
|
_, ok := (*m)[field]
|
||||||
|
if !ok {
|
||||||
|
(*m)[field] = []string{value}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
(*m)[field] = append((*m)[field], value)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get will return the array of string from the provided field
|
||||||
|
func (m *MapParams) Get(field string) []string {
|
||||||
|
return (*m)[field]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Size will return the total size of the underlying map
|
||||||
|
func (m *MapParams) Size() int {
|
||||||
|
size := 0
|
||||||
|
for range *m {
|
||||||
|
size++
|
||||||
|
}
|
||||||
|
return size
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalJSON will unmarshal the json into the []string
|
||||||
|
func (m *MapParamsValue) UnmarshalJSON(data []byte) error {
|
||||||
|
// check if the data is an array
|
||||||
|
// if so, marshal it into m
|
||||||
|
if data[0] == '[' {
|
||||||
|
var values []any
|
||||||
|
err := json.Unmarshal(data, &values)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// convert the values to array of strings
|
||||||
|
for _, value := range values {
|
||||||
|
typeOf := reflect.TypeOf(value).Kind().String()
|
||||||
|
|
||||||
|
if typeOf == "map" {
|
||||||
|
v, err := json.Marshal(value)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*m = append(*m, string(v))
|
||||||
|
} else {
|
||||||
|
*m = append(*m, fmt.Sprintf("%v", value))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// if not, then convert into a string and add it to m
|
||||||
|
var s any
|
||||||
|
if err := json.Unmarshal(data, &s); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
*m = append(*m, fmt.Sprintf("%v", s))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetRandomSimpleFunc(f *Faker) (string, Info) {
|
||||||
|
// Loop through all the functions and add them to a slice
|
||||||
|
var keys []string
|
||||||
|
for k, info := range FuncLookups {
|
||||||
|
// Only grab simple functions
|
||||||
|
if info.Params == nil {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Randomly grab a function from the slice
|
||||||
|
randomKey := randomString(f, keys)
|
||||||
|
|
||||||
|
// Return the function name and info
|
||||||
|
return randomKey, FuncLookups[randomKey]
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddFuncLookup takes a field and adds it to map
|
||||||
|
func AddFuncLookup(functionName string, info Info) {
|
||||||
|
if FuncLookups == nil {
|
||||||
|
FuncLookups = make(map[string]Info)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check content type
|
||||||
|
if info.ContentType == "" {
|
||||||
|
info.ContentType = "text/plain"
|
||||||
|
}
|
||||||
|
|
||||||
|
lockFuncLookups.Lock()
|
||||||
|
FuncLookups[functionName] = info
|
||||||
|
lockFuncLookups.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetFuncLookup will lookup
|
||||||
|
func GetFuncLookup(functionName string) *Info {
|
||||||
|
var info Info
|
||||||
|
var ok bool
|
||||||
|
|
||||||
|
// Check internal functions first
|
||||||
|
info, ok = internalFuncLookups[functionName]
|
||||||
|
if ok {
|
||||||
|
return &info
|
||||||
|
}
|
||||||
|
|
||||||
|
info, ok = FuncLookups[functionName]
|
||||||
|
if ok {
|
||||||
|
return &info
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveFuncLookup will remove a function from lookup
|
||||||
|
func RemoveFuncLookup(functionName string) {
|
||||||
|
_, ok := FuncLookups[functionName]
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
lockFuncLookups.Lock()
|
||||||
|
delete(FuncLookups, functionName)
|
||||||
|
lockFuncLookups.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAny will retrieve Any field from Info
|
||||||
|
func (i *Info) GetAny(m *MapParams, field string) (any, error) {
|
||||||
|
_, value, err := i.GetField(m, field)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure value[0] exists
|
||||||
|
if len(value) == 0 {
|
||||||
|
return nil, fmt.Errorf("could not find field: %s", field)
|
||||||
|
}
|
||||||
|
|
||||||
|
var anyValue any
|
||||||
|
|
||||||
|
// Try to convert to int
|
||||||
|
valueInt, err := strconv.ParseInt(value[0], 10, 64)
|
||||||
|
if err == nil {
|
||||||
|
return int(valueInt), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to convert to float
|
||||||
|
valueFloat, err := strconv.ParseFloat(value[0], 64)
|
||||||
|
if err == nil {
|
||||||
|
return valueFloat, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to convert to boolean
|
||||||
|
valueBool, err := strconv.ParseBool(value[0])
|
||||||
|
if err == nil {
|
||||||
|
return valueBool, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(value[0]), &anyValue)
|
||||||
|
if err == nil {
|
||||||
|
return valueBool, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return value[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMap will retrieve map[string]any field from data
|
||||||
|
func (i *Info) GetMap(m *MapParams, field string) (map[string]any, error) {
|
||||||
|
_, value, err := i.GetField(m, field)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var mapValue map[string]any
|
||||||
|
err = json.Unmarshal([]byte(value[0]), &mapValue)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("%s field could not parse to map[string]any", field)
|
||||||
|
}
|
||||||
|
|
||||||
|
return mapValue, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetField will retrieve field from data
|
||||||
|
func (i *Info) GetField(m *MapParams, field string) (*Param, []string, error) {
|
||||||
|
// Get param
|
||||||
|
var p *Param
|
||||||
|
for _, param := range i.Params {
|
||||||
|
if param.Field == field {
|
||||||
|
p = ¶m
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if p == nil {
|
||||||
|
return nil, nil, fmt.Errorf("could not find param field %s", field)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get value from map
|
||||||
|
if m != nil {
|
||||||
|
value, ok := (*m)[field]
|
||||||
|
if !ok {
|
||||||
|
// If default isnt empty use default
|
||||||
|
if p.Default != "" {
|
||||||
|
return p, []string{p.Default}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, nil, fmt.Errorf("could not find field: %s", field)
|
||||||
|
}
|
||||||
|
|
||||||
|
return p, value, nil
|
||||||
|
} else if p.Default != "" {
|
||||||
|
// If p.Type is []uint, then we need to convert it to []string
|
||||||
|
if strings.HasPrefix(p.Default, "[") {
|
||||||
|
// Remove [] from type
|
||||||
|
defaultClean := p.Default[1 : len(p.Default)-1]
|
||||||
|
|
||||||
|
// Split on comma
|
||||||
|
defaultSplit := strings.Split(defaultClean, ",")
|
||||||
|
|
||||||
|
return p, defaultSplit, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// If default isnt empty use default
|
||||||
|
return p, []string{p.Default}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, nil, fmt.Errorf("could not find field: %s", field)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetBool will retrieve boolean field from data
|
||||||
|
func (i *Info) GetBool(m *MapParams, field string) (bool, error) {
|
||||||
|
p, value, err := i.GetField(m, field)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to convert to boolean
|
||||||
|
valueBool, err := strconv.ParseBool(value[0])
|
||||||
|
if err != nil {
|
||||||
|
return false, fmt.Errorf("%s field could not parse to bool value", p.Field)
|
||||||
|
}
|
||||||
|
|
||||||
|
return valueBool, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetInt will retrieve int field from data
|
||||||
|
func (i *Info) GetInt(m *MapParams, field string) (int, error) {
|
||||||
|
p, value, err := i.GetField(m, field)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to convert to int
|
||||||
|
valueInt, err := strconv.ParseInt(value[0], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return 0, fmt.Errorf("%s field could not parse to int value", p.Field)
|
||||||
|
}
|
||||||
|
|
||||||
|
return int(valueInt), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetUint will retrieve uint field from data
|
||||||
|
func (i *Info) GetUint(m *MapParams, field string) (uint, error) {
|
||||||
|
p, value, err := i.GetField(m, field)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to convert to int
|
||||||
|
valueUint, err := strconv.ParseUint(value[0], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return 0, fmt.Errorf("%s field could not parse to int value", p.Field)
|
||||||
|
}
|
||||||
|
|
||||||
|
return uint(valueUint), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetFloat32 will retrieve int field from data
|
||||||
|
func (i *Info) GetFloat32(m *MapParams, field string) (float32, error) {
|
||||||
|
p, value, err := i.GetField(m, field)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to convert to float
|
||||||
|
valueFloat, err := strconv.ParseFloat(value[0], 32)
|
||||||
|
if err != nil {
|
||||||
|
return 0, fmt.Errorf("%s field could not parse to float value", p.Field)
|
||||||
|
}
|
||||||
|
|
||||||
|
return float32(valueFloat), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetFloat64 will retrieve int field from data
|
||||||
|
func (i *Info) GetFloat64(m *MapParams, field string) (float64, error) {
|
||||||
|
p, value, err := i.GetField(m, field)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to convert to float
|
||||||
|
valueFloat, err := strconv.ParseFloat(value[0], 64)
|
||||||
|
if err != nil {
|
||||||
|
return 0, fmt.Errorf("%s field could not parse to float value", p.Field)
|
||||||
|
}
|
||||||
|
|
||||||
|
return valueFloat, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetString will retrieve string field from data
|
||||||
|
func (i *Info) GetString(m *MapParams, field string) (string, error) {
|
||||||
|
_, value, err := i.GetField(m, field)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return value[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetStringArray will retrieve []string field from data
|
||||||
|
func (i *Info) GetStringArray(m *MapParams, field string) ([]string, error) {
|
||||||
|
_, values, err := i.GetField(m, field)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return values, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetIntArray will retrieve []int field from data
|
||||||
|
func (i *Info) GetIntArray(m *MapParams, field string) ([]int, error) {
|
||||||
|
_, value, err := i.GetField(m, field)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var ints []int
|
||||||
|
for i := 0; i < len(value); i++ {
|
||||||
|
valueInt, err := strconv.ParseInt(value[i], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("%s value could not parse to int", value[i])
|
||||||
|
}
|
||||||
|
ints = append(ints, int(valueInt))
|
||||||
|
}
|
||||||
|
|
||||||
|
return ints, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetUintArray will retrieve []uint field from data
|
||||||
|
func (i *Info) GetUintArray(m *MapParams, field string) ([]uint, error) {
|
||||||
|
_, value, err := i.GetField(m, field)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var uints []uint
|
||||||
|
for i := 0; i < len(value); i++ {
|
||||||
|
valueUint, err := strconv.ParseUint(value[i], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("%s value could not parse to uint", value[i])
|
||||||
|
}
|
||||||
|
uints = append(uints, uint(valueUint))
|
||||||
|
}
|
||||||
|
|
||||||
|
return uints, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetFloat32Array will retrieve []float field from data
|
||||||
|
func (i *Info) GetFloat32Array(m *MapParams, field string) ([]float32, error) {
|
||||||
|
_, value, err := i.GetField(m, field)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var floats []float32
|
||||||
|
for i := 0; i < len(value); i++ {
|
||||||
|
valueFloat, err := strconv.ParseFloat(value[i], 32)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("%s value could not parse to float", value[i])
|
||||||
|
}
|
||||||
|
floats = append(floats, float32(valueFloat))
|
||||||
|
}
|
||||||
|
|
||||||
|
return floats, nil
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,126 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
// LoremIpsumWord will generate a random word
|
||||||
|
func LoremIpsumWord() string { return loremIpsumWord(GlobalFaker) }
|
||||||
|
|
||||||
|
// LoremIpsumWord will generate a random word
|
||||||
|
func (f *Faker) LoremIpsumWord() string { return loremIpsumWord(f) }
|
||||||
|
|
||||||
|
func loremIpsumWord(f *Faker) string { return getRandValue(f, []string{"lorem", "word"}) }
|
||||||
|
|
||||||
|
// LoremIpsumSentence will generate a random sentence
|
||||||
|
func LoremIpsumSentence(wordCount int) string {
|
||||||
|
return loremIpsumSentence(GlobalFaker, wordCount)
|
||||||
|
}
|
||||||
|
|
||||||
|
// LoremIpsumSentence will generate a random sentence
|
||||||
|
func (f *Faker) LoremIpsumSentence(wordCount int) string {
|
||||||
|
return loremIpsumSentence(f, wordCount)
|
||||||
|
}
|
||||||
|
|
||||||
|
func loremIpsumSentence(f *Faker, wordCount int) string {
|
||||||
|
return sentenceGen(f, wordCount, loremIpsumWord)
|
||||||
|
}
|
||||||
|
|
||||||
|
// LoremIpsumParagraph will generate a random paragraphGenerator
|
||||||
|
func LoremIpsumParagraph(paragraphCount int, sentenceCount int, wordCount int, separator string) string {
|
||||||
|
return loremIpsumParagraph(GlobalFaker, paragraphCount, sentenceCount, wordCount, separator)
|
||||||
|
}
|
||||||
|
|
||||||
|
// LoremIpsumParagraph will generate a random paragraphGenerator
|
||||||
|
func (f *Faker) LoremIpsumParagraph(paragraphCount int, sentenceCount int, wordCount int, separator string) string {
|
||||||
|
return loremIpsumParagraph(f, paragraphCount, sentenceCount, wordCount, separator)
|
||||||
|
}
|
||||||
|
|
||||||
|
func loremIpsumParagraph(f *Faker, paragraphCount int, sentenceCount int, wordCount int, separator string) string {
|
||||||
|
return paragraphGen(f, paragrapOptions{paragraphCount, sentenceCount, wordCount, separator}, loremIpsumSentence)
|
||||||
|
}
|
||||||
|
|
||||||
|
func addLoremLookup() {
|
||||||
|
AddFuncLookup("loremipsumword", Info{
|
||||||
|
Display: "Lorem Ipsum Word",
|
||||||
|
Category: "word",
|
||||||
|
Description: "Word of the Lorem Ipsum placeholder text used in design and publishing",
|
||||||
|
Example: "quia",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return loremIpsumWord(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("loremipsumsentence", Info{
|
||||||
|
Display: "Lorem Ipsum Sentence",
|
||||||
|
Category: "word",
|
||||||
|
Description: "Sentence of the Lorem Ipsum placeholder text used in design and publishing",
|
||||||
|
Example: "Quia quae repellat consequatur quidem.",
|
||||||
|
Output: "string",
|
||||||
|
Params: []Param{
|
||||||
|
{Field: "wordcount", Display: "Word Count", Type: "int", Default: "5", Description: "Number of words in a sentence"},
|
||||||
|
},
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
wordCount, err := info.GetInt(m, "wordcount")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if wordCount <= 0 || wordCount > 50 {
|
||||||
|
return nil, errors.New("invalid word count, must be greater than 0, less than 50")
|
||||||
|
}
|
||||||
|
|
||||||
|
return loremIpsumSentence(f, wordCount), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("loremipsumparagraph", Info{
|
||||||
|
Display: "Lorem Ipsum Paragraph",
|
||||||
|
Category: "word",
|
||||||
|
Description: "Paragraph of the Lorem Ipsum placeholder text used in design and publishing",
|
||||||
|
Example: `Quia quae repellat consequatur quidem nisi quo qui voluptatum accusantium quisquam amet. Quas et ut non dolorem ipsam aut enim assumenda mollitia harum ut. Dicta similique veniam nulla voluptas at excepturi non ad maxime at non. Eaque hic repellat praesentium voluptatem qui consequuntur dolor iusto autem velit aut. Fugit tempore exercitationem harum consequatur voluptatum modi minima aut eaque et et.
|
||||||
|
|
||||||
|
Aut ea voluptatem dignissimos expedita odit tempore quod aut beatae ipsam iste. Minus voluptatibus dolorem maiores eius sed nihil vel enim odio voluptatem accusamus. Natus quibusdam temporibus tenetur cumque sint necessitatibus dolorem ex ducimus iusto ex. Voluptatem neque dicta explicabo officiis et ducimus sit ut ut praesentium pariatur. Illum molestias nisi at dolore ut voluptatem accusantium et fugiat et ut.
|
||||||
|
|
||||||
|
Explicabo incidunt reprehenderit non quia dignissimos recusandae vitae soluta quia et quia. Aut veniam voluptas consequatur placeat sapiente non eveniet voluptatibus magni velit eum. Nobis vel repellendus sed est qui autem laudantium quidem quam ullam consequatur. Aut iusto ut commodi similique quae voluptatem atque qui fugiat eum aut. Quis distinctio consequatur voluptatem vel aliquid aut laborum facere officiis iure tempora.`,
|
||||||
|
Output: "string",
|
||||||
|
Params: []Param{
|
||||||
|
{Field: "paragraphcount", Display: "Paragraph Count", Type: "int", Default: "2", Description: "Number of paragraphs"},
|
||||||
|
{Field: "sentencecount", Display: "Sentence Count", Type: "int", Default: "2", Description: "Number of sentences in a paragraph"},
|
||||||
|
{Field: "wordcount", Display: "Word Count", Type: "int", Default: "5", Description: "Number of words in a sentence"},
|
||||||
|
{Field: "paragraphseparator", Display: "Paragraph Separator", Type: "string", Default: "<br />", Description: "String value to add between paragraphs"},
|
||||||
|
},
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
paragraphCount, err := info.GetInt(m, "paragraphcount")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if paragraphCount <= 0 || paragraphCount > 20 {
|
||||||
|
return nil, errors.New("invalid paragraph count, must be greater than 0, less than 20")
|
||||||
|
}
|
||||||
|
|
||||||
|
sentenceCount, err := info.GetInt(m, "sentencecount")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if sentenceCount <= 0 || sentenceCount > 20 {
|
||||||
|
return nil, errors.New("invalid sentence count, must be greater than 0, less than 20")
|
||||||
|
}
|
||||||
|
|
||||||
|
wordCount, err := info.GetInt(m, "wordcount")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if wordCount <= 0 || wordCount > 50 {
|
||||||
|
return nil, errors.New("invalid word count, must be greater than 0, less than 50")
|
||||||
|
}
|
||||||
|
|
||||||
|
paragraphSeparator, err := info.GetString(m, "paragraphseparator")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return loremIpsumParagraph(f, paragraphCount, sentenceCount, wordCount, paragraphSeparator), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,365 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
// MinecraftOre will generate a random Minecraft ore
|
||||||
|
func MinecraftOre() string { return minecraftOre(GlobalFaker) }
|
||||||
|
|
||||||
|
// MinecraftOre will generate a random Minecraft ore
|
||||||
|
func (f *Faker) MinecraftOre() string { return minecraftOre(f) }
|
||||||
|
|
||||||
|
func minecraftOre(f *Faker) string { return getRandValue(f, []string{"minecraft", "ore"}) }
|
||||||
|
|
||||||
|
// MinecraftWood will generate a random Minecraft wood
|
||||||
|
func MinecraftWood() string { return minecraftWood(GlobalFaker) }
|
||||||
|
|
||||||
|
// MinecraftWood will generate a random Minecraft wood
|
||||||
|
func (f *Faker) MinecraftWood() string { return minecraftWood(f) }
|
||||||
|
|
||||||
|
func minecraftWood(f *Faker) string { return getRandValue(f, []string{"minecraft", "wood"}) }
|
||||||
|
|
||||||
|
// MinecraftArmorTier will generate a random Minecraft armor tier
|
||||||
|
func MinecraftArmorTier() string { return minecraftArmorTier(GlobalFaker) }
|
||||||
|
|
||||||
|
// MinecraftArmorTier will generate a random Minecraft armor tier
|
||||||
|
func (f *Faker) MinecraftArmorTier() string { return minecraftArmorTier(f) }
|
||||||
|
|
||||||
|
func minecraftArmorTier(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"minecraft", "armortier"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// MinecraftArmorPart will generate a random Minecraft armor part
|
||||||
|
func MinecraftArmorPart() string { return minecraftArmorPart(GlobalFaker) }
|
||||||
|
|
||||||
|
// MinecraftArmorPart will generate a random Minecraft armor part
|
||||||
|
func (f *Faker) MinecraftArmorPart() string { return minecraftArmorPart(f) }
|
||||||
|
|
||||||
|
func minecraftArmorPart(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"minecraft", "armorpart"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// MinecraftWeapon will generate a random Minecraft weapon
|
||||||
|
func MinecraftWeapon() string { return minecraftWeapon(GlobalFaker) }
|
||||||
|
|
||||||
|
// MinecraftWeapon will generate a random Minecraft weapon
|
||||||
|
func (f *Faker) MinecraftWeapon() string { return minecraftWeapon(f) }
|
||||||
|
|
||||||
|
func minecraftWeapon(f *Faker) string { return getRandValue(f, []string{"minecraft", "weapon"}) }
|
||||||
|
|
||||||
|
// MinecraftTool will generate a random Minecraft tool
|
||||||
|
func MinecraftTool() string { return minecraftTool(GlobalFaker) }
|
||||||
|
|
||||||
|
// MinecraftTool will generate a random Minecraft tool
|
||||||
|
func (f *Faker) MinecraftTool() string { return minecraftTool(f) }
|
||||||
|
|
||||||
|
func minecraftTool(f *Faker) string { return getRandValue(f, []string{"minecraft", "tool"}) }
|
||||||
|
|
||||||
|
// MinecraftDye will generate a random Minecraft dye
|
||||||
|
func MinecraftDye() string { return minecraftDye(GlobalFaker) }
|
||||||
|
|
||||||
|
// MinecraftDye will generate a random Minecraft dye
|
||||||
|
func (f *Faker) MinecraftDye() string { return minecraftDye(f) }
|
||||||
|
|
||||||
|
func minecraftDye(f *Faker) string { return getRandValue(f, []string{"minecraft", "dye"}) }
|
||||||
|
|
||||||
|
// MinecraftFood will generate a random Minecraft food
|
||||||
|
func MinecraftFood() string { return minecraftFood(GlobalFaker) }
|
||||||
|
|
||||||
|
// MinecraftFood will generate a random Minecraft food
|
||||||
|
func (f *Faker) MinecraftFood() string { return minecraftFood(f) }
|
||||||
|
|
||||||
|
func minecraftFood(f *Faker) string { return getRandValue(f, []string{"minecraft", "food"}) }
|
||||||
|
|
||||||
|
// MinecraftAnimal will generate a random Minecraft animal
|
||||||
|
func MinecraftAnimal() string { return minecraftAnimal(GlobalFaker) }
|
||||||
|
|
||||||
|
// MinecraftAnimal will generate a random Minecraft animal
|
||||||
|
func (f *Faker) MinecraftAnimal() string { return minecraftAnimal(f) }
|
||||||
|
|
||||||
|
func minecraftAnimal(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"minecraft", "animal"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// MinecraftVillagerJob will generate a random Minecraft villager job
|
||||||
|
func MinecraftVillagerJob() string { return minecraftVillagerJob(GlobalFaker) }
|
||||||
|
|
||||||
|
// MinecraftVillagerJob will generate a random Minecraft villager job
|
||||||
|
func (f *Faker) MinecraftVillagerJob() string { return minecraftVillagerJob(f) }
|
||||||
|
|
||||||
|
func minecraftVillagerJob(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"minecraft", "villagerjob"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// MinecraftVillagerStation will generate a random Minecraft villager station
|
||||||
|
func MinecraftVillagerStation() string { return minecraftVillagerStation(GlobalFaker) }
|
||||||
|
|
||||||
|
// MinecraftVillagerStation will generate a random Minecraft villager station
|
||||||
|
func (f *Faker) MinecraftVillagerStation() string { return minecraftVillagerStation(f) }
|
||||||
|
|
||||||
|
func minecraftVillagerStation(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"minecraft", "villagerstation"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// MinecraftVillagerLevel will generate a random Minecraft villager level
|
||||||
|
func MinecraftVillagerLevel() string { return minecraftVillagerLevel(GlobalFaker) }
|
||||||
|
|
||||||
|
// MinecraftVillagerLevel will generate a random Minecraft villager level
|
||||||
|
func (f *Faker) MinecraftVillagerLevel() string { return minecraftVillagerLevel(f) }
|
||||||
|
|
||||||
|
func minecraftVillagerLevel(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"minecraft", "villagerlevel"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// MinecraftMobPassive will generate a random Minecraft mob passive
|
||||||
|
func MinecraftMobPassive() string { return minecraftMobPassive(GlobalFaker) }
|
||||||
|
|
||||||
|
// MinecraftMobPassive will generate a random Minecraft mob passive
|
||||||
|
func (f *Faker) MinecraftMobPassive() string { return minecraftMobPassive(f) }
|
||||||
|
|
||||||
|
func minecraftMobPassive(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"minecraft", "mobpassive"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// MinecraftMobNeutral will generate a random Minecraft mob neutral
|
||||||
|
func MinecraftMobNeutral() string { return minecraftMobNeutral(GlobalFaker) }
|
||||||
|
|
||||||
|
// MinecraftMobNeutral will generate a random Minecraft mob neutral
|
||||||
|
func (f *Faker) MinecraftMobNeutral() string { return minecraftMobNeutral(f) }
|
||||||
|
|
||||||
|
func minecraftMobNeutral(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"minecraft", "mobneutral"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// MinecraftMobHostile will generate a random Minecraft mob hostile
|
||||||
|
func MinecraftMobHostile() string { return minecraftMobHostile(GlobalFaker) }
|
||||||
|
|
||||||
|
// MinecraftMobHostile will generate a random Minecraft mob hostile
|
||||||
|
func (f *Faker) MinecraftMobHostile() string { return minecraftMobHostile(f) }
|
||||||
|
|
||||||
|
func minecraftMobHostile(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"minecraft", "mobhostile"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// MinecraftMobBoss will generate a random Minecraft mob boss
|
||||||
|
func MinecraftMobBoss() string { return minecraftMobBoss(GlobalFaker) }
|
||||||
|
|
||||||
|
// MinecraftMobBoss will generate a random Minecraft mob boss
|
||||||
|
func (f *Faker) MinecraftMobBoss() string { return minecraftMobBoss(f) }
|
||||||
|
|
||||||
|
func minecraftMobBoss(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"minecraft", "mobboss"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// MinecraftBiome will generate a random Minecraft biome
|
||||||
|
func MinecraftBiome() string { return minecraftBiome(GlobalFaker) }
|
||||||
|
|
||||||
|
// MinecraftBiome will generate a random Minecraft biome
|
||||||
|
func (f *Faker) MinecraftBiome() string { return minecraftBiome(f) }
|
||||||
|
|
||||||
|
func minecraftBiome(f *Faker) string { return getRandValue(f, []string{"minecraft", "biome"}) }
|
||||||
|
|
||||||
|
// MinecraftWeather will generate a random Minecraft weather
|
||||||
|
func MinecraftWeather() string { return minecraftWeather(GlobalFaker) }
|
||||||
|
|
||||||
|
// MinecraftWeather will generate a random Minecraft weather
|
||||||
|
func (f *Faker) MinecraftWeather() string { return minecraftWeather(f) }
|
||||||
|
|
||||||
|
func minecraftWeather(f *Faker) string { return getRandValue(f, []string{"minecraft", "weather"}) }
|
||||||
|
|
||||||
|
func addMinecraftLookup() {
|
||||||
|
AddFuncLookup("minecraftore", Info{
|
||||||
|
Display: "Minecraft ore",
|
||||||
|
Category: "minecraft",
|
||||||
|
Description: "Naturally occurring minerals found in the game Minecraft, used for crafting purposes",
|
||||||
|
Example: "coal",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return minecraftOre(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("minecraftwood", Info{
|
||||||
|
Display: "Minecraft wood",
|
||||||
|
Category: "minecraft",
|
||||||
|
Description: "Natural resource in Minecraft, used for crafting various items and building structures",
|
||||||
|
Example: "oak",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return minecraftWood(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("minecraftarmortier", Info{
|
||||||
|
Display: "Minecraft armor tier",
|
||||||
|
Category: "minecraft",
|
||||||
|
Description: "Classification system for armor sets in Minecraft, indicating their effectiveness and protection level",
|
||||||
|
Example: "iron",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return minecraftArmorTier(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("minecraftarmorpart", Info{
|
||||||
|
Display: "Minecraft armor part",
|
||||||
|
Category: "minecraft",
|
||||||
|
Description: "Component of an armor set in Minecraft, such as a helmet, chestplate, leggings, or boots",
|
||||||
|
Example: "helmet",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return minecraftArmorPart(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("minecraftweapon", Info{
|
||||||
|
Display: "Minecraft weapon",
|
||||||
|
Category: "minecraft",
|
||||||
|
Description: "Tools and items used in Minecraft for combat and defeating hostile mobs",
|
||||||
|
Example: "bow",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return minecraftWeapon(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("minecrafttool", Info{
|
||||||
|
Display: "Minecraft tool",
|
||||||
|
Category: "minecraft",
|
||||||
|
Description: "Items in Minecraft designed for specific tasks, including mining, digging, and building",
|
||||||
|
Example: "shovel",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return minecraftTool(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("minecraftdye", Info{
|
||||||
|
Display: "Minecraft dye",
|
||||||
|
Category: "minecraft",
|
||||||
|
Description: "Items used to change the color of various in-game objects",
|
||||||
|
Example: "white",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return minecraftDye(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("minecraftfood", Info{
|
||||||
|
Display: "Minecraft food",
|
||||||
|
Category: "minecraft",
|
||||||
|
Description: "Consumable items in Minecraft that provide nourishment to the player character",
|
||||||
|
Example: "apple",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return minecraftFood(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("minecraftanimal", Info{
|
||||||
|
Display: "Minecraft animal",
|
||||||
|
Category: "minecraft",
|
||||||
|
Description: "Non-hostile creatures in Minecraft, often used for resources and farming",
|
||||||
|
Example: "chicken",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return minecraftAnimal(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("minecraftvillagerjob", Info{
|
||||||
|
Display: "Minecraft villager job",
|
||||||
|
Category: "minecraft",
|
||||||
|
Description: "The profession or occupation assigned to a villager character in the game",
|
||||||
|
Example: "farmer",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return minecraftVillagerJob(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("minecraftvillagerstation", Info{
|
||||||
|
Display: "Minecraft villager station",
|
||||||
|
Category: "minecraft",
|
||||||
|
Description: "Designated area or structure in Minecraft where villagers perform their job-related tasks and trading",
|
||||||
|
Example: "furnace",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return minecraftVillagerStation(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("minecraftvillagerlevel", Info{
|
||||||
|
Display: "Minecraft villager level",
|
||||||
|
Category: "minecraft",
|
||||||
|
Description: "Measure of a villager's experience and proficiency in their assigned job or profession",
|
||||||
|
Example: "master",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return minecraftVillagerLevel(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("minecraftmobpassive", Info{
|
||||||
|
Display: "Minecraft mob passive",
|
||||||
|
Category: "minecraft",
|
||||||
|
Description: "Non-aggressive creatures in the game that do not attack players",
|
||||||
|
Example: "cow",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return minecraftMobPassive(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("minecraftmobneutral", Info{
|
||||||
|
Display: "Minecraft mob neutral",
|
||||||
|
Category: "minecraft",
|
||||||
|
Description: "Creature in the game that only becomes hostile if provoked, typically defending itself when attacked",
|
||||||
|
Example: "bee",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return minecraftMobNeutral(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("minecraftmobhostile", Info{
|
||||||
|
Display: "Minecraft mob hostile",
|
||||||
|
Category: "minecraft",
|
||||||
|
Description: "Aggressive creatures in the game that actively attack players when encountered",
|
||||||
|
Example: "spider",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return minecraftMobHostile(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("minecraftmobboss", Info{
|
||||||
|
Display: "Minecraft mob boss",
|
||||||
|
Category: "minecraft",
|
||||||
|
Description: "Powerful hostile creature in the game, often found in challenging dungeons or structures",
|
||||||
|
Example: "ender dragon",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return minecraftMobBoss(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("minecraftbiome", Info{
|
||||||
|
Display: "Minecraft biome",
|
||||||
|
Category: "minecraft",
|
||||||
|
Description: "Distinctive environmental regions in the game, characterized by unique terrain, vegetation, and weather",
|
||||||
|
Example: "forest",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return minecraftBiome(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("minecraftweather", Info{
|
||||||
|
Display: "Minecraft weather",
|
||||||
|
Category: "minecraft",
|
||||||
|
Description: "Atmospheric conditions in the game that include rain, thunderstorms, and clear skies, affecting gameplay and ambiance",
|
||||||
|
Example: "rain",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return minecraftWeather(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,164 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/hex"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/brianvoe/gofakeit/v7/data"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Bool will generate a random boolean value
|
||||||
|
func Bool() bool { return boolFunc(GlobalFaker) }
|
||||||
|
|
||||||
|
// Bool will generate a random boolean value
|
||||||
|
func (f *Faker) Bool() bool { return boolFunc(f) }
|
||||||
|
|
||||||
|
func boolFunc(f *Faker) bool { return randIntRange(f, 0, 1) == 1 }
|
||||||
|
|
||||||
|
// UUID (version 4) will generate a random unique identifier based upon random numbers
|
||||||
|
// Format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
||||||
|
func UUID() string { return uuid(GlobalFaker) }
|
||||||
|
|
||||||
|
// UUID (version 4) will generate a random unique identifier based upon random numbers
|
||||||
|
// Format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx 8-4-4-4-12
|
||||||
|
func (f *Faker) UUID() string { return uuid(f) }
|
||||||
|
|
||||||
|
func uuid(f *Faker) string {
|
||||||
|
version := byte(4)
|
||||||
|
uuid := make([]byte, 16)
|
||||||
|
|
||||||
|
// Read 16 random bytes
|
||||||
|
for i := 0; i < 16; i++ {
|
||||||
|
uuid[i] = byte(f.IntN(256))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set version
|
||||||
|
uuid[6] = (uuid[6] & 0x0f) | (version << 4)
|
||||||
|
|
||||||
|
// Set variant
|
||||||
|
uuid[8] = (uuid[8] & 0xbf) | 0x80
|
||||||
|
|
||||||
|
buf := make([]byte, 36)
|
||||||
|
hex.Encode(buf[0:8], uuid[0:4])
|
||||||
|
buf[8] = dash
|
||||||
|
hex.Encode(buf[9:13], uuid[4:6])
|
||||||
|
buf[13] = dash
|
||||||
|
hex.Encode(buf[14:18], uuid[6:8])
|
||||||
|
buf[18] = dash
|
||||||
|
hex.Encode(buf[19:23], uuid[8:10])
|
||||||
|
buf[23] = dash
|
||||||
|
hex.Encode(buf[24:], uuid[10:])
|
||||||
|
|
||||||
|
return string(buf)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShuffleAnySlice takes in a slice and outputs it in a random order
|
||||||
|
func ShuffleAnySlice(v any) { shuffleAnySlice(GlobalFaker, v) }
|
||||||
|
|
||||||
|
// ShuffleAnySlice takes in a slice and outputs it in a random order
|
||||||
|
func (f *Faker) ShuffleAnySlice(v any) { shuffleAnySlice(f, v) }
|
||||||
|
|
||||||
|
func shuffleAnySlice(f *Faker, v any) {
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check type of passed in value, if not a slice return with no action taken
|
||||||
|
typ := reflect.TypeOf(v)
|
||||||
|
if typ.Kind() != reflect.Slice {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
s := reflect.ValueOf(v)
|
||||||
|
n := s.Len()
|
||||||
|
|
||||||
|
if n <= 1 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
swap := func(i, j int) {
|
||||||
|
tmp := reflect.ValueOf(s.Index(i).Interface())
|
||||||
|
s.Index(i).Set(s.Index(j))
|
||||||
|
s.Index(j).Set(tmp)
|
||||||
|
}
|
||||||
|
|
||||||
|
//if size is > int32 probably it will never finish, or ran out of entropy
|
||||||
|
i := n - 1
|
||||||
|
for ; i > 0; i-- {
|
||||||
|
j := int(int32NFunc(f, int32(i+1)))
|
||||||
|
swap(i, j)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FlipACoin will return a random value of Heads or Tails
|
||||||
|
func FlipACoin() string { return flipACoin(GlobalFaker) }
|
||||||
|
|
||||||
|
// FlipACoin will return a random value of Heads or Tails
|
||||||
|
func (f *Faker) FlipACoin() string { return flipACoin(f) }
|
||||||
|
|
||||||
|
func flipACoin(f *Faker) string {
|
||||||
|
if boolFunc(f) {
|
||||||
|
return "Heads"
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Tails"
|
||||||
|
}
|
||||||
|
|
||||||
|
// RandomMapKey will return a random key from a map
|
||||||
|
func RandomMapKey(mapI any) any { return randomMapKey(GlobalFaker, mapI) }
|
||||||
|
|
||||||
|
// RandomMapKey will return a random key from a map
|
||||||
|
func (f *Faker) RandomMapKey(mapI any) any { return randomMapKey(f, mapI) }
|
||||||
|
|
||||||
|
func randomMapKey(f *Faker, mapI any) any {
|
||||||
|
keys := reflect.ValueOf(mapI).MapKeys()
|
||||||
|
return keys[f.IntN(len(keys))].Interface()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Categories will return a map string array of available data categories and sub categories
|
||||||
|
func Categories() map[string][]string {
|
||||||
|
types := make(map[string][]string)
|
||||||
|
for category, subCategoriesMap := range data.Data {
|
||||||
|
subCategories := make([]string, 0)
|
||||||
|
for subType := range subCategoriesMap {
|
||||||
|
subCategories = append(subCategories, subType)
|
||||||
|
}
|
||||||
|
types[category] = subCategories
|
||||||
|
}
|
||||||
|
return types
|
||||||
|
}
|
||||||
|
|
||||||
|
func addMiscLookup() {
|
||||||
|
AddFuncLookup("uuid", Info{
|
||||||
|
Display: "UUID",
|
||||||
|
Category: "misc",
|
||||||
|
Description: "128-bit identifier used to uniquely identify objects or entities in computer systems",
|
||||||
|
Example: "590c1440-9888-45b0-bd51-a817ee07c3f2",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return uuid(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("bool", Info{
|
||||||
|
Display: "Boolean",
|
||||||
|
Category: "misc",
|
||||||
|
Description: "Data type that represents one of two possible values, typically true or false",
|
||||||
|
Example: "true",
|
||||||
|
Output: "bool",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return boolFunc(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("flipacoin", Info{
|
||||||
|
Display: "Flip A Coin",
|
||||||
|
Category: "misc",
|
||||||
|
Description: "Decision-making method involving the tossing of a coin to determine outcomes",
|
||||||
|
Example: "Tails",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return flipACoin(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,68 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
func MovieName() string { return movieName(GlobalFaker) }
|
||||||
|
|
||||||
|
func (f *Faker) MovieName() string { return movieName(f) }
|
||||||
|
|
||||||
|
func movieName(f *Faker) string { return getRandValue(f, []string{"movie", "name"}) }
|
||||||
|
|
||||||
|
func MovieGenre() string { return movieGenre(GlobalFaker) }
|
||||||
|
|
||||||
|
func (f *Faker) MovieGenre() string { return movieGenre(f) }
|
||||||
|
|
||||||
|
func movieGenre(f *Faker) string { return getRandValue(f, []string{"movie", "genre"}) }
|
||||||
|
|
||||||
|
type MovieInfo struct {
|
||||||
|
Name string `json:"name" xml:"name"`
|
||||||
|
Genre string `json:"genre" xml:"genre"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func Movie() *MovieInfo { return movie(GlobalFaker) }
|
||||||
|
|
||||||
|
func (f *Faker) Movie() *MovieInfo { return movie(f) }
|
||||||
|
|
||||||
|
func movie(f *Faker) *MovieInfo {
|
||||||
|
return &MovieInfo{
|
||||||
|
Name: movieName(f),
|
||||||
|
Genre: movieGenre(f),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func addMovieLookup() {
|
||||||
|
AddFuncLookup("movie", Info{
|
||||||
|
Display: "Movie",
|
||||||
|
Category: "movie",
|
||||||
|
Description: "A story told through moving pictures and sound",
|
||||||
|
Example: `{
|
||||||
|
"name": "Psycho",
|
||||||
|
"genre": "Mystery"
|
||||||
|
}`,
|
||||||
|
Output: "map[string]string",
|
||||||
|
ContentType: "application/json",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return movie(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("moviename", Info{
|
||||||
|
Display: "Movie Name",
|
||||||
|
Category: "movie",
|
||||||
|
Description: "Title or name of a specific film used for identification and reference",
|
||||||
|
Example: "The Matrix",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return movieName(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("moviegenre", Info{
|
||||||
|
Display: "Genre",
|
||||||
|
Category: "movie",
|
||||||
|
Description: "Category that classifies movies based on common themes, styles, and storytelling approaches",
|
||||||
|
Example: "Action",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return movieGenre(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,703 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math"
|
||||||
|
"math/bits"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Number will generate a random number between given min and max
|
||||||
|
func Number(min int, max int) int { return number(GlobalFaker, min, max) }
|
||||||
|
|
||||||
|
// Number will generate a random number between given min and max
|
||||||
|
func (f *Faker) Number(min int, max int) int { return number(f, min, max) }
|
||||||
|
|
||||||
|
func number(f *Faker, min int, max int) int { return randIntRange(f, min, max) }
|
||||||
|
|
||||||
|
// Uint will generate a random uint value
|
||||||
|
func Uint() uint { return uintFunc(GlobalFaker) }
|
||||||
|
|
||||||
|
// Uint will generate a random uint value
|
||||||
|
func (f *Faker) Uint() uint { return uintFunc(f) }
|
||||||
|
|
||||||
|
func uintFunc(f *Faker) uint { return uint(f.Uint64()) }
|
||||||
|
|
||||||
|
// UintN will generate a random uint value between 0 and n
|
||||||
|
func UintN(n uint) uint { return uintNFunc(GlobalFaker, n) }
|
||||||
|
|
||||||
|
// UintN will generate a random uint value between 0 and n
|
||||||
|
func (f *Faker) UintN(n uint) uint { return uintNFunc(f, n) }
|
||||||
|
|
||||||
|
func uintNFunc(f *Faker, n uint) uint {
|
||||||
|
if n == 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return uint(uint64NFunc(f, uint64(n)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Uint8 will generate a random uint8 value
|
||||||
|
func Uint8() uint8 { return uint8Func(GlobalFaker) }
|
||||||
|
|
||||||
|
// Uint8 will generate a random uint8 value
|
||||||
|
func (f *Faker) Uint8() uint8 { return uint8Func(f) }
|
||||||
|
|
||||||
|
func uint8Func(f *Faker) uint8 { return uint8(randIntRange(f, minUint, math.MaxUint8)) }
|
||||||
|
|
||||||
|
// Uint16 will generate a random uint16 value
|
||||||
|
func Uint16() uint16 { return uint16Func(GlobalFaker) }
|
||||||
|
|
||||||
|
// Uint16 will generate a random uint16 value
|
||||||
|
func (f *Faker) Uint16() uint16 { return uint16Func(f) }
|
||||||
|
|
||||||
|
func uint16Func(f *Faker) uint16 { return uint16(randIntRange(f, minUint, math.MaxUint16)) }
|
||||||
|
|
||||||
|
// Uint32 will generate a random uint32 value
|
||||||
|
func Uint32() uint32 { return uint32Func(GlobalFaker) }
|
||||||
|
|
||||||
|
// Uint32 will generate a random uint32 value
|
||||||
|
func (f *Faker) Uint32() uint32 { return uint32Func(f) }
|
||||||
|
|
||||||
|
func uint32Func(f *Faker) uint32 { return uint32(f.Uint64() >> 32) }
|
||||||
|
|
||||||
|
// Uint64 will generate a random uint64 value
|
||||||
|
func Uint64() uint64 { return GlobalFaker.Uint64() }
|
||||||
|
|
||||||
|
// Uint64 will generate a random uint64 value
|
||||||
|
// This is the primary location in which the random number is generated.
|
||||||
|
// This will be the only location in which reading from Rand.Uint64() is lockable
|
||||||
|
func (f *Faker) Uint64() uint64 {
|
||||||
|
// Check if the source is locked
|
||||||
|
if f.Locked {
|
||||||
|
// Lock the source
|
||||||
|
f.mu.Lock()
|
||||||
|
defer f.mu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
return f.Rand.Uint64()
|
||||||
|
}
|
||||||
|
|
||||||
|
// uint64n is the no-bounds-checks version of Uint64N.
|
||||||
|
// See https://cs.opensource.google/go/go/+/refs/tags/go1.22.0:src/math/rand/v2/rand.go;l=78
|
||||||
|
// hidden as to not clutter with additional N functions
|
||||||
|
func uint64NFunc(f *Faker, n uint64) uint64 {
|
||||||
|
if is32bit && uint64(uint32(n)) == n {
|
||||||
|
// create reusable function here
|
||||||
|
uint32NFunc := func(f *Faker, n uint32) uint32 {
|
||||||
|
if n&(n-1) == 0 { // n is power of two, can mask
|
||||||
|
return uint32(f.Uint64()) & (n - 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
x := f.Uint64()
|
||||||
|
lo1a, lo0 := bits.Mul32(uint32(x), n)
|
||||||
|
hi, lo1b := bits.Mul32(uint32(x>>32), n)
|
||||||
|
lo1, c := bits.Add32(lo1a, lo1b, 0)
|
||||||
|
hi += c
|
||||||
|
if lo1 == 0 && lo0 < uint32(n) {
|
||||||
|
n64 := uint64(n)
|
||||||
|
thresh := uint32(-n64 % n64)
|
||||||
|
for lo1 == 0 && lo0 < thresh {
|
||||||
|
x := f.Uint64()
|
||||||
|
lo1a, lo0 = bits.Mul32(uint32(x), n)
|
||||||
|
hi, lo1b = bits.Mul32(uint32(x>>32), n)
|
||||||
|
lo1, c = bits.Add32(lo1a, lo1b, 0)
|
||||||
|
hi += c
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return hi
|
||||||
|
}
|
||||||
|
|
||||||
|
return uint64(uint32NFunc(f, uint32(n)))
|
||||||
|
}
|
||||||
|
if n&(n-1) == 0 { // n is power of two, can mask
|
||||||
|
return f.Uint64() & (n - 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
hi, lo := bits.Mul64(f.Uint64(), n)
|
||||||
|
if lo < n {
|
||||||
|
thresh := -n % n
|
||||||
|
for lo < thresh {
|
||||||
|
hi, lo = bits.Mul64(f.Uint64(), n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return hi
|
||||||
|
}
|
||||||
|
|
||||||
|
// UintRange will generate a random uint value between min and max
|
||||||
|
func UintRange(min, max uint) uint { return uintRangeFunc(GlobalFaker, min, max) }
|
||||||
|
|
||||||
|
// UintRange will generate a random uint value between min and max
|
||||||
|
func (f *Faker) UintRange(min, max uint) uint { return uintRangeFunc(f, min, max) }
|
||||||
|
|
||||||
|
func uintRangeFunc(f *Faker, min, max uint) uint { return randUintRange(f, min, max) }
|
||||||
|
|
||||||
|
// Int will generate a random int value
|
||||||
|
func Int() int { return intFunc(GlobalFaker) }
|
||||||
|
|
||||||
|
// Int will generate a random int value
|
||||||
|
func (f *Faker) Int() int { return intFunc(f) }
|
||||||
|
|
||||||
|
func intFunc(f *Faker) int { return int(uint(f.Uint64()) << 1 >> 1) }
|
||||||
|
|
||||||
|
// IntN will generate a random int value between 0 and n
|
||||||
|
func IntN(n int) int { return intNFunc(GlobalFaker, n) }
|
||||||
|
|
||||||
|
// IntN will generate a random int value between 0 and n
|
||||||
|
func (f *Faker) IntN(n int) int { return intNFunc(f, n) }
|
||||||
|
|
||||||
|
func intNFunc(f *Faker, n int) int {
|
||||||
|
if n <= 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return int(uint64NFunc(f, uint64(n)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int8 will generate a random Int8 value
|
||||||
|
func Int8() int8 { return int8Func(GlobalFaker) }
|
||||||
|
|
||||||
|
// Int8 will generate a random Int8 value
|
||||||
|
func (f *Faker) Int8() int8 { return int8Func(f) }
|
||||||
|
|
||||||
|
func int8Func(f *Faker) int8 { return int8(randIntRange(f, math.MinInt8, math.MaxInt8)) }
|
||||||
|
|
||||||
|
// Int16 will generate a random int16 value
|
||||||
|
func Int16() int16 { return int16Func(GlobalFaker) }
|
||||||
|
|
||||||
|
// Int16 will generate a random int16 value
|
||||||
|
func (f *Faker) Int16() int16 { return int16Func(f) }
|
||||||
|
|
||||||
|
func int16Func(f *Faker) int16 { return int16(randIntRange(f, math.MinInt16, math.MaxInt16)) }
|
||||||
|
|
||||||
|
// Int32 will generate a random int32 value
|
||||||
|
func Int32() int32 { return int32Func(GlobalFaker) }
|
||||||
|
|
||||||
|
// Int32 will generate a random int32 value
|
||||||
|
func (f *Faker) Int32() int32 { return int32Func(f) }
|
||||||
|
|
||||||
|
func int32Func(f *Faker) int32 { return int32(f.Uint64() >> 33) }
|
||||||
|
|
||||||
|
// int32n is an identical computation to int64n
|
||||||
|
// hidden as to not clutter with additional N functions
|
||||||
|
func int32NFunc(f *Faker, n int32) int32 {
|
||||||
|
if n <= 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return int32(uint64NFunc(f, uint64(n)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int64 will generate a random int64 value
|
||||||
|
func Int64() int64 { return int64Func(GlobalFaker) }
|
||||||
|
|
||||||
|
// Int64 will generate a random int64 value
|
||||||
|
func (f *Faker) Int64() int64 { return int64Func(f) }
|
||||||
|
|
||||||
|
func int64Func(f *Faker) int64 { return int64(f.Uint64() &^ (1 << 63)) }
|
||||||
|
|
||||||
|
// IntRange will generate a random int value between min and max
|
||||||
|
func IntRange(min, max int) int { return intRangeFunc(GlobalFaker, min, max) }
|
||||||
|
|
||||||
|
// IntRange will generate a random int value between min and max
|
||||||
|
func (f *Faker) IntRange(min, max int) int { return intRangeFunc(f, min, max) }
|
||||||
|
|
||||||
|
func intRangeFunc(f *Faker, min, max int) int { return randIntRange(f, min, max) }
|
||||||
|
|
||||||
|
// Float32 will generate a random float32 value
|
||||||
|
func Float32() float32 { return float32Func(GlobalFaker) }
|
||||||
|
|
||||||
|
// Float32 will generate a random float32 value
|
||||||
|
func (f *Faker) Float32() float32 { return float32Func(f) }
|
||||||
|
|
||||||
|
func float32Func(f *Faker) float32 {
|
||||||
|
// There are exactly 1<<24 float32s in [0,1). Use Intn(1<<24) / (1<<24).
|
||||||
|
return float32(f.Uint32()<<8>>8) / (1 << 24)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float32Range will generate a random float32 value between min and max
|
||||||
|
func Float32Range(min, max float32) float32 {
|
||||||
|
return float32Range(GlobalFaker, min, max)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float32Range will generate a random float32 value between min and max
|
||||||
|
func (f *Faker) Float32Range(min, max float32) float32 {
|
||||||
|
return float32Range(f, min, max)
|
||||||
|
}
|
||||||
|
|
||||||
|
func float32Range(f *Faker, min, max float32) float32 {
|
||||||
|
if min == max {
|
||||||
|
return min
|
||||||
|
}
|
||||||
|
return f.Float32()*(max-min) + min
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64 will generate a random float64 value
|
||||||
|
func Float64() float64 {
|
||||||
|
return float64Func(GlobalFaker)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64 will generate a random float64 value
|
||||||
|
func (f *Faker) Float64() float64 {
|
||||||
|
return float64Func(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func float64Func(f *Faker) float64 {
|
||||||
|
// There are exactly 1<<53 float64s in [0,1). Use Intn(1<<53) / (1<<53).
|
||||||
|
return float64(f.Uint64()<<11>>11) / (1 << 53)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64Range will generate a random float64 value between min and max
|
||||||
|
func Float64Range(min, max float64) float64 {
|
||||||
|
return float64Range(GlobalFaker, min, max)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64Range will generate a random float64 value between min and max
|
||||||
|
func (f *Faker) Float64Range(min, max float64) float64 {
|
||||||
|
return float64Range(f, min, max)
|
||||||
|
}
|
||||||
|
|
||||||
|
func float64Range(f *Faker, min, max float64) float64 {
|
||||||
|
if min == max {
|
||||||
|
return min
|
||||||
|
}
|
||||||
|
return f.Float64()*(max-min) + min
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShuffleInts will randomize a slice of ints
|
||||||
|
func ShuffleInts(a []int) { shuffleInts(GlobalFaker, a) }
|
||||||
|
|
||||||
|
// ShuffleInts will randomize a slice of ints
|
||||||
|
func (f *Faker) ShuffleInts(a []int) { shuffleInts(f, a) }
|
||||||
|
|
||||||
|
func shuffleInts(f *Faker, a []int) {
|
||||||
|
for i := range a {
|
||||||
|
j := f.IntN(i + 1)
|
||||||
|
a[i], a[j] = a[j], a[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// RandomInt will take in a slice of int and return a randomly selected value
|
||||||
|
func RandomInt(i []int) int { return randomInt(GlobalFaker, i) }
|
||||||
|
|
||||||
|
// RandomInt will take in a slice of int and return a randomly selected value
|
||||||
|
func (f *Faker) RandomInt(i []int) int { return randomInt(f, i) }
|
||||||
|
|
||||||
|
func randomInt(f *Faker, i []int) int {
|
||||||
|
size := len(i)
|
||||||
|
if size == 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
if size == 1 {
|
||||||
|
return i[0]
|
||||||
|
}
|
||||||
|
return i[f.IntN(size)]
|
||||||
|
}
|
||||||
|
|
||||||
|
// RandomUint will take in a slice of uint and return a randomly selected value
|
||||||
|
func RandomUint(u []uint) uint { return randomUint(GlobalFaker, u) }
|
||||||
|
|
||||||
|
// RandomUint will take in a slice of uint and return a randomly selected value
|
||||||
|
func (f *Faker) RandomUint(u []uint) uint { return randomUint(f, u) }
|
||||||
|
|
||||||
|
func randomUint(f *Faker, u []uint) uint {
|
||||||
|
size := len(u)
|
||||||
|
if size == 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
if size == 1 {
|
||||||
|
return u[0]
|
||||||
|
}
|
||||||
|
return u[f.IntN(size)]
|
||||||
|
}
|
||||||
|
|
||||||
|
// HexUint will generate a random uint hex value with "0x" prefix
|
||||||
|
func HexUint(bitSize int) string { return hexUint(GlobalFaker, bitSize) }
|
||||||
|
|
||||||
|
// HexUint will generate a random uint hex value with "0x" prefix
|
||||||
|
func (f *Faker) HexUint(bitSize int) string { return hexUint(f, bitSize) }
|
||||||
|
|
||||||
|
func hexUint(f *Faker, bitSize int) string {
|
||||||
|
digits := []byte("0123456789abcdef")
|
||||||
|
hexLen := (bitSize >> 2) + 2
|
||||||
|
if hexLen <= 2 {
|
||||||
|
return "0x"
|
||||||
|
}
|
||||||
|
|
||||||
|
s := make([]byte, hexLen)
|
||||||
|
s[0], s[1] = '0', 'x'
|
||||||
|
for i := 2; i < hexLen; i++ {
|
||||||
|
s[i] = digits[f.IntN(16)]
|
||||||
|
}
|
||||||
|
return string(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
func addNumberLookup() {
|
||||||
|
AddFuncLookup("number", Info{
|
||||||
|
Display: "Number",
|
||||||
|
Category: "number",
|
||||||
|
Description: "Mathematical concept used for counting, measuring, and expressing quantities or values",
|
||||||
|
Example: "14866",
|
||||||
|
Output: "int",
|
||||||
|
Params: []Param{
|
||||||
|
{Field: "min", Display: "Min", Type: "int", Default: "-2147483648", Description: "Minimum integer value"},
|
||||||
|
{Field: "max", Display: "Max", Type: "int", Default: "2147483647", Description: "Maximum integer value"},
|
||||||
|
},
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
min, err := info.GetInt(m, "min")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
max, err := info.GetInt(m, "max")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return number(f, min, max), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("uint", Info{
|
||||||
|
Display: "Uint",
|
||||||
|
Category: "number",
|
||||||
|
Description: "Unsigned integer",
|
||||||
|
Example: "14866",
|
||||||
|
Output: "uint",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return uintFunc(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("uintn", Info{
|
||||||
|
Display: "UintN",
|
||||||
|
Category: "number",
|
||||||
|
Description: "Unsigned integer between 0 and n",
|
||||||
|
Example: "32783",
|
||||||
|
Output: "uint",
|
||||||
|
Params: []Param{
|
||||||
|
{Field: "n", Display: "N", Type: "uint", Default: "4294967295", Description: "Maximum uint value"},
|
||||||
|
},
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
n, err := info.GetUint(m, "n")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return uintNFunc(f, n), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("uint8", Info{
|
||||||
|
Display: "Uint8",
|
||||||
|
Category: "number",
|
||||||
|
Description: "Unsigned 8-bit integer, capable of representing values from 0 to 255",
|
||||||
|
Example: "152",
|
||||||
|
Output: "uint8",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return uint8Func(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("uint16", Info{
|
||||||
|
Display: "Uint16",
|
||||||
|
Category: "number",
|
||||||
|
Description: "Unsigned 16-bit integer, capable of representing values from 0 to 65,535",
|
||||||
|
Example: "34968",
|
||||||
|
Output: "uint16",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return uint16Func(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("uint32", Info{
|
||||||
|
Display: "Uint32",
|
||||||
|
Category: "number",
|
||||||
|
Description: "Unsigned 32-bit integer, capable of representing values from 0 to 4,294,967,295",
|
||||||
|
Example: "1075055705",
|
||||||
|
Output: "uint32",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return uint32Func(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("uint64", Info{
|
||||||
|
Display: "Uint64",
|
||||||
|
Category: "number",
|
||||||
|
Description: "Unsigned 64-bit integer, capable of representing values from 0 to 18,446,744,073,709,551,615",
|
||||||
|
Example: "843730692693298265",
|
||||||
|
Output: "uint64",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return f.Uint64(), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("uintrange", Info{
|
||||||
|
Display: "UintRange",
|
||||||
|
Category: "number",
|
||||||
|
Description: "Non-negative integer value between given range",
|
||||||
|
Example: "1075055705",
|
||||||
|
Output: "uint",
|
||||||
|
Params: []Param{
|
||||||
|
{Field: "min", Display: "Min", Type: "uint", Default: "0", Description: "Minimum uint value"},
|
||||||
|
{Field: "max", Display: "Max", Type: "uint", Default: "4294967295", Description: "Maximum uint value"},
|
||||||
|
},
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
min, err := info.GetUint(m, "min")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
max, err := info.GetUint(m, "max")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return uintRangeFunc(f, min, max), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("int", Info{
|
||||||
|
Display: "Int",
|
||||||
|
Category: "number",
|
||||||
|
Description: "Signed integer",
|
||||||
|
Example: "14866",
|
||||||
|
Output: "int",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return intFunc(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("intn", Info{
|
||||||
|
Display: "IntN",
|
||||||
|
Category: "number",
|
||||||
|
Description: "Integer value between 0 and n",
|
||||||
|
Example: "32783",
|
||||||
|
Output: "int",
|
||||||
|
Params: []Param{
|
||||||
|
{Field: "n", Display: "N", Type: "int", Default: "2147483647", Description: "Maximum int value"},
|
||||||
|
},
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
n, err := info.GetInt(m, "n")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return intNFunc(f, n), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("int8", Info{
|
||||||
|
Display: "Int8",
|
||||||
|
Category: "number",
|
||||||
|
Description: "Signed 8-bit integer, capable of representing values from -128 to 127",
|
||||||
|
Example: "24",
|
||||||
|
Output: "int8",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return int8Func(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("int16", Info{
|
||||||
|
Display: "Int16",
|
||||||
|
Category: "number",
|
||||||
|
Description: "Signed 16-bit integer, capable of representing values from 32,768 to 32,767",
|
||||||
|
Example: "2200",
|
||||||
|
Output: "int16",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return int16Func(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("int32", Info{
|
||||||
|
Display: "Int32",
|
||||||
|
Category: "number",
|
||||||
|
Description: "Signed 32-bit integer, capable of representing values from -2,147,483,648 to 2,147,483,647",
|
||||||
|
Example: "-1072427943",
|
||||||
|
Output: "int32",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return int32Func(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("int64", Info{
|
||||||
|
Display: "Int64",
|
||||||
|
Category: "number",
|
||||||
|
Description: "Signed 64-bit integer, capable of representing values from -9,223,372,036,854,775,808 to -9,223,372,036,854,775,807",
|
||||||
|
Example: "-8379641344161477543",
|
||||||
|
Output: "int64",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return int64Func(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("intrange", Info{
|
||||||
|
Display: "IntRange",
|
||||||
|
Category: "number",
|
||||||
|
Description: "Integer value between given range",
|
||||||
|
Example: "-8379477543",
|
||||||
|
Output: "int",
|
||||||
|
Params: []Param{
|
||||||
|
{Field: "min", Display: "Min", Type: "int", Description: "Minimum int value"},
|
||||||
|
{Field: "max", Display: "Max", Type: "int", Description: "Maximum int value"},
|
||||||
|
},
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
min, err := info.GetInt(m, "min")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
max, err := info.GetInt(m, "max")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return intRangeFunc(f, min, max), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("float32", Info{
|
||||||
|
Display: "Float32",
|
||||||
|
Category: "number",
|
||||||
|
Description: "Data type representing floating-point numbers with 32 bits of precision in computing",
|
||||||
|
Example: "3.1128167e+37",
|
||||||
|
Output: "float32",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return float32Func(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("float32range", Info{
|
||||||
|
Display: "Float32 Range",
|
||||||
|
Category: "number",
|
||||||
|
Description: "Float32 value between given range",
|
||||||
|
Example: "914774.6",
|
||||||
|
Output: "float32",
|
||||||
|
Params: []Param{
|
||||||
|
{Field: "min", Display: "Min", Type: "float", Description: "Minimum float32 value"},
|
||||||
|
{Field: "max", Display: "Max", Type: "float", Description: "Maximum float32 value"},
|
||||||
|
},
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
min, err := info.GetFloat32(m, "min")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
max, err := info.GetFloat32(m, "max")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return float32Range(f, min, max), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("float64", Info{
|
||||||
|
Display: "Float64",
|
||||||
|
Category: "number",
|
||||||
|
Description: "Data type representing floating-point numbers with 64 bits of precision in computing",
|
||||||
|
Example: "1.644484108270445e+307",
|
||||||
|
Output: "float64",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return float64Func(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("float64range", Info{
|
||||||
|
Display: "Float64 Range",
|
||||||
|
Category: "number",
|
||||||
|
Description: "Float64 value between given range",
|
||||||
|
Example: "914774.5585333086",
|
||||||
|
Output: "float64",
|
||||||
|
Params: []Param{
|
||||||
|
{Field: "min", Display: "Min", Type: "float", Description: "Minimum float64 value"},
|
||||||
|
{Field: "max", Display: "Max", Type: "float", Description: "Maximum float64 value"},
|
||||||
|
},
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
min, err := info.GetFloat64(m, "min")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
max, err := info.GetFloat64(m, "max")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return float64Range(f, min, max), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("shuffleints", Info{
|
||||||
|
Display: "Shuffle Ints",
|
||||||
|
Category: "number",
|
||||||
|
Description: "Shuffles an array of ints",
|
||||||
|
Example: "1,2,3,4 => 3,1,4,2",
|
||||||
|
Output: "[]int",
|
||||||
|
Params: []Param{
|
||||||
|
{Field: "ints", Display: "Integers", Type: "[]int", Description: "Delimited separated integers"},
|
||||||
|
},
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
ints, err := info.GetIntArray(m, "ints")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
shuffleInts(f, ints)
|
||||||
|
|
||||||
|
return ints, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("randomint", Info{
|
||||||
|
Display: "Random Int",
|
||||||
|
Category: "number",
|
||||||
|
Description: "Randomly selected value from a slice of int",
|
||||||
|
Example: "-1,2,-3,4 => -3",
|
||||||
|
Output: "int",
|
||||||
|
Params: []Param{
|
||||||
|
{Field: "ints", Display: "Integers", Type: "[]int", Description: "Delimited separated integers"},
|
||||||
|
},
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
ints, err := info.GetIntArray(m, "ints")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return randomInt(f, ints), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("randomuint", Info{
|
||||||
|
Display: "Random Uint",
|
||||||
|
Category: "number",
|
||||||
|
Description: "Randomly selected value from a slice of uint",
|
||||||
|
Example: "1,2,3,4 => 4",
|
||||||
|
Output: "uint",
|
||||||
|
Params: []Param{
|
||||||
|
{Field: "uints", Display: "Unsigned Integers", Type: "[]uint", Description: "Delimited separated unsigned integers"},
|
||||||
|
},
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
uints, err := info.GetUintArray(m, "uints")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return randomUint(f, uints), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("hexuint", Info{
|
||||||
|
Display: "HexUint",
|
||||||
|
Category: "number",
|
||||||
|
Description: "Hexadecimal representation of an unsigned integer",
|
||||||
|
Example: "0x87",
|
||||||
|
Output: "string",
|
||||||
|
Params: []Param{
|
||||||
|
{Field: "bitSize", Display: "Bit Size", Type: "int", Default: "8", Description: "Bit size of the unsigned integer"},
|
||||||
|
},
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
bitSize, err := info.GetInt(m, "bitSize")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return hexUint(f, bitSize), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,443 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/brianvoe/gofakeit/v7/data"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CurrencyInfo is a struct of currency information
|
||||||
|
type CurrencyInfo struct {
|
||||||
|
Short string `json:"short" xml:"short"`
|
||||||
|
Long string `json:"long" xml:"long"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Currency will generate a struct with random currency information
|
||||||
|
func Currency() *CurrencyInfo { return currency(GlobalFaker) }
|
||||||
|
|
||||||
|
// Currency will generate a struct with random currency information
|
||||||
|
func (f *Faker) Currency() *CurrencyInfo { return currency(f) }
|
||||||
|
|
||||||
|
func currency(f *Faker) *CurrencyInfo {
|
||||||
|
index := f.IntN(len(data.Data["currency"]["short"]))
|
||||||
|
return &CurrencyInfo{
|
||||||
|
Short: data.Data["currency"]["short"][index],
|
||||||
|
Long: data.Data["currency"]["long"][index],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CurrencyShort will generate a random short currency value
|
||||||
|
func CurrencyShort() string { return currencyShort(GlobalFaker) }
|
||||||
|
|
||||||
|
// CurrencyShort will generate a random short currency value
|
||||||
|
func (f *Faker) CurrencyShort() string { return currencyShort(f) }
|
||||||
|
|
||||||
|
func currencyShort(f *Faker) string { return getRandValue(f, []string{"currency", "short"}) }
|
||||||
|
|
||||||
|
// CurrencyLong will generate a random long currency name
|
||||||
|
func CurrencyLong() string { return currencyLong(GlobalFaker) }
|
||||||
|
|
||||||
|
// CurrencyLong will generate a random long currency name
|
||||||
|
func (f *Faker) CurrencyLong() string { return currencyLong(f) }
|
||||||
|
|
||||||
|
func currencyLong(f *Faker) string { return getRandValue(f, []string{"currency", "long"}) }
|
||||||
|
|
||||||
|
// Price will take in a min and max value and return a formatted price
|
||||||
|
func Price(min, max float64) float64 { return price(GlobalFaker, min, max) }
|
||||||
|
|
||||||
|
// Price will take in a min and max value and return a formatted price
|
||||||
|
func (f *Faker) Price(min, max float64) float64 { return price(f, min, max) }
|
||||||
|
|
||||||
|
func price(f *Faker, min, max float64) float64 {
|
||||||
|
return math.Floor(float64Range(f, min, max)*100) / 100
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreditCardInfo is a struct containing credit variables
|
||||||
|
type CreditCardInfo struct {
|
||||||
|
Type string `json:"type" xml:"type"`
|
||||||
|
Number string `json:"number" xml:"number"`
|
||||||
|
Exp string `json:"exp" xml:"exp"`
|
||||||
|
Cvv string `json:"cvv" xml:"cvv"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreditCard will generate a struct full of credit card information
|
||||||
|
func CreditCard() *CreditCardInfo { return creditCard(GlobalFaker) }
|
||||||
|
|
||||||
|
// CreditCard will generate a struct full of credit card information
|
||||||
|
func (f *Faker) CreditCard() *CreditCardInfo { return creditCard(f) }
|
||||||
|
|
||||||
|
func creditCard(f *Faker) *CreditCardInfo {
|
||||||
|
ccType := randomString(f, data.CreditCardTypes)
|
||||||
|
ccv, _ := generate(f, strings.Repeat("#", int(data.CreditCards[randomString(f, data.CreditCardTypes)].Code.Size)))
|
||||||
|
|
||||||
|
return &CreditCardInfo{
|
||||||
|
Type: data.CreditCards[randomString(f, data.CreditCardTypes)].Display,
|
||||||
|
Number: creditCardNumber(f, &CreditCardOptions{Types: []string{ccType}}),
|
||||||
|
Exp: creditCardExp(f),
|
||||||
|
Cvv: ccv,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreditCardType will generate a random credit card type string
|
||||||
|
func CreditCardType() string { return creditCardType(GlobalFaker) }
|
||||||
|
|
||||||
|
// CreditCardType will generate a random credit card type string
|
||||||
|
func (f *Faker) CreditCardType() string { return creditCardType(f) }
|
||||||
|
|
||||||
|
func creditCardType(f *Faker) string {
|
||||||
|
return data.CreditCards[randomString(f, data.CreditCardTypes)].Display
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreditCardOptions is the options for credit card number
|
||||||
|
type CreditCardOptions struct {
|
||||||
|
Types []string `json:"types"`
|
||||||
|
Bins []string `json:"bins"` // optional parameter of prepended numbers
|
||||||
|
Gaps bool `json:"gaps"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreditCardNumber will generate a random luhn credit card number
|
||||||
|
func CreditCardNumber(cco *CreditCardOptions) string { return creditCardNumber(GlobalFaker, cco) }
|
||||||
|
|
||||||
|
// CreditCardNumber will generate a random luhn credit card number
|
||||||
|
func (f *Faker) CreditCardNumber(cco *CreditCardOptions) string { return creditCardNumber(f, cco) }
|
||||||
|
|
||||||
|
func creditCardNumber(f *Faker, cco *CreditCardOptions) string {
|
||||||
|
if cco == nil {
|
||||||
|
cco = &CreditCardOptions{}
|
||||||
|
}
|
||||||
|
if cco.Types == nil || len(cco.Types) == 0 {
|
||||||
|
cco.Types = data.CreditCardTypes
|
||||||
|
}
|
||||||
|
ccType := randomString(f, cco.Types)
|
||||||
|
|
||||||
|
// Get Card info
|
||||||
|
var cardInfo data.CreditCardInfo
|
||||||
|
if info, ok := data.CreditCards[ccType]; ok {
|
||||||
|
cardInfo = info
|
||||||
|
} else {
|
||||||
|
ccType = randomString(f, data.CreditCardTypes)
|
||||||
|
cardInfo = data.CreditCards[ccType]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get length and pattern
|
||||||
|
length := randomUint(f, cardInfo.Lengths)
|
||||||
|
numStr := ""
|
||||||
|
if len(cco.Bins) >= 1 {
|
||||||
|
numStr = randomString(f, cco.Bins)
|
||||||
|
} else {
|
||||||
|
numStr = strconv.FormatUint(uint64(randomUint(f, cardInfo.Patterns)), 10)
|
||||||
|
}
|
||||||
|
numStr += strings.Repeat("#", int(length)-len(numStr))
|
||||||
|
numStr = numerify(f, numStr)
|
||||||
|
ui, _ := strconv.ParseUint(numStr, 10, 64)
|
||||||
|
|
||||||
|
// Loop through until its a valid luhn
|
||||||
|
for {
|
||||||
|
valid := isLuhn(strconv.FormatUint(ui, 10))
|
||||||
|
if valid {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
ui++
|
||||||
|
}
|
||||||
|
numStr = strconv.FormatUint(ui, 10)
|
||||||
|
|
||||||
|
// Add gaps to number
|
||||||
|
if cco.Gaps {
|
||||||
|
for i, spot := range cardInfo.Gaps {
|
||||||
|
numStr = numStr[:(int(spot)+i)] + " " + numStr[(int(spot)+i):]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return numStr
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreditCardExp will generate a random credit card expiration date string
|
||||||
|
// Exp date will always be a future date
|
||||||
|
func CreditCardExp() string { return creditCardExp(GlobalFaker) }
|
||||||
|
|
||||||
|
// CreditCardExp will generate a random credit card expiration date string
|
||||||
|
// Exp date will always be a future date
|
||||||
|
func (f *Faker) CreditCardExp() string { return creditCardExp(f) }
|
||||||
|
|
||||||
|
func creditCardExp(f *Faker) string {
|
||||||
|
month := strconv.Itoa(randIntRange(f, 1, 12))
|
||||||
|
if len(month) == 1 {
|
||||||
|
month = "0" + month
|
||||||
|
}
|
||||||
|
|
||||||
|
var currentYear = time.Now().Year() - 2000
|
||||||
|
return month + "/" + strconv.Itoa(randIntRange(f, currentYear+1, currentYear+10))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreditCardCvv will generate a random CVV number
|
||||||
|
// Its a string because you could have 017 as an exp date
|
||||||
|
func CreditCardCvv() string { return creditCardCvv(GlobalFaker) }
|
||||||
|
|
||||||
|
// CreditCardCvv will generate a random CVV number
|
||||||
|
// Its a string because you could have 017 as an exp date
|
||||||
|
func (f *Faker) CreditCardCvv() string { return creditCardCvv(f) }
|
||||||
|
|
||||||
|
func creditCardCvv(f *Faker) string { return numerify(f, "###") }
|
||||||
|
|
||||||
|
// isLuhn check is used for checking if credit card is a valid luhn card
|
||||||
|
func isLuhn(s string) bool {
|
||||||
|
var t = [...]int{0, 2, 4, 6, 8, 1, 3, 5, 7, 9}
|
||||||
|
odd := len(s) & 1
|
||||||
|
var sum int
|
||||||
|
for i, c := range s {
|
||||||
|
if c < '0' || c > '9' {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if i&1 == odd {
|
||||||
|
sum += t[c-'0']
|
||||||
|
} else {
|
||||||
|
sum += int(c - '0')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sum%10 == 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// AchRouting will generate a 9 digit routing number
|
||||||
|
func AchRouting() string { return achRouting(GlobalFaker) }
|
||||||
|
|
||||||
|
// AchRouting will generate a 9 digit routing number
|
||||||
|
func (f *Faker) AchRouting() string { return achRouting(f) }
|
||||||
|
|
||||||
|
func achRouting(f *Faker) string { return numerify(f, "#########") }
|
||||||
|
|
||||||
|
// AchAccount will generate a 12 digit account number
|
||||||
|
func AchAccount() string { return achAccount(GlobalFaker) }
|
||||||
|
|
||||||
|
// AchAccount will generate a 12 digit account number
|
||||||
|
func (f *Faker) AchAccount() string { return achAccount(f) }
|
||||||
|
|
||||||
|
func achAccount(f *Faker) string { return numerify(f, "############") }
|
||||||
|
|
||||||
|
// BitcoinAddress will generate a random bitcoin address consisting of numbers, upper and lower characters
|
||||||
|
func BitcoinAddress() string { return bitcoinAddress(GlobalFaker) }
|
||||||
|
|
||||||
|
// BitcoinAddress will generate a random bitcoin address consisting of numbers, upper and lower characters
|
||||||
|
func (f *Faker) BitcoinAddress() string { return bitcoinAddress(f) }
|
||||||
|
|
||||||
|
func bitcoinAddress(f *Faker) string {
|
||||||
|
return randomString(f, []string{"1", "3"}) + password(f, true, true, true, false, false, number(f, 25, 34))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BitcoinPrivateKey will generate a random bitcoin private key base58 consisting of numbers, upper and lower characters
|
||||||
|
func BitcoinPrivateKey() string { return bitcoinPrivateKey(GlobalFaker) }
|
||||||
|
|
||||||
|
// BitcoinPrivateKey will generate a random bitcoin private key base58 consisting of numbers, upper and lower characters
|
||||||
|
func (f *Faker) BitcoinPrivateKey() string { return bitcoinPrivateKey(f) }
|
||||||
|
|
||||||
|
func bitcoinPrivateKey(f *Faker) string {
|
||||||
|
var b strings.Builder
|
||||||
|
for i := 0; i < 49; i++ {
|
||||||
|
b.WriteString(randCharacter(f, base58))
|
||||||
|
}
|
||||||
|
return "5" + randomString(f, []string{"H", "J", "K"}) + b.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func addPaymentLookup() {
|
||||||
|
AddFuncLookup("currency", Info{
|
||||||
|
Display: "Currency",
|
||||||
|
Category: "payment",
|
||||||
|
Description: "Medium of exchange, often in the form of paper money or coins, used for trade and transactions",
|
||||||
|
Example: `{
|
||||||
|
"short": "IQD",
|
||||||
|
"long": "Iraq Dinar"
|
||||||
|
}`,
|
||||||
|
Output: "map[string]string",
|
||||||
|
ContentType: "application/json",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return currency(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("currencyshort", Info{
|
||||||
|
Display: "Currency Short",
|
||||||
|
Category: "payment",
|
||||||
|
Description: "Short 3-letter word used to represent a specific currency",
|
||||||
|
Example: "USD",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return currencyShort(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("currencylong", Info{
|
||||||
|
Display: "Currency Long",
|
||||||
|
Category: "payment",
|
||||||
|
Description: "Complete name of a specific currency used for official identification in financial transactions",
|
||||||
|
Example: "United States Dollar",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return currencyLong(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("price", Info{
|
||||||
|
Display: "Price",
|
||||||
|
Category: "payment",
|
||||||
|
Description: "The amount of money or value assigned to a product, service, or asset in a transaction",
|
||||||
|
Example: "92.26",
|
||||||
|
Output: "float64",
|
||||||
|
Params: []Param{
|
||||||
|
{Field: "min", Display: "Min", Type: "float", Default: "0", Description: "Minimum price value"},
|
||||||
|
{Field: "max", Display: "Max", Type: "float", Default: "1000", Description: "Maximum price value"},
|
||||||
|
},
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
min, err := info.GetFloat64(m, "min")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
max, err := info.GetFloat64(m, "max")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return price(f, min, max), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("creditcard", Info{
|
||||||
|
Display: "Credit Card",
|
||||||
|
Category: "payment",
|
||||||
|
Description: "Plastic card allowing users to make purchases on credit, with payment due at a later date",
|
||||||
|
Example: `{
|
||||||
|
"type": "UnionPay",
|
||||||
|
"number": "4364599489953698",
|
||||||
|
"exp": "02/24",
|
||||||
|
"cvv": "300"
|
||||||
|
}`,
|
||||||
|
Output: "map[string]any",
|
||||||
|
ContentType: "application/json",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return creditCard(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("creditcardtype", Info{
|
||||||
|
Display: "Credit Card Type",
|
||||||
|
Category: "payment",
|
||||||
|
Description: "Classification of credit cards based on the issuing company",
|
||||||
|
Example: "Visa",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return creditCardType(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("creditcardnumber", Info{
|
||||||
|
Display: "Credit Card Number",
|
||||||
|
Category: "payment",
|
||||||
|
Description: "Unique numerical identifier on a credit card used for making electronic payments and transactions",
|
||||||
|
Example: "4136459948995369",
|
||||||
|
Output: "string",
|
||||||
|
Params: []Param{
|
||||||
|
{
|
||||||
|
Field: "types", Display: "Types", Type: "[]string", Default: "all",
|
||||||
|
Options: []string{"visa", "mastercard", "american-express", "diners-club", "discover", "jcb", "unionpay", "maestro", "elo", "hiper", "hipercard"},
|
||||||
|
Description: "A select number of types you want to use when generating a credit card number",
|
||||||
|
},
|
||||||
|
{Field: "bins", Display: "Bins", Type: "[]string", Optional: true, Description: "Optional list of prepended bin numbers to pick from"},
|
||||||
|
{Field: "gaps", Display: "Gaps", Type: "bool", Default: "false", Description: "Whether or not to have gaps in number"},
|
||||||
|
},
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
types, err := info.GetStringArray(m, "types")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(types) == 1 && types[0] == "all" {
|
||||||
|
types = []string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
bins, _ := info.GetStringArray(m, "bins")
|
||||||
|
|
||||||
|
gaps, err := info.GetBool(m, "gaps")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
options := CreditCardOptions{
|
||||||
|
Types: types,
|
||||||
|
Gaps: gaps,
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(bins) >= 1 {
|
||||||
|
options.Bins = bins
|
||||||
|
}
|
||||||
|
|
||||||
|
return creditCardNumber(f, &options), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("creditcardexp", Info{
|
||||||
|
Display: "Credit Card Exp",
|
||||||
|
Category: "payment",
|
||||||
|
Description: "Date when a credit card becomes invalid and cannot be used for transactions",
|
||||||
|
Example: "01/21",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return creditCardExp(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("creditcardcvv", Info{
|
||||||
|
Display: "Credit Card CVV",
|
||||||
|
Category: "payment",
|
||||||
|
Description: "Three or four-digit security code on a credit card used for online and remote transactions",
|
||||||
|
Example: "513",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return creditCardCvv(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("achrouting", Info{
|
||||||
|
Display: "ACH Routing Number",
|
||||||
|
Category: "payment",
|
||||||
|
Description: "Unique nine-digit code used in the U.S. for identifying the bank and processing electronic transactions",
|
||||||
|
Example: "513715684",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return achRouting(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("achaccount", Info{
|
||||||
|
Display: "ACH Account Number",
|
||||||
|
Category: "payment",
|
||||||
|
Description: "A bank account number used for Automated Clearing House transactions and electronic transfers",
|
||||||
|
Example: "491527954328",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return achAccount(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("bitcoinaddress", Info{
|
||||||
|
Display: "Bitcoin Address",
|
||||||
|
Category: "payment",
|
||||||
|
Description: "Cryptographic identifier used to receive, store, and send Bitcoin cryptocurrency in a peer-to-peer network",
|
||||||
|
Example: "1lWLbxojXq6BqWX7X60VkcDIvYA",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return bitcoinAddress(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("bitcoinprivatekey", Info{
|
||||||
|
Display: "Bitcoin Private Key",
|
||||||
|
Category: "payment",
|
||||||
|
Description: "Secret, secure code that allows the owner to access and control their Bitcoin holdings",
|
||||||
|
Example: "5vrbXTADWJ6sQBSYd6lLkG97jljNc0X9VPBvbVqsIH9lWOLcoqg",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return bitcoinPrivateKey(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,423 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PersonInfo is a struct of person information
|
||||||
|
type PersonInfo struct {
|
||||||
|
FirstName string `json:"first_name" xml:"first_name"`
|
||||||
|
LastName string `json:"last_name" xml:"last_name"`
|
||||||
|
Gender string `json:"gender" xml:"gender"`
|
||||||
|
SSN string `json:"ssn" xml:"ssn"`
|
||||||
|
Hobby string `json:"hobby" xml:"hobby"`
|
||||||
|
Job *JobInfo `json:"job" xml:"job"`
|
||||||
|
Address *AddressInfo `json:"address" xml:"address"`
|
||||||
|
Contact *ContactInfo `json:"contact" xml:"contact"`
|
||||||
|
CreditCard *CreditCardInfo `json:"credit_card" xml:"credit_card"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Person will generate a struct with person information
|
||||||
|
func Person() *PersonInfo { return person(GlobalFaker) }
|
||||||
|
|
||||||
|
// Person will generate a struct with person information
|
||||||
|
func (f *Faker) Person() *PersonInfo { return person(f) }
|
||||||
|
|
||||||
|
func person(f *Faker) *PersonInfo {
|
||||||
|
return &PersonInfo{
|
||||||
|
FirstName: firstName(f),
|
||||||
|
LastName: lastName(f),
|
||||||
|
Gender: gender(f),
|
||||||
|
SSN: ssn(f),
|
||||||
|
Hobby: hobby(f),
|
||||||
|
Job: job(f),
|
||||||
|
Address: address(f),
|
||||||
|
Contact: contact(f),
|
||||||
|
CreditCard: creditCard(f),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Name will generate a random First and Last Name
|
||||||
|
func Name() string { return name(GlobalFaker) }
|
||||||
|
|
||||||
|
// Name will generate a random First and Last Name
|
||||||
|
func (f *Faker) Name() string { return name(f) }
|
||||||
|
|
||||||
|
func name(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"person", "first"}) + " " + getRandValue(f, []string{"person", "last"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstName will generate a random first name
|
||||||
|
func FirstName() string { return firstName(GlobalFaker) }
|
||||||
|
|
||||||
|
// FirstName will generate a random first name
|
||||||
|
func (f *Faker) FirstName() string { return firstName(f) }
|
||||||
|
|
||||||
|
func firstName(f *Faker) string { return getRandValue(f, []string{"person", "first"}) }
|
||||||
|
|
||||||
|
// MiddleName will generate a random middle name
|
||||||
|
func MiddleName() string { return middleName(GlobalFaker) }
|
||||||
|
|
||||||
|
// MiddleName will generate a random middle name
|
||||||
|
func (f *Faker) MiddleName() string { return middleName(f) }
|
||||||
|
|
||||||
|
func middleName(f *Faker) string { return getRandValue(f, []string{"person", "middle"}) }
|
||||||
|
|
||||||
|
// LastName will generate a random last name
|
||||||
|
func LastName() string { return lastName(GlobalFaker) }
|
||||||
|
|
||||||
|
// LastName will generate a random last name
|
||||||
|
func (f *Faker) LastName() string { return lastName(f) }
|
||||||
|
|
||||||
|
func lastName(f *Faker) string { return getRandValue(f, []string{"person", "last"}) }
|
||||||
|
|
||||||
|
// NamePrefix will generate a random name prefix
|
||||||
|
func NamePrefix() string { return namePrefix(GlobalFaker) }
|
||||||
|
|
||||||
|
// NamePrefix will generate a random name prefix
|
||||||
|
func (f *Faker) NamePrefix() string { return namePrefix(f) }
|
||||||
|
|
||||||
|
func namePrefix(f *Faker) string { return getRandValue(f, []string{"person", "prefix"}) }
|
||||||
|
|
||||||
|
// NameSuffix will generate a random name suffix
|
||||||
|
func NameSuffix() string { return nameSuffix(GlobalFaker) }
|
||||||
|
|
||||||
|
// NameSuffix will generate a random name suffix
|
||||||
|
func (f *Faker) NameSuffix() string { return nameSuffix(f) }
|
||||||
|
|
||||||
|
func nameSuffix(f *Faker) string { return getRandValue(f, []string{"person", "suffix"}) }
|
||||||
|
|
||||||
|
// SSN will generate a random Social Security Number
|
||||||
|
func SSN() string { return ssn(GlobalFaker) }
|
||||||
|
|
||||||
|
// SSN will generate a random Social Security Number
|
||||||
|
func (f *Faker) SSN() string { return ssn(f) }
|
||||||
|
|
||||||
|
func ssn(f *Faker) string { return strconv.Itoa(randIntRange(f, 100000000, 999999999)) }
|
||||||
|
|
||||||
|
// Gender will generate a random gender string
|
||||||
|
func Gender() string { return gender(GlobalFaker) }
|
||||||
|
|
||||||
|
// Gender will generate a random gender string
|
||||||
|
func (f *Faker) Gender() string { return gender(f) }
|
||||||
|
|
||||||
|
func gender(f *Faker) string {
|
||||||
|
if boolFunc(f) {
|
||||||
|
return "male"
|
||||||
|
}
|
||||||
|
|
||||||
|
return "female"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hobby will generate a random hobby string
|
||||||
|
func Hobby() string { return hobby(GlobalFaker) }
|
||||||
|
|
||||||
|
// Hobby will generate a random hobby string
|
||||||
|
func (f *Faker) Hobby() string { return hobby(f) }
|
||||||
|
|
||||||
|
func hobby(f *Faker) string { return getRandValue(f, []string{"person", "hobby"}) }
|
||||||
|
|
||||||
|
// ContactInfo struct full of contact info
|
||||||
|
type ContactInfo struct {
|
||||||
|
Phone string `json:"phone" xml:"phone"`
|
||||||
|
Email string `json:"email" xml:"email"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Contact will generate a struct with information randomly populated contact information
|
||||||
|
func Contact() *ContactInfo { return contact(GlobalFaker) }
|
||||||
|
|
||||||
|
// Contact will generate a struct with information randomly populated contact information
|
||||||
|
func (f *Faker) Contact() *ContactInfo { return contact(f) }
|
||||||
|
|
||||||
|
func contact(f *Faker) *ContactInfo {
|
||||||
|
return &ContactInfo{
|
||||||
|
Phone: phone(f),
|
||||||
|
Email: email(f),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Phone will generate a random phone number string
|
||||||
|
func Phone() string { return phone(GlobalFaker) }
|
||||||
|
|
||||||
|
// Phone will generate a random phone number string
|
||||||
|
func (f *Faker) Phone() string { return phone(f) }
|
||||||
|
|
||||||
|
func phone(f *Faker) string { return replaceWithNumbers(f, "##########") }
|
||||||
|
|
||||||
|
// PhoneFormatted will generate a random phone number string
|
||||||
|
func PhoneFormatted() string { return phoneFormatted(GlobalFaker) }
|
||||||
|
|
||||||
|
// PhoneFormatted will generate a random phone number string
|
||||||
|
func (f *Faker) PhoneFormatted() string { return phoneFormatted(f) }
|
||||||
|
|
||||||
|
func phoneFormatted(f *Faker) string {
|
||||||
|
return replaceWithNumbers(f, getRandValue(f, []string{"person", "phone"}))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Email will generate a random email string
|
||||||
|
func Email() string { return email(GlobalFaker) }
|
||||||
|
|
||||||
|
// Email will generate a random email string
|
||||||
|
func (f *Faker) Email() string { return email(f) }
|
||||||
|
|
||||||
|
func email(f *Faker) string {
|
||||||
|
email := getRandValue(f, []string{"person", "first"}) + getRandValue(f, []string{"person", "last"})
|
||||||
|
email += "@"
|
||||||
|
email += getRandValue(f, []string{"person", "last"}) + "." + getRandValue(f, []string{"internet", "domain_suffix"})
|
||||||
|
|
||||||
|
return strings.ToLower(email)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Teams takes in an array of people and team names and randomly places the people into teams as evenly as possible
|
||||||
|
func Teams(peopleArray []string, teamsArray []string) map[string][]string {
|
||||||
|
return teams(GlobalFaker, peopleArray, teamsArray)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Teams takes in an array of people and team names and randomly places the people into teams as evenly as possible
|
||||||
|
func (f *Faker) Teams(peopleArray []string, teamsArray []string) map[string][]string {
|
||||||
|
return teams(f, peopleArray, teamsArray)
|
||||||
|
}
|
||||||
|
|
||||||
|
func teams(f *Faker, people []string, teams []string) map[string][]string {
|
||||||
|
// Shuffle the people if more than 1
|
||||||
|
if len(people) > 1 {
|
||||||
|
shuffleStrings(f, people)
|
||||||
|
}
|
||||||
|
|
||||||
|
peopleIndex := 0
|
||||||
|
teamsOutput := make(map[string][]string)
|
||||||
|
numPer := math.Ceil(float64(len(people)) / float64(len(teams)))
|
||||||
|
for _, team := range teams {
|
||||||
|
teamsOutput[team] = []string{}
|
||||||
|
for i := 0.00; i < numPer; i++ {
|
||||||
|
if peopleIndex < len(people) {
|
||||||
|
teamsOutput[team] = append(teamsOutput[team], people[peopleIndex])
|
||||||
|
peopleIndex++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return teamsOutput
|
||||||
|
}
|
||||||
|
|
||||||
|
func addPersonLookup() {
|
||||||
|
AddFuncLookup("person", Info{
|
||||||
|
Display: "Person",
|
||||||
|
Category: "person",
|
||||||
|
Description: "Personal data, like name and contact details, used for identification and communication",
|
||||||
|
Example: `{
|
||||||
|
"first_name": "Markus",
|
||||||
|
"last_name": "Moen",
|
||||||
|
"gender": "male",
|
||||||
|
"ssn": "275413589",
|
||||||
|
"image": "https://picsum.photos/208/500",
|
||||||
|
"hobby": "Lacrosse",
|
||||||
|
"job": {
|
||||||
|
"company": "Intermap Technologies",
|
||||||
|
"title": "Developer",
|
||||||
|
"descriptor": "Direct",
|
||||||
|
"level": "Paradigm"
|
||||||
|
},
|
||||||
|
"address": {
|
||||||
|
"address": "369 North Cornerbury, Miami, North Dakota 24259",
|
||||||
|
"street": "369 North Cornerbury",
|
||||||
|
"city": "Miami",
|
||||||
|
"state": "North Dakota",
|
||||||
|
"zip": "24259",
|
||||||
|
"country": "Ghana",
|
||||||
|
"latitude": -6.662595,
|
||||||
|
"longitude": 23.921575
|
||||||
|
},
|
||||||
|
"contact": {
|
||||||
|
"phone": "3023202027",
|
||||||
|
"email": "lamarkoelpin@heaney.biz"
|
||||||
|
},
|
||||||
|
"credit_card": {
|
||||||
|
"type": "Maestro",
|
||||||
|
"number": "39800889982276",
|
||||||
|
"exp": "01/29",
|
||||||
|
"cvv": "932"
|
||||||
|
}
|
||||||
|
}`,
|
||||||
|
Output: "map[string]any",
|
||||||
|
ContentType: "application/json",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return person(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("name", Info{
|
||||||
|
Display: "Name",
|
||||||
|
Category: "person",
|
||||||
|
Description: "The given and family name of an individual",
|
||||||
|
Example: "Markus Moen",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return name(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("nameprefix", Info{
|
||||||
|
Display: "Name Prefix",
|
||||||
|
Category: "person",
|
||||||
|
Description: "A title or honorific added before a person's name",
|
||||||
|
Example: "Mr.",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return namePrefix(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("namesuffix", Info{
|
||||||
|
Display: "Name Suffix",
|
||||||
|
Category: "person",
|
||||||
|
Description: "A title or designation added after a person's name",
|
||||||
|
Example: "Jr.",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return nameSuffix(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("firstname", Info{
|
||||||
|
Display: "First Name",
|
||||||
|
Category: "person",
|
||||||
|
Description: "The name given to a person at birth",
|
||||||
|
Example: "Markus",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return firstName(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("middlename", Info{
|
||||||
|
Display: "Middle Name",
|
||||||
|
Category: "person",
|
||||||
|
Description: "Name between a person's first name and last name",
|
||||||
|
Example: "Belinda",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return middleName(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("lastname", Info{
|
||||||
|
Display: "Last Name",
|
||||||
|
Category: "person",
|
||||||
|
Description: "The family name or surname of an individual",
|
||||||
|
Example: "Daniel",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return lastName(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("gender", Info{
|
||||||
|
Display: "Gender",
|
||||||
|
Category: "person",
|
||||||
|
Description: "Classification based on social and cultural norms that identifies an individual",
|
||||||
|
Example: "male",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return gender(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("ssn", Info{
|
||||||
|
Display: "SSN",
|
||||||
|
Category: "person",
|
||||||
|
Description: "Unique nine-digit identifier used for government and financial purposes in the United States",
|
||||||
|
Example: "296446360",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return ssn(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("hobby", Info{
|
||||||
|
Display: "Hobby",
|
||||||
|
Category: "person",
|
||||||
|
Description: "An activity pursued for leisure and pleasure",
|
||||||
|
Example: "Swimming",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return hobby(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("email", Info{
|
||||||
|
Display: "Email",
|
||||||
|
Category: "person",
|
||||||
|
Description: "Electronic mail used for sending digital messages and communication over the internet",
|
||||||
|
Example: "markusmoen@pagac.net",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return email(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("phone", Info{
|
||||||
|
Display: "Phone",
|
||||||
|
Category: "person",
|
||||||
|
Description: "Numerical sequence used to contact individuals via telephone or mobile devices",
|
||||||
|
Example: "6136459948",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return phone(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("phoneformatted", Info{
|
||||||
|
Display: "Phone Formatted",
|
||||||
|
Category: "person",
|
||||||
|
Description: "Formatted phone number of a person",
|
||||||
|
Example: "136-459-9489",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return phoneFormatted(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("teams", Info{
|
||||||
|
Display: "Teams",
|
||||||
|
Category: "person",
|
||||||
|
Description: "Randomly split people into teams",
|
||||||
|
Example: `{
|
||||||
|
"Team 1": [
|
||||||
|
"Justin",
|
||||||
|
"Connor",
|
||||||
|
"Jeff"
|
||||||
|
],
|
||||||
|
"Team 2": [
|
||||||
|
"Sharon",
|
||||||
|
"Fabian",
|
||||||
|
"Billy"
|
||||||
|
],
|
||||||
|
"Team 3": [
|
||||||
|
"Steve",
|
||||||
|
"Robert"
|
||||||
|
]
|
||||||
|
}`,
|
||||||
|
Output: "map[string][]string",
|
||||||
|
ContentType: "application/json",
|
||||||
|
Params: []Param{
|
||||||
|
{Field: "people", Display: "Strings", Type: "[]string", Description: "Array of people"},
|
||||||
|
{Field: "teams", Display: "Strings", Type: "[]string", Description: "Array of teams"},
|
||||||
|
},
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
people, err := info.GetStringArray(m, "people")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
teamsArray, err := info.GetStringArray(m, "teams")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return teams(f, people, teamsArray), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,390 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ProductInfo struct {
|
||||||
|
Name string `json:"name" xml:"name"`
|
||||||
|
Description string `json:"description" xml:"description"`
|
||||||
|
Categories []string `json:"categories" xml:"categories"`
|
||||||
|
Price float64 `json:"price" xml:"price"`
|
||||||
|
Features []string `json:"features" xml:"features"`
|
||||||
|
Color string `json:"color" xml:"color"`
|
||||||
|
Material string `json:"material" xml:"material"`
|
||||||
|
UPC string `json:"upc" xml:"upc"`
|
||||||
|
Audience []string `json:"audience" xml:"audience"`
|
||||||
|
Dimension string `json:"dimension" xml:"dimension"`
|
||||||
|
UseCase string `json:"use_case" xml:"use_case"`
|
||||||
|
Benefit string `json:"benefit" xml:"benefit"`
|
||||||
|
Suffix string `json:"suffix" xml:"suffix"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Product will generate a random set of product information
|
||||||
|
func Product() *ProductInfo { return product(GlobalFaker) }
|
||||||
|
|
||||||
|
// Product will generate a random set of product information
|
||||||
|
func (f *Faker) Product() *ProductInfo { return product(f) }
|
||||||
|
|
||||||
|
func product(f *Faker) *ProductInfo {
|
||||||
|
// Categories
|
||||||
|
categories := []string{}
|
||||||
|
weightedCategory, _ := weighted(f, []any{1, 2, 3, 4}, []float32{1, 4, 3, 4})
|
||||||
|
|
||||||
|
for i := 0; i < weightedCategory.(int); i++ {
|
||||||
|
categories = append(categories, productCategory(f))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Features
|
||||||
|
features := []string{}
|
||||||
|
for i := 0; i < number(f, 1, 5); i++ {
|
||||||
|
features = append(features, productFeature(f))
|
||||||
|
}
|
||||||
|
|
||||||
|
product := &ProductInfo{
|
||||||
|
Name: productName(f),
|
||||||
|
Description: productDescription(f),
|
||||||
|
Categories: categories,
|
||||||
|
Price: price(f, 3.00, 100.00),
|
||||||
|
UPC: productUPC(f),
|
||||||
|
Features: features,
|
||||||
|
Color: safeColor(f),
|
||||||
|
Material: productMaterial(f),
|
||||||
|
Audience: productAudience(f),
|
||||||
|
Dimension: productDimension(f),
|
||||||
|
UseCase: productUseCase(f),
|
||||||
|
Benefit: productBenefit(f),
|
||||||
|
Suffix: productSuffix(f),
|
||||||
|
}
|
||||||
|
|
||||||
|
return product
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProductName will generate a random product name
|
||||||
|
func ProductName() string { return productName(GlobalFaker) }
|
||||||
|
|
||||||
|
// ProductName will generate a random product name
|
||||||
|
func (f *Faker) ProductName() string { return productName(f) }
|
||||||
|
|
||||||
|
func productName(f *Faker) string {
|
||||||
|
name := getRandValue(f, []string{"product", "name"})
|
||||||
|
switch number(f, 0, 9) {
|
||||||
|
case 1:
|
||||||
|
// Name + Adjective + Feature
|
||||||
|
return title(fmt.Sprintf("%s %s %s", name, getRandValue(f, []string{"product", "adjective"}), productFeature(f)))
|
||||||
|
case 2:
|
||||||
|
// Adjective + Material + Name
|
||||||
|
return title(fmt.Sprintf("%s %s %s", getRandValue(f, []string{"product", "adjective"}), productMaterial(f), name))
|
||||||
|
case 3:
|
||||||
|
// Color + Name + Suffix
|
||||||
|
return title(fmt.Sprintf("%s %s %s", safeColor(f), name, getRandValue(f, []string{"product", "suffix"})))
|
||||||
|
case 4:
|
||||||
|
// Feature + Name + Adjective
|
||||||
|
return title(fmt.Sprintf("%s %s %s", productFeature(f), name, getRandValue(f, []string{"product", "adjective"})))
|
||||||
|
case 5:
|
||||||
|
// Material + Color + Name
|
||||||
|
return title(fmt.Sprintf("%s %s %s", productMaterial(f), safeColor(f), name))
|
||||||
|
case 6:
|
||||||
|
// Name + Suffix + Material
|
||||||
|
return title(fmt.Sprintf("%s %s %s", name, getRandValue(f, []string{"product", "suffix"}), productMaterial(f)))
|
||||||
|
case 7:
|
||||||
|
// Adjective + Feature + Name
|
||||||
|
return title(fmt.Sprintf("%s %s %s", getRandValue(f, []string{"product", "adjective"}), productFeature(f), name))
|
||||||
|
case 8:
|
||||||
|
// Color + Material + Name
|
||||||
|
return title(fmt.Sprintf("%s %s %s", safeColor(f), productMaterial(f), name))
|
||||||
|
case 9:
|
||||||
|
// Suffix + Adjective + Name
|
||||||
|
return title(fmt.Sprintf("%s %s %s", getRandValue(f, []string{"product", "suffix"}), getRandValue(f, []string{"product", "adjective"}), name))
|
||||||
|
}
|
||||||
|
|
||||||
|
// case: 0 - Adjective + Name + Suffix
|
||||||
|
return title(fmt.Sprintf("%s %s %s", getRandValue(f, []string{"product", "adjective"}), name, getRandValue(f, []string{"product", "suffix"})))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProductDescription will generate a random product description
|
||||||
|
func ProductDescription() string { return productDescription(GlobalFaker) }
|
||||||
|
|
||||||
|
// ProductDescription will generate a random product description
|
||||||
|
func (f *Faker) ProductDescription() string { return productDescription(f) }
|
||||||
|
|
||||||
|
func productDescription(f *Faker) string {
|
||||||
|
prodDesc := getRandValue(f, []string{"product", "description"})
|
||||||
|
|
||||||
|
// Replace all {productaudience} with join "and"
|
||||||
|
for strings.Contains(prodDesc, "{productaudience}") {
|
||||||
|
prodDesc = strings.Replace(prodDesc, "{productaudience}", strings.Join(productAudience(f), " and "), 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
desc, _ := generate(f, prodDesc)
|
||||||
|
return desc
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProductCategory will generate a random product category
|
||||||
|
func ProductCategory() string { return productCategory(GlobalFaker) }
|
||||||
|
|
||||||
|
// ProductCategory will generate a random product category
|
||||||
|
func (f *Faker) ProductCategory() string { return productCategory(f) }
|
||||||
|
|
||||||
|
func productCategory(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"product", "category"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProductFeature will generate a random product feature
|
||||||
|
func ProductFeature() string { return productFeature(GlobalFaker) }
|
||||||
|
|
||||||
|
// ProductFeature will generate a random product feature
|
||||||
|
func (f *Faker) ProductFeature() string { return productFeature(f) }
|
||||||
|
|
||||||
|
func productFeature(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"product", "feature"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProductMaterial will generate a random product material
|
||||||
|
func ProductMaterial() string { return productMaterial(GlobalFaker) }
|
||||||
|
|
||||||
|
// ProductMaterial will generate a random product material
|
||||||
|
func (f *Faker) ProductMaterial() string { return productMaterial(f) }
|
||||||
|
|
||||||
|
func productMaterial(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"product", "material"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProductUPC will generate a random product UPC
|
||||||
|
func ProductUPC() string { return productUPC(GlobalFaker) }
|
||||||
|
|
||||||
|
// ProductUPC will generate a random product UPC
|
||||||
|
func (f *Faker) ProductUPC() string { return productUPC(f) }
|
||||||
|
|
||||||
|
func productUPC(f *Faker) string {
|
||||||
|
// The first digit of a UPC is a fixed digit (usually 0)
|
||||||
|
upc := "0"
|
||||||
|
|
||||||
|
// Generate the remaining 11 digits randomly
|
||||||
|
for i := 1; i < 12; i++ {
|
||||||
|
digit := number(f, 0, 9)
|
||||||
|
upc += fmt.Sprintf("%d", digit)
|
||||||
|
}
|
||||||
|
|
||||||
|
return upc
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProductAudience will generate a random target audience
|
||||||
|
func ProductAudience() []string { return productAudience(GlobalFaker) }
|
||||||
|
|
||||||
|
// ProductAudience will generate a random target audience
|
||||||
|
func (f *Faker) ProductAudience() []string { return productAudience(f) }
|
||||||
|
|
||||||
|
func productAudience(f *Faker) []string {
|
||||||
|
audiences := []string{}
|
||||||
|
for i := 0; i < number(f, 1, 2); i++ {
|
||||||
|
// Check if the target audience is already in the list
|
||||||
|
// If it is, generate a new target audience
|
||||||
|
for {
|
||||||
|
audience := getRandValue(f, []string{"product", "target_audience"})
|
||||||
|
// Check if in array
|
||||||
|
if !stringInSlice(audience, audiences) {
|
||||||
|
audiences = append(audiences, audience)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return audiences
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProductDimension will generate a random product dimension
|
||||||
|
func ProductDimension() string { return productDimension(GlobalFaker) }
|
||||||
|
|
||||||
|
// ProductDimension will generate a random product dimension
|
||||||
|
func (f *Faker) ProductDimension() string { return productDimension(f) }
|
||||||
|
|
||||||
|
func productDimension(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"product", "dimension"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProductUseCase will generate a random product use case
|
||||||
|
func ProductUseCase() string { return productUseCase(GlobalFaker) }
|
||||||
|
|
||||||
|
// ProductUseCase will generate a random product use case
|
||||||
|
func (f *Faker) ProductUseCase() string { return productUseCase(f) }
|
||||||
|
|
||||||
|
func productUseCase(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"product", "use_case"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProductBenefit will generate a random product benefit
|
||||||
|
func ProductBenefit() string { return productBenefit(GlobalFaker) }
|
||||||
|
|
||||||
|
// ProductBenefit will generate a random product benefit
|
||||||
|
func (f *Faker) ProductBenefit() string { return productBenefit(f) }
|
||||||
|
|
||||||
|
func productBenefit(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"product", "benefit"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProductSuffix will generate a random product suffix
|
||||||
|
func ProductSuffix() string { return productSuffix(GlobalFaker) }
|
||||||
|
|
||||||
|
// ProductSuffix will generate a random product suffix
|
||||||
|
func (f *Faker) ProductSuffix() string { return productSuffix(f) }
|
||||||
|
|
||||||
|
func productSuffix(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"product", "suffix"})
|
||||||
|
}
|
||||||
|
|
||||||
|
func addProductLookup() {
|
||||||
|
AddFuncLookup("product", Info{
|
||||||
|
Display: "Product",
|
||||||
|
Category: "product",
|
||||||
|
Description: "An item created for sale or use",
|
||||||
|
Example: `{
|
||||||
|
"name": "olive copper monitor",
|
||||||
|
"description": "Backwards caused quarterly without week it hungry thing someone him regularly. Whomever this revolt hence from his timing as quantity us these yours.",
|
||||||
|
"categories": [
|
||||||
|
"clothing",
|
||||||
|
"tools and hardware"
|
||||||
|
],
|
||||||
|
"price": 7.61,
|
||||||
|
"features": [
|
||||||
|
"ultra-lightweight"
|
||||||
|
],
|
||||||
|
"color": "navy",
|
||||||
|
"material": "brass",
|
||||||
|
"upc": "012780949980",
|
||||||
|
"audience": [
|
||||||
|
"adults"
|
||||||
|
],
|
||||||
|
"dimension": "medium",
|
||||||
|
"use_case": "home",
|
||||||
|
"benefit": "comfort",
|
||||||
|
"suffix": "pro"
|
||||||
|
}`,
|
||||||
|
Output: "map[string]any",
|
||||||
|
ContentType: "application/json",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return product(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("productname", Info{
|
||||||
|
Display: "Product Name",
|
||||||
|
Category: "product",
|
||||||
|
Description: "Distinctive title or label assigned to a product for identification and marketing",
|
||||||
|
Example: "olive copper monitor",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return productName(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("productdescription", Info{
|
||||||
|
Display: "Product Description",
|
||||||
|
Category: "product",
|
||||||
|
Description: "Explanation detailing the features and characteristics of a product",
|
||||||
|
Example: "Backwards caused quarterly without week it hungry thing someone him regularly. Whomever this revolt hence from his timing as quantity us these yours.",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return productDescription(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("productcategory", Info{
|
||||||
|
Display: "Product Category",
|
||||||
|
Category: "product",
|
||||||
|
Description: "Classification grouping similar products based on shared characteristics or functions",
|
||||||
|
Example: "clothing",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return productCategory(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("productfeature", Info{
|
||||||
|
Display: "Product Feature",
|
||||||
|
Category: "product",
|
||||||
|
Description: "Specific characteristic of a product that distinguishes it from others products",
|
||||||
|
Example: "ultra-lightweight",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return productFeature(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("productmaterial", Info{
|
||||||
|
Display: "Product Material",
|
||||||
|
Category: "product",
|
||||||
|
Description: "The substance from which a product is made, influencing its appearance, durability, and properties",
|
||||||
|
Example: "brass",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return productMaterial(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("productupc", Info{
|
||||||
|
Display: "Product UPC",
|
||||||
|
Category: "product",
|
||||||
|
Description: "Standardized barcode used for product identification and tracking in retail and commerce",
|
||||||
|
Example: "012780949980",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return productUPC(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("productaudience", Info{
|
||||||
|
Display: "Product Audience",
|
||||||
|
Category: "product",
|
||||||
|
Description: "The group of people for whom the product is designed or intended",
|
||||||
|
Example: "adults",
|
||||||
|
Output: "[]string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return productAudience(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("productdimension", Info{
|
||||||
|
Display: "Product Dimension",
|
||||||
|
Category: "product",
|
||||||
|
Description: "The size or dimension of a product",
|
||||||
|
Example: "medium",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return productDimension(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("productusecase", Info{
|
||||||
|
Display: "Product Use Case",
|
||||||
|
Category: "product",
|
||||||
|
Description: "The scenario or purpose for which a product is typically used",
|
||||||
|
Example: "home",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return productUseCase(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("productbenefit", Info{
|
||||||
|
Display: "Product Benefit",
|
||||||
|
Category: "product",
|
||||||
|
Description: "The key advantage or value the product provides",
|
||||||
|
Example: "comfort",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return productBenefit(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
AddFuncLookup("productsuffix", Info{
|
||||||
|
Display: "Product Suffix",
|
||||||
|
Category: "product",
|
||||||
|
Description: "A suffix used to differentiate product models or versions",
|
||||||
|
Example: "pro",
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return productSuffix(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
package gofakeit
|
||||||
|
|
||||||
|
// School will generate a random School type
|
||||||
|
func School() string { return school(GlobalFaker) }
|
||||||
|
|
||||||
|
func (f *Faker) School() string { return school(f) }
|
||||||
|
|
||||||
|
func school(f *Faker) string {
|
||||||
|
return getRandValue(f, []string{"school", "name"}) + " " +
|
||||||
|
getRandValue(f, []string{"school", "isPrivate"}) + " " +
|
||||||
|
getRandValue(f, []string{"school", "type"})
|
||||||
|
}
|
||||||
|
|
||||||
|
func addSchoolLookup() {
|
||||||
|
AddFuncLookup("school", Info{
|
||||||
|
Display: "School",
|
||||||
|
Category: "school",
|
||||||
|
Description: "An institution for formal education and learning",
|
||||||
|
Example: `Harborview State Academy`,
|
||||||
|
Output: "string",
|
||||||
|
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
|
||||||
|
return school(f), nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue