lib

package
v1.0.188 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Space     = " "
	EmptyStr  = ""
	LineBreak = "\n"
)
View Source
const (
	// LEVEL_DEBUG = 0
	LEVEL_DEBUG = iota
	// LEVEL_INFO = 1
	LEVEL_INFO
	// LEVEL_WARNING = 2
	LEVEL_WARNING
	// LEVEL_ERROR = 3
	LEVEL_ERROR
	// LEVEL_CRITICAL = 4
	LEVEL_CRITICAL
)
View Source
const Format1 = "2006-01-02T15:04:05"
View Source
const Format2 = "2006-01-02T15:04:05.000" //2025-02-30T00:00:00.000

Variables

View Source
var (
	// ErrInvalidLogLevel is used when an invalid log level has been used.
	ErrInvalidLogLevel = errors.New("invalid log level")
)

Functions

func AnsiCompareText

func AnsiCompareText(str1, str2 string) int

func AnsiQuotedStr

func AnsiQuotedStr(S string, Quote byte) string

func ByteToGzipByte added in v1.0.154

func ByteToGzipByte(data []byte, filename string) ([]byte, error)

ByteToGzipByte Esta funcao faz: 1 - pega um []byte coloca um nome nele 2 - Comprime ele em .gz e retorna o []byte (dele em gz) Ele faz tudo isso em memoria sem gerar arquivo em disco Otimo para enviar via http, ftp, etc

func ByteToSaveFile

func ByteToSaveFile(nomeArquivo string, dados []byte) error

ByteToSaveFile: Converte Byte para Arquivo

func CloneBytes

func CloneBytes(src []byte) []byte

CloneBytes: copia o byte para evitar referencia cruzada de objetos

func ConvertToStringPointers

func ConvertToStringPointers(input []string) []*string

func Copy

func Copy(value string, colIni, qtdeCaracteres int) string

Copy: Imita a funcao Copy delphi

func DateNilToStr

func DateNilToStr(date *time.Time) string

DateNilToStr: Converte data em string dd/mm/yyyy

func DateToStr

func DateToStr(date time.Time) string

DateToStr: Converte data em string dd/mm/yyyy

func DecompressGzipToBytes added in v1.0.154

func DecompressGzipToBytes(gzippedData []byte) ([]byte, error)

DecompressGzipToBytes Esta funcao faz: 1 - pega um []byte coloca um nome nele 2 - Comprime ele de .gz para file e devolve o byte dele assim voce pode optar por salvar em disco ou ate salvar em banco 3 - retorna apenas o byte de um unico arquivo!

func DecompressGzipToSaveOneFile added in v1.0.154

func DecompressGzipToSaveOneFile(gzippedData []byte, outputPath string) error

DecompressGzipToSaveOneFile Esta funcao faz: 1 - pega um []byte coloca um nome nele 2 - Comprime ele de .gz para file e salva em um diretorio o arquivo (unico)

func DecryptData

func DecryptData(privateKey *rsa.PrivateKey, encryptedData []byte) ([]byte, error)

Função para descriptografar dados com a chave privada RSA

func Dividir added in v1.0.163

func Dividir(numerador, denominador float64) float64

func EncodeByte

func EncodeByte(input []byte) string

EncodeByte: Recebe uma []byte como entrada e retorna a string codificada em base64 Imita funcao da unit Soap.EncdDecd do Delphi

func EncodeString

func EncodeString(input string) string

EncodeString: Recebe uma string como entrada e retorna a string codificada em base64 Imita funcao da unit Soap.EncdDecd do Delphi

func EncryptData

func EncryptData(publicKey *rsa.PublicKey, data []byte) ([]byte, error)

Função para criptografar dados com a chave pública RSA

func EndDayOfYearMonth

func EndDayOfYearMonth(year int, month time.Month) time.Time

EndDayOfYearMonth: Ultimo dia do Ano/Mes , exemp: 2024/12 = dia é 31

