helper

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CamelToSnake

func CamelToSnake(s string) string

camelToSnake converts camelCase or PascalCase to snake_case

func ClearSpecialCharacters

func ClearSpecialCharacters(val string) string

clearSpecialCharacters cleans the input string by replacing curly apostrophes, removing HTML tags, and keeping only allowed characters.

func Command

func Command(name string, arg ...string) interface{}

func CompareValues

func CompareValues(a, b interface{}) int

func Contains

func Contains(slice []string, item string) bool

Utility function to check if slice contains an element

func ConvertCalculatedValue

func ConvertCalculatedValue(value interface{}) interface{}

func ConvertJSONArrayToCSV

func ConvertJSONArrayToCSV(jsonData interface{}, headingColumns []string, filename string) (string, error)

ConvertJSONArrayToCSV takes a byte slice of JSON data (an array of objects) and a list of desired column names. It converts this data into a CSV string.

func ConvertJSONArrayToDataArray

func ConvertJSONArrayToDataArray(jsonData interface{}, headingColumns []string) ([][]string, error)

ConvertJSONArrayToCSV takes a byte slice of JSON data (an array of objects) and a list of desired column names. It converts this data into a CSV string.

func ConvertJSONArrayToExcel

func ConvertJSONArrayToExcel(jsonData interface{}, headingColumns []string, filename string) (string, error)

ConvertJSONArrayToCSV takes a byte slice of JSON data (an array of objects) and a list of desired column names. It converts this data into a CSV string.

func ConvertTo

func ConvertTo[T any](data interface{}) (T, error)

convertTo converts a map[string]interface{} to a struct of type T

func ConvertToDataMap

func ConvertToDataMap(data map[string]interface{}) datatype.DataMap

convertTo converts a map[string]interface{} to a struct of type T

func CreateDirectory

func CreateDirectory(dir string) error

func CreateFile

func CreateFile(data interface{}, filename string) error

func CreateFolder

func CreateFolder(dir string) error

func DateEnd

func DateEnd(value interface{}) time.Time

func DateStart

func DateStart(value interface{}) time.Time

func DownloadFile

func DownloadFile(url, destPath string, progress func(downloaded, total int64)) error

DownloadFile downloads a file from URL and saves it to destPath Supports:

  • Large files (streaming)
  • Progress callback
  • Timeout
  • Resume (optional, see note below)
  • Automatic directory creation

func ExtractGraphqlQuery

func ExtractGraphqlQuery(data interface{}, level uint) map[uint][]string

func FileExists

func FileExists(filename string) bool

FileExists checks if a file exists

func FormatPhone

func FormatPhone(phone interface{}) string

func GetBaseUrl

func GetBaseUrl(str string) string

func GetChildRelativeName

func GetChildRelativeName(parent string, collection string, primaryKey string, foreignKey string) string

func GetCrossPlatformIdleTime

func GetCrossPlatformIdleTime() time.Duration

The central function that calls the OS-specific function

func GetDirectoryPath

func GetDirectoryPath() string

GetDirectoryPath returns the absolute path of the specified file or executable

func GetEmailContent

func GetEmailContent(layout, template string, data map[string]interface{}) string

getEmailContent reads a template file, processes it, and wraps it in a layout

func GetFirst

func GetFirst(data interface{}) interface{}

func GetHexString

func GetHexString(length int) string

func GetList

func GetList(data interface{}, key string) []interface{}

func GetLocalIP

func GetLocalIP() (string, error)

GetLocalIP retrieves the first non-loopback local IP address

func GetLocalIPS

func GetLocalIPS() ([]string, error)

GetLocalIP retrieves the first non-loopback local IP address

func GetMap

func GetMap(data interface{}, key string) map[string]interface{}

func GetMapArray

func GetMapArray(data interface{}, source string, keys map[string]string) []interface{}

func GetMapBoolean

func GetMapBoolean(data interface{}, key string) bool

func GetMapDate

func GetMapDate(data interface{}, key string) time.Time

func GetMapFloat

func GetMapFloat(data interface{}, key string) float64

func GetMapInt

func GetMapInt(data interface{}, key string) int

func GetMapString

func GetMapString(data interface{}, key string) string

func GetMapValue

func GetMapValue(data interface{}, key string) interface{}

func GetNetworkIP

func GetNetworkIP() (string, error)

GetNetworkIP retrieves the local IP and calculates the network address

func GetParentRelativeName

func GetParentRelativeName(collection string, primaryKey string, foreignKey string) string

func GetPath

func GetPath(relativePath string) string

func GetPublicIP

func GetPublicIP() (string, error)

GetPublicIP fetches the external IP address from an API

func GetPublicPath

func GetPublicPath() (string, error)

GetPublicPath returns the absolute path of a frontend file (e.g., index.html)

func GetRandomInt

func GetRandomInt(length int) string

func GetRandomString

func GetRandomString(length int, typ string) string

func GetRequest

func GetRequest(url string, headers map[string]string) (status int, responseBody string, err error)

GetRequest performs an HTTP GET request with the specified URL, headers, and optional body.

func GetSortedUniqueKeys

func GetSortedUniqueKeys(records []datatype.DataMap) []string

GetSortedUniqueKeys extracts all unique keys (field names) from a slice of Records and returns them as an alphabetically sorted slice of strings.

func GetTextContent

func GetTextContent(template string, data map[string]interface{}) string

getTextContent reads a template file and processes it with data

func GetTimestamp

func GetTimestamp(value interface{}) time.Time

func GetType

func GetType(data interface{}) string

func GetValueOf

func GetValueOf(data interface{}, key string) interface{}

func GetValueOfBoolean

