utils

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2023 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
const (

	/*Email : valida la expresion valida en una cadena de caracteres*/
	Email string = "" /* 1208-byte string literal not displayed */
	/*URLPath : formato de los path de las url*/
	URLPath string = `((\/|\?|#)[^\s]*)`
	/*URLPort : puertos validos de una url*/
	URLPort string = `(:(\d{1,5}))`
	/*URLIP : estructura de una ip publica*/
	URLIP string = `([1-9]\d?|1\d\d|2[01]\d|22[0-3]|24\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){2}(?:\.([0-9]\d?|1\d\d|2[0-4]\d|25[0-5]))`
	/*URLSubdomain : dominios validos de un pagina*/
	URLSubdomain string = `((www\.)|([a-zA-Z0-9]+([-_\.]?[a-zA-Z0-9])*[a-zA-Z0-9]\.[a-zA-Z0-9]+))`
	/*IP : valida el formato de un string*/
	IP string = `` /* 659-byte string literal not displayed */
	/*URLUsername : valida los url con usuario*/
	URLUsername string = `(\S+(:\S*)?@)`
	/*URLSchema : valida el esquema de una url*/
	URLSchema string = `((ftp|tcp|udp|wss?|https?):\/\/)`
	/*URL : Formato para validar cadenas de url*/
	URL = `^` + URLSchema + `?` + URLUsername + `?` + `((` + URLIP + `|(\[` + IP + `\])|(([a-zA-Z0-9]([a-zA-Z0-9-_]+)?[a-zA-Z0-9]([-\.][a-zA-Z0-9]+)*)|(` + URLSubdomain + `?))?(([a-zA-Z\x{00a1}-\x{ffff}0-9]+-?-?)*[a-zA-Z\x{00a1}-\x{ffff}0-9]+)(?:\.([a-zA-Z\x{00a1}-\x{ffff}]{1,}))?))\.?` + URLPort + `?` + URLPath + `?$`

	/*MaxURLRuneCount : maxima cantidad de runas por contar*/
	MaxURLRuneCount = 2083
	/*MinURLRuneCount : minima cantidad de runas por contar*/
	MinURLRuneCount = 3
)

Variables

View Source
var (
	/*EmailFor : expresion para validar email*/
	EmailFor = regexp.MustCompile(Email)

	/*URLFor : valida la expresion de cadenas */
	URLFor = regexp.MustCompile(URL)
)

Functions

func CharRand

func CharRand(Upper bool) string

CharRand : Genera una letra aleatoria upper indica si queres mayusculas o miniscula.

func CreateEnvs added in v1.0.7

func CreateEnvs(data map[string]string) error

CreateEnvs : genera un .env solo con un map string

func DateEquals

func DateEquals(b time.Time, v time.Time) bool

DateEquals : valida las fechas b fecha base v fecha a validar

func DateIdent

func DateIdent(b time.Time, v time.Time) bool

DateIdent : Valida si las fechas son identicas. b fecha base v fecha a validar

func EnvsLoad

func EnvsLoad(envs ...string) (map[string]string, error)

EnvsLoad : carga un arreglo con variables de entorno y lo regresar enun map[string]string

func FActual

func FActual() time.Time

FActual : devuelve la fecha de hoy redondeada.

func FNulo

func FNulo() time.Time

FNulo : Genera una fecha nula 29991231

func FilterExcl

func FilterExcl(strs []string, excl []string) []string

FilterExcl : excluye los registro de un arreglo A con el B ejemplo A[a,b,c,d] B[a,b] Result [c,d]

func FilterStr

func FilterStr(strs []string, valid func(string) bool) (ret []string)

FilterStr : filtra un arreglo de string mediante un metodo definido

func GetLines

func GetLines(s string) []string

GetLines : consigue un arreglos por saltos de lineas en un string

func InStr

func InStr(str string, strs ...string) bool

InStr : compara varios string con uno especifico

func IsEmail