func Espacos

func Espacos(quantidade int) string

Espacos: Retornar string cheia de espaços

func Exclude

func Exclude[T comparable](slice []T, value T) []T

func ExtractFileNameWithoutExt

func ExtractFileNameWithoutExt(fileName string) string

func FileExists

func FileExists(filePath string) bool

FileExists: Verifica se o arquivo existe

func FileToGzipFile added in v1.0.154

func FileToGzipFile(nomeArquivo, nomedozip string) error

FileToGzipFile Comprime um arquivo em disco para um arquivo gzip

func FloatToInt

func FloatToInt(value float64) int

FloatToInt: Exp:

FloatToInt(-4613.70) = -4613

func FloatToStr

func FloatToStr(value float64, width, precision int) string

func FloatToStrPTBR

func FloatToStrPTBR(value float64, width, precision int) string

FloatToStrPTBR: Exp:

FloatToStr(-4613.70, 2, 64) = -4613,70

func FormatCPF

func FormatCPF(cpf string) string

formato 000.000.000-00

func FormatDate

func FormatDate(format string, date time.Time) string

FormatDate: Formata Data

func FormatDatePoint

func FormatDatePoint(format string, date *time.Time) *string

FormatDatePoint: Formata ponteiro de data

func FormatDecimal

func FormatDecimal(value string) string

func FormatFloat

func FormatFloat(format string, value float64, width, precision int) string

FormatFloat: Exp:

comum.FormatFloat("%%%d.%df", mes.Valor, 4, 2)
comum.FormatFloat("%%%d.2f", item.Qtde_venda, 14, 2)
comum.FormatFloat("%%%d.2f", item.Qtde_venda, 14, 2)

func FormatMatrixFloat

func FormatMatrixFloat(numero float64, digitos, deci int) string

FormatMatrixFloat: FormatMatrixFloat(numero, 12, 2) = +000000051.01 FormatMatrixFloat(numero, 15, 3) = +00000000051.010

func GenerateDeleteQuery

func GenerateDeleteQuery(name string, id string) string

func GenerateInsertQueryTagDb

func GenerateInsertQueryTagDb(name string, data interface{}) string

func GenerateInsertQueryTagJson

func GenerateInsertQueryTagJson(name string, data interface{}) string

func GenerateUpdateQueryTagDb

func GenerateUpdateQueryTagDb(name string, data interface{}, id string) string

func GenerateUpdateQueryTagJson

func GenerateUpdateQueryTagJson(name string, data interface{}, id string) string

func GerarQrCodeJpegBase64

func GerarQrCodeJpegBase64(pixCode string) string

func GetApplicationName

func GetApplicationName() string

GetApplicationName: nome da aplicação sem extensão

func GetApplicationNameExe

func GetApplicationNameExe() string

GetApplicationNameExe: nome da aplicação com extensão

func GetComputerName

func GetComputerName() string

GetApplicationName: nome da aplicação sem extensão

func GetEnvBool

func GetEnvBool(value string) bool

GetEnvBool: obte boleano de .env

func GetEnvInt

func GetEnvInt(value string) int

GetEnvInt: obte int de .env

func GetEnvString

func GetEnvString(value string) string

GetEnvString: obte string de .env

func GetModuleName

func GetModuleName() string

func GetPathApplication

func GetPathApplication() string

GetPathApplication: Pasta da aplicação

func GetPathApplicationFile

func GetPathApplicationFile(fileName string) string

GetPathApplicationFile: Aplica pasta local da aplicação ao nome do arquivo informado

func Guid

func Guid() uuid.UUID

Guid: Guid em formato UUID

func GuidString

func GuidString() string

GuidString: Guid em formato string

func GzipCompress added in v1.0.154

func GzipCompress(data []byte) ([]byte, error)

Função para compactar uma string usando GZIP

func GzipDecompress added in v1.0.154

func GzipDecompress(compressedData []byte) (string, error)