func GetValueOfBoolean(data interface{}, key string) bool

func GetValueOfDate

func GetValueOfDate(data interface{}, key string) time.Time

func GetValueOfFloat

func GetValueOfFloat(data interface{}, key string) int

func GetValueOfInt

func GetValueOfInt(data interface{}, key string) int

func GetValueOfMap

func GetValueOfMap(data interface{}, key string) map[string]interface{}

func GetValueOfString

func GetValueOfString(data interface{}, key string) string

func GetWhatsappContent

func GetWhatsappContent(template string, data map[string]interface{}) interface{}

getWhatsappContent processes template content and attempts to parse it as JSON

func HomeDirectory

func HomeDirectory(name string) string

func HourEnd

func HourEnd(value interface{}) time.Time

func HourStart

func HourStart(value interface{}) time.Time

func IsArray

func IsArray(v interface{}) bool

func IsEmail

func IsEmail(email interface{}) bool

func IsEmailIdentifier

func IsEmailIdentifier() bool

func IsEmpty

func IsEmpty(value interface{}) bool

func IsList

func IsList(v interface{}) bool

func IsMap

func IsMap(data interface{}) bool

func IsNotEmpty

func IsNotEmpty(value interface{}) bool

func IsNumeric

func IsNumeric(value interface{}) bool

IsNumeric checks if a value is an int, float, or a numeric string

func IsPhone

func IsPhone(value interface{}) bool

func IsPhoneIdentifier

func IsPhoneIdentifier() bool

func IsPointer

func IsPointer(v interface{}) bool

func IsSlice

func IsSlice(v interface{}) bool

func IsSliceOfMapStringInterface

func IsSliceOfMapStringInterface(v interface{}) bool

func IsUsernameIdentifier

func IsUsernameIdentifier() bool

func IsWhatsappIdentifier

func IsWhatsappIdentifier() bool

func LoadFile

func LoadFile(filename string) string

LoadFile reads a JSON file and converts it to a map

func LoadJSONFile

func LoadJSONFile(filename string) (map[string]interface{}, error)

LoadJSONFile reads a JSON file and converts it to a map

func ModifyString

func ModifyString(value string) string

modifyString is a placeholder implementation; adjust based on your needs

func MonthEnd

func MonthEnd(value interface{}) time.Time

func MonthStart

func MonthStart(value interface{}) time.Time

func ObjectID

func ObjectID(id interface{}) bson.ObjectID

func ObjectIDtoString

func ObjectIDtoString(id bson.ObjectID) string

func PhoneFormat

func PhoneFormat(phone interface{}) string

func Pluralize

func Pluralize(word string) string

Pluralize converts a singular noun to its plural form

func PostRequest

func PostRequest(url string, headers map[string]string, body interface{}) (status int, responseBody string, err error)

func Reverse

func Reverse[T interface{}](slice []T)

func SaveToFile

func SaveToFile(data interface{}, filename string) error

func Singularize

func Singularize(word string) string

Singularize converts a plural noun to its singular form

func SortMap

func SortMap[T interface{}](options map[string]T) map[string]T

func SortedKeys

func SortedKeys[T interface{}](options map[string]T) []string

func StringLength

func StringLength(value string) int

func StringToDatetime

func StringToDatetime(value interface{}) *time.Time

func StringToTimeOnly

func StringToTimeOnly(value interface{}) *time.Time

func TextTemplate

func TextTemplate(templateString string, data map[string]interface{}, regexPattern *regexp.Regexp) string

textTemplate replaces placeholders in templateString with values from data

func ToByte

func ToByte(data interface{}) []byte

func ToCamelCase

func ToCamelCase(s string) string

ToCamelCase converts a string to CamelCase

func ToFloat

func ToFloat(value interface{}) float64

func ToFloat64

func ToFloat64(value interface{}) float64

func ToInt

func ToInt(value interface{}) int

func ToInterface

func ToInterface(data interface{}) (interface{}, error)

func ToJson

func ToJson(data interface{}) string

func ToList

func ToList[T any](data interface{}) []T

func ToMap

func ToMap[T any](data interface{}) map[string]T

JSON file and converts it to a map

func ToMapList

func ToMapList[T any](data interface{}) []map[string]T

func ToSlug

func ToSlug(s string) string

ToSlug converts a string to a URL-friendly slug

func ToString

func ToString(s interface{}) string

func ToTimestampString

func ToTimestampString(value interface{}, layout string) time.Time

func ToTitle

func ToTitle(s string) string

func ToUnderscore

func ToUnderscore(text string) string

ToUnderscore converts a string into snake_case format. It handles camelCase, PascalCase, and kebab-case.

func ToVariable

func ToVariable(s string) string

func Today

func Today() time.Time

func TodayEnd

func TodayEnd() time.Time

func Tomorrow

func Tomorrow() time.Time

func TomorrowEnd

func TomorrowEnd() time.Time

func TrackTime

func TrackTime(start *time.Time, name string)

func UUID

func UUID() string

func ValidateEmail

func ValidateEmail(email interface{}) bool

func WeekEnd

func WeekEnd(value interface{}) time.Time

func WeekStart

func WeekStart(value interface{}) time.Time

func Yesterday

func Yesterday() time.Time

func YesterdayEnd

func YesterdayEnd() time.Time

Types

type Objectifier

type Objectifier struct{}

Objectifier provides methods to get or check existence of nested map values

func (*Objectifier) Exists

func (o *Objectifier) Exists(name string, context map[string]interface{}) bool

func (*Objectifier) Get

func (o *Objectifier) Get(name string, create bool, context map[string]interface{}) interface{}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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