func IsEmail(str string) bool

IsEmail : valida si el string es un email.

func IsEmptyStr added in v1.0.4

func IsEmptyStr(v string) bool

IsEmptyStr : valida si un string esta vacio

func IsEmptyVl

func IsEmptyVl(v reflect.Value) bool

IsEmptyVl : valida si el valor esta vacio

func IsNilArrayStr

func IsNilArrayStr(strs ...string) bool

IsNilArrayStr : valida si los string son vacio

func IsNilStr

func IsNilStr(str string) bool

IsNilStr : valida si un string esta vacio

func IsSpace

func IsSpace(str string) bool

IsSpace : valida si la cadena contiene espacio.

func IsURL

func IsURL(str string) bool

IsURL : valida un string si una url es valida

func LowerStrs

func LowerStrs(strs ...string) []string

LowerStrs : coloca en minusculas un arreglo compleot de strings

func Merge

func Merge(base, override interface{}) interface{}

Merge : combina variables array o string en un solo valor conjunto

func RandInt

func RandInt(min, max int) int

RandInt : envia un numero aleatorio

func ReturnIf

func ReturnIf(a bool, b, c interface{}) interface{}

ReturnIf : retorna un if ternario https://github.com/TheMushrr00m/go-ternary Doc ReturnIf(<bool expression>, <result for true>, <result for false>) ReturnIf(5 > 4, "It's true", "It's false :(")

func Reverse

func Reverse(s string) string

Reverse : manda la reversa de un string

func StrErr

func StrErr(str string) error

StrErr : envia un string con errores personalizado

func StrRand

func StrRand(cant int, Upper bool) string

StrRand : genera una cadena de caracteres ramdon

func SubString

func SubString(s string, start, end int) string

SubString : substring para un string en golang con runas

func Throw

func Throw(up Exception)

Throw : captura el error y detiene el proceso

func TimeEqual

func TimeEqual(b time.Time, v time.Time) bool

TimeEqual : valida los tiempos b fecha base v fecha a validar

func Trim

func Trim(str string) string

Trim : Elimina el espacio de un string a nivel de runas.

func UpperStrs

func UpperStrs(strs ...string) []string

UpperStrs : coloca en mayusculas un arreglo compleot de strings

func ValidDuplidArrayStr

func ValidDuplidArrayStr(strs []string) bool

ValidDuplidArrayStr : valida un arreglo de string si estan duplicados

func ValidateSQLInjection added in v1.0.1

func ValidateSQLInjection(input string) bool

validateSQLInjection : Valida un string si no tiene palabras reservadas sql

Types

type Block

type Block struct {
	Try     func()
	Catch   func(Exception)
	Finally func()
}

Block : bloque de codigo que maneja excepciones

func (Block) Do

func (tcf Block) Do()

Do : ejecuta el bloque de codigo con exepciones

type Exception

type Exception interface{}

Exception : error capturado

type StError

type StError struct {
	When time.Time
	What string
}

StError : Estructura de manejo de error con mensajes personalizados

func (*StError) Error

func (p *StError) Error() string

Error : Muestra el mensaje personalizado del error

func (*StError) MandError

func (p *StError) MandError(mensaje string) error

MandError : Envia un mensaje con la interfaz de error personalizado.

type StMsj

type StMsj struct {
	Store map[string]string
}

StMsj : estructura para manejo de errores y mensajes personalizados

func (*StMsj) AddMsj

func (p *StMsj) AddMsj(code, msj string)

AddMsj : agrega un mensaje con su codigo unico

func (*StMsj) AddStore

func (p *StMsj) AddStore(store map[string]string)

AddStore : agrega su store completo

func (*StMsj) GetError

func (p *StMsj) GetError(code string) error

GetError : envia un error medio el codigo

func (*StMsj) GetString

func (p *StMsj) GetString(code string) string

GetString : envia un mensaje por medio del codigo

Jump to

Keyboard shortcuts

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