Sinevia / utils

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Utils

tests

Various utility functions

Array Functions

  • ArrayContains(array interface{}, val interface{}) (exists bool, index int)
  • ArrayMerge(array ...[]interface{}) []interface{}
  • IsStringArrayEqual(a, b []string) bool

Email Functions

  • EmailSend(from string, to []string, subject string, htmlMessage string) (bool, error)

Environment Variables Functions

  • AppAddress() string
  • AppEnv() string
  • AppName() string
  • AppPort() string
  • AppURL() string
  • DbDriver() string
  • DbHost() string
  • DbPort() string
  • DbDatabase() string
  • DbUsername() string
  • DbPassword() string
  • EmailFromAddress() string
  • EmailFromName() string
  • Env(key string) string
  • EnvIntialize(key string) string - Intializes an .env file, if exists. Fails loudly if the file is invalid and cannot be parsed
utils.EnvIntialize()

Fiber Framework Functions

  • FiberAllIps(c *fiber.Ctx) []string
  • FiberGetValueArray2D(c *fiber.Ctx, key string, defaultValue ...[]string)
  • FiberReq(c *fiber.Ctx, key string, valueDefault string) string - returns the trimmed key from POST, or default value if empty

File Functions

  • FileExists(filePath string) bool
  • FileGetContents(filename string) (string, error)
  • FilePutContents(filename string, data string, mode os.FileMode) error - writes a string to file
  • FileToBase64(filePath string) string - converts a file to Base64 encoded string
  • ImgToBase64Url(filePath string) string - converts an image file to Base64 encoded URL string

HTML Functions

  • MinCSS(cssString string) (string, error) - Minifies a Css string
  • MinHTML(htmlString string) (string, error) - Minifies a HTML string
  • MinScript(sctiptString string) (string, error) - Minifies a JavaScript string
  • ScriptsHTML(str string) string - returns an HTML fragment of scripts tags, with embedded and minified local scripts (mainly suitable for serverless environment)
  • StylesHTML(str string) string - returns an HTML fragment of scripts tags, with embedded and minified local styles (mainly suitable for serverless environment)

HTTP Functions

  • Req(r *http.Request, key string, defaultValue string) string - Returns a POST or GET value for a key, or default if not exists
  • RespondJSON(w http.ResponseWriter, response api.Response) - Respond returns an API response as JSON

Interface Functions

  • InterfaceToStringArray(v interface{}) []string

Link Functions

  • LinkWebsite() string

Map Functions

  • MapToColumn(inputMap []map[string]string, keyName string) []string
  • MapToKeyValue(inputMap []map[string]string, keyName string, valueName string) map[string]string

String Functions

  • AddSlashes(str string) string - adds slashes
  • RandStr(len int) string - generates a random string
  • Slugify(s string, replaceWith rune) string - converts a string to slug
  • StrToInt(s string) (int, error) - converts a string to Int32
  • StrToInt64(s string) (int64, error) - converts a string to Int64
  • TemplateParseString(template string, data) string - parses a template file and returns as string
  • ToString(v interface{}) string - converts an interface to string

Time Functions

  • StrToTimeUnix(str string) (int64, error) - converts string to Unix time

Other Functions

  • IsNumeric(s string) bool - checks if a string is numeric

About

License:MIT License


Languages

Language:Go 100.0%