baseutils

package module
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: Unlicense Imports: 13 Imported by: 1

README

base-utils

General util functions for Go applications


direct dependencies

  • AWS Go SDK (github.com/aws/aws-sdk-go) used for S3 uploads
  • mimetype (github.com/gabriel-vasile/mimetype) used to infer a file MIME type and extension at the S3 upload function

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AWSRegionToRegion map[string]string = map[string]string{
	"sa-east-1":    "saopaulo",
	"ca-central-1": "montreal",
	"us-east-1":    "virginia",
}

AWS region to application region map

View Source
var Empty any

Empty define an empty interface literal type to pass null as a parameter

View Source
var FlyioRegionToAPPRegion map[string]string = map[string]string{
	"gru": "saopaulo",
	"yul": "montreal",
	"iad": "virginia",
}

Fly.io region into application region name

View Source
var RegionToAWSRegion map[string]string = map[string]string{
	"saopaulo": "sa-east-1",
	"montreal": "ca-central-1",
	"virginia": "us-east-1",
}

application region to AWS region map

Functions

func CopyFile

func CopyFile(source, dest string) (err error)

CopyFile open and read the source file contents, then, call WriteFileto write the new file

func ExtractNullInt added in v0.5.0

func ExtractNullInt(data any) (v null.Int)

ExtractNullInt extract a null.Int out of a interface that might not be int64

func ExtractNullString added in v0.5.0

func ExtractNullString(data any) (v null.String)

ExtractNullString extract a null.String out of a interface that might not be string

func ExtractNullTime added in v0.9.1

func ExtractNullTime(data any) (v null.Time)

ExtractNullTime extract a null.Time out of a string interface by parsing it in various formats

func ExtractStringArray added in v0.5.0

func ExtractStringArray(data any) (v []string)

ExtractStringArray extract a array of strings out of an interface

func FillString added in v0.7.0

func FillString(currVal, newVal string) string

FillString check if the current string is empty, if so, return the new string

func GetFQDNIPv4Address

func GetFQDNIPv4Address(fqdn string) (addr string)

GetFQDNIPv4Address fetch the first IPv4 address from an FQDN, ignoring errors

func GetIPAddressRDNS

func GetIPAddressRDNS(addr string) (rdns string)

GetIPAddressRDNS fetch the reverse DNS address from an IP, ignoring errors

func GetKey added in v0.5.0

func GetKey(needle string, haystack map[string]any) any

GetKey get a key value of a interface within a string map

func GzipData

func GzipData(input *[]byte) (output *[]byte, err error)

GzipData take an content as a bytes pointer and Gzip those data, returning the output as bytes

func IsFlyioInstance added in v0.8.0

func IsFlyioInstance() (isFly bool, region string)

determine if the current running instance is a Fly.io instance

func IsMap

func IsMap(v any) bool

IsMap check if the informed interface is an map of string to interface

func ListFolderFiles

func ListFolderFiles(folder string, includeDirectories bool) (files []os.FileInfo, err error)

ListFolderFiles take a folder path and walk through each item on it

func NewLogger added in v0.9.0

func NewLogger(l *log.Logger, prefix string) *log.Logger

NewLogger create a new logger using the parent logger prefix and writer

func ParseJSONFile

func ParseJSONFile(path string, data any) (err error)

ParseJSONFile open the passed file from path and try to unmarshal its contents into the passed interface

func RandomString

func RandomString(length int, upperCase, lowerCase, numbers bool) string

RandomString generate a random string of the passed length using the desired chars

func TruncateText added in v0.9.0

func TruncateText(s string, maxLen int) string

TruncateText truncate a text and add ellipsis to its end

func UnGzipData

func UnGzipData(input *[]byte) (output *[]byte, err error)

UnGzipData take a Gzip-ped content as a bytes pointer and undo the Gzip, returning the uncompressed data as bytes

func WriteFile

func WriteFile(path string, content *[]byte) (err error)

WriteFile take an path to write into and content in bytes and write the file creating the folder tree recursively

Types

This section is empty.

Jump to

Keyboard shortcuts

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