Função para descompactar um GZIP para string

func IfThen

func IfThen[T any](condition bool, v1 T, v2 T) T

IfThen: If then em uma unica funcao

func In

func In[T any](valor T, lista []T) bool

In: Verifica se algo esta na lista

func InIn

func InIn[T any](lista1 []T, lista2 []T) bool

InIn: Procura valores de uma lista dentor de outra lista Encontrando qualquer valor ele retorna true

func Include

func Include[T comparable](slice []T, value T) []T

Include adds a given value to a slice, if it doesn't already exist.

func Int64ToStr

func Int64ToStr(value int64) string

Int64ToStr: Converte int64 para string

func IntToStr

func IntToStr(value int) string

IntToStr: Converte int para string

func IsPointer

func IsPointer(value interface{}) bool

func IsQuotedBase

func IsQuotedBase(value string, ACh1, ACh2 byte) bool

func IsValidEmail

func IsValidEmail(email string) bool

IsValidEmail: Valida se é um email valido

func JoinErrors

func JoinErrors(errors []error) string

JoinErrors: Junta uma lista de erros e converte em string

func LimitStr

func LimitStr(value string, limit int) string

LimitStr: Corta a string caso exceda

func LoadPrivateKey

func LoadPrivateKey(path string) (*rsa.PrivateKey, error)

Função para carregar a chave privada a partir de um arquivo PEM

func LoadPublicKey

func LoadPublicKey(path string) (*rsa.PublicKey, error)

Função para carregar a chave pública a partir de um arquivo PEM

func Lpad

func Lpad(s string, length int, padChar string) string

Lpad: Completa Caracteres a Esquerda(Left)

func Md5

func Md5(src string) string

func OnlyAlfa

func OnlyAlfa(s string) string

OnlyAlfa: Deixa apenas Alfa passar

func OnlyAlfaNumber

func OnlyAlfaNumber(s string) string

OnlyAlfaNumber: Deixa apenas Number/Alfa passar

func OnlyEmail

func OnlyEmail(email string) string

OnlyEmail: Deixa apenas caracteres de email

func OnlyNumber

func OnlyNumber(s string) string

OnlyNumber: Deixa apenas numeros passar

func Pos

func Pos(substring, s string) int

Pos: Esta função Pos aceita dois argumentos: a substring que você está procurando e a string na qual você está procurando. Ela retorna o índice baseado em 1 da primeira ocorrência da substring na string. Se a substring não for encontrada, ela retorna 0 Comentario:

por mais que exista strings.Contains essa aqui retorna posicao onde encontrou o dado

caso de uso:

use para recortar um dado apos encontrar um dados desejado
encontrar marcadores como <> ,</> para recortar dados

func PreencherDireita

func PreencherDireita(s string, tamanho int, caracter string) string

PreencherDireita: Preenche a direita com o caracter informado, caso exceda o tamanho informado ele recorta o valor

func PreencherEsquerda

func PreencherEsquerda(s string, tamanho int, caracter string) string

PreencherEsquerda: Preenche a esqueda com o caracter informado, caso exceda o tamanho informado ele recorta o valor

func QuotedStr

func QuotedStr(s string) string

QuotedStr: coloca aspas simples entre uma string

func RandomString

func RandomString(qtde int) string

func ReadJsonFileToStruct

func ReadJsonFileToStruct(PahtFile string, value any) error

func RemoveAcentos

func RemoveAcentos(s string) string

RemoveAcentos: Remove acentos

func RemoveCaracteres

func RemoveCaracteres(texto string, pRemoveAcentos bool) string

RemoveCaracteres: Remove tudo que não é letra, numero, ou espaco, pode remover acentos tambem caso[pRemoveAcentos]=(true)

func RemoveFileExtension

func RemoveFileExtension(name string) string

RemoveFileExtension: Remove Extensão do arquivo

func RemoverQuebraLinha

func RemoverQuebraLinha(texto string) string

RemoverQuebraLinha: Função para remover quebras de linha \r ou \n

func RepetirString

func RepetirString(c string, quantidade int) string

RepetirString: Repete uma string x vezes

func Rpad

func Rpad(s string, length int, padChar string) string

Rpad: Completa Caracteres a Direita(Right)

func SignData

func SignData(privateKey *rsa.PrivateKey, data []byte) ([]byte, error)

Função para assinar dados com a chave privada do remetente

func StrIso8601ToDate1

func StrIso8601ToDate1(str string) time.Time

func StrIso8601ToDate2

func StrIso8601ToDate2(str string) time.Time

func StrToDate

func StrToDate(str string) (time.Time, error)

StrToDate: converte string em data dd/mm/yyyy

func StrToInt

func StrToInt(value string) int

StrToInt: Converte string para int

func StrToInt64

func StrToInt64(value string) int64

StrToInt64: Converte string para int64

func Trim

func Trim(value string) string

Trim: Remove espaços

func UnQuoteBase

func UnQuoteBase(value string, ACh1, ACh2 byte) string

Types

type Log

type Log struct {
	AppName   string
	TypePrint TypePrint
	LogNivel  NivelLog
	Log       map[string]*LogEmp
	// contains filtered or unexported fields
}

func NewLog

func NewLog() *Log

func (*Log) Critical

func (lg *Log) Critical(app string, v ...interface{})

func (*Log) Debug

func (lg *Log) Debug(app string, v ...interface{})

func (*Log) Error

func (lg *Log) Error(app string, v ...interface{})

func (*Log) Fatal

func (lg *Log) Fatal(app string, v ...interface{})

func (*Log) Info

func (lg *Log) Info(app string, v ...interface{})

func (*Log) Print

func (lg *Log) Print(msg ...interface{})

func (*Log) Screen

func (lg *Log) Screen(app string, v ...interface{})

func (*Log) Warning

func (lg *Log) Warning(app string, v ...interface{})

func (*Log) WriteLog

func (lg *Log) WriteLog(app string, setTime bool, msg ...interface{})

type LogEmp

type LogEmp struct {
	File *os.File
	Hora string
}

func NewLogApp

func NewLogApp(app string) *LogEmp

type Logger

type Logger interface {
	Debug(v ...interface{})
	Info(v ...interface{})
	Warning(v ...interface{})
	Error(v ...interface{})
	Critical(v ...interface{})
	Fatal(v ...interface{})
}

Logger collects logging information at several levels

func NewLogger

func NewLogger(level string, out io.Writer, prefix string, logDir string) (Logger, error)

NewLogger creates and returns a Logger object

type MFile

type MFile struct {
	Nome            string
	CaminhoCompleto string
	Tamanho         int64
}

func ListarArquivosPastaFiltro

func ListarArquivosPastaFiltro(pasta, prefixo, extensao string) ([]MFile, error)

ListarArquivosPastaFiltro: Lista arquivos de uma pasta, porem voce pode filtrar por tipo de arquivos e tambem colocar um prefixo de procura exemplo: ListarArquivosPastaFiltro("c:\", "VRIN*", ".txt")

func ListarArquivosPastaTodos

func ListarArquivosPastaTodos(pasta string) ([]MFile, error)

ListarArquivosPastaTodos: Lista arquivos de uma pasta informada

type NivelLog

type NivelLog int
const (
	N_NENHUM   NivelLog = 0
	N_DEBUG    NivelLog = 1
	N_INFO     NivelLog = 2
	N_WARNING  NivelLog = 3
	N_ERROR    NivelLog = 4
	N_CRITICAL NivelLog = 5
)

type TypePrint

type TypePrint int
const (
	LG_Silent  TypePrint = 0
	LG_Print   TypePrint = 1
	LG_PrintLn TypePrint = 2
)

Jump to

Keyboard shortcuts

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