From dfe6b90f5e07d1d023a07354cb8a1cfa7c088dc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20P=C3=A9rez?= Date: Sat, 23 Nov 2024 11:10:48 +0100 Subject: [PATCH] add sentence generation function and create README.md --- README.md | 51 ++++++++++++++++++++++++++++++++++++++++++++++ esfaker/esfaker.go | 12 +++++++++++ 2 files changed, 63 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..67c9bb2 --- /dev/null +++ b/README.md @@ -0,0 +1,51 @@ +# Gopher Toolbox + +Es una librería donde se concentra el código _boilerplate_ que se usan en +distintos proyectos. Incluyen lo siguiente: + +- Implementación controladores de bases de datos: + - [PGX Pool](github.com/jackc/pgx/v5) + - MySQL + + +- Utilidades para conversión de tipos [pgtype](github.com/jackc/pgx/v5/pgtype) a +tipos de Golang. + + +- Generación de datos aleatorios para pruebas unitarias, similar a librería +[Faker](https://faker.readthedocs.io/en/master/) de Python. + +```go +MaleName() string +FemaleName() string +Name() string +LastName() string +Email(beforeAt string) string +Int(min, max int64) int64 +Float(min, max float64) float64 +Bool() bool +Chars(min, max int) string +AllChars(min, max int) string +AllCharsOrEmpty(min, max int) string +AllCharsOrNil(min, max int) *string +NumericString(length int) string +Sentence(min, max int) string +``` + +- Conversión de ficheros Excel a tipos estructurados. Se le pasa el tipo del +_struct_ a la función `Convert[T any](bookPath, sheetName string)` y te +devolverá los datos del tipo `dataExcel []T`. + + +- Constantes para los manejadores HTTP. + + +- Utilidades varias + +```go +CorrectTimezone(timeStamp time.Time) time.Time +GetBool(value string) bool +LogAndReturnError(err error, message string) error +GetBoolFromString(s string) bool +Slugify(s string) string +``` \ No newline at end of file diff --git a/esfaker/esfaker.go b/esfaker/esfaker.go index 2433e2e..64fa45d 100644 --- a/esfaker/esfaker.go +++ b/esfaker/esfaker.go @@ -102,3 +102,15 @@ func NumericString(length int) string { return sb.String() } + +func Sentence(min, max int) string { + var sb strings.Builder + k := len(lowercaseAlphabet) + + for i := 0; i < rand.Intn(max-min+1)+min; i++ { + c := lowercaseAlphabet[rand.Intn(k)] + sb.WriteByte(c) + } + + return sb.String() +}