str

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2023 License: Apache-2.0 Imports: 11 Imported by: 5

Documentation

Overview

Package string provides a set of functions for working with strings

Index

Constants

View Source
const (
	INPUT_TYPE_BOOL   = "bool"
	INPUT_TYPE_INT    = "int"
	INPUT_TYPE_FLOAT  = "float"
	INPUT_TYPE_STRING = "string"
)

const definitions for the input types

Variables

View Source
var Err_ValueIsBlank = fmt.Errorf("a value is blank")

err definitions

Functions

func CastStringToType

func CastStringToType(input_type string, value interface{}) interface{}

CastStringToType casts a string to a type - input_type: the type to cast to

  • INPUT_TYPE_BOOL = "bool"
  • INPUT_TYPE_INT = "int"
  • INPUT_TYPE_FLOAT = "float"

- value: the string to cast - returns: the cast value

func CheckNotBlank

func CheckNotBlank(value ...string) error

CheckNotBlank takes a list of strings and returns an error if any of the strings are blank - value: a list of strings - returns: an error if any of the strings are blank

func Clean

func Clean(str string, replace string) string

Clean It takes a string and replaces all non-alphanumeric characters with the string passed in as the second argument - str: the string to clean - replace: the string to replace non-alphanumeric characters with - returns: the cleaned string

func CommaListContainsString

func CommaListContainsString(string_list string, str string) bool

CommaListContainsString returns true if a string contains any of the items in a comma separated list - string_list: the comma separated list of strings - str: the string to check - returns: true if the string contains any of the items in the comma separated list

func Concat

func Concat(sep string, string_list ...any) string

Concat takes a string and a list of strings and returns a string. - sep: the separator to use between the strings - string_list: a list of strings to concatenate - returns: a concatenated string

func CreateKey

func CreateKey(value string, replace_with string) string

CreateKey takes a string and returns a string that can be used as a key - value: the string to convert - replace_with: the string to replace spaces with - returns: the converted string

func CreateKeyOrGUID

func CreateKeyOrGUID(value string, replace_with string) (string, error)

CreateKeyOrGUID takes a string and returns a string that can be used as a key or a GUID if the string is empty - value: the string to convert - replace_with: the string to replace spaces with - returns: the converted string - error: any error that occurs

func GetDomainOrIP

func GetDomainOrIP(url_str string) string

GetDomainOrIP returns the domain or IP from a URL - url_str: the URL to parse - returns: the domain or IP from the URL

func GetPortInt

func GetPortInt(url_str string) int

GetPortInt returns the port from a URL as an int - url_str: the URL to parse - returns: the port from the URL as an int

func GetPortString

func GetPortString(url_str string) string

GetPortString returns the port from a URL - url_str: the URL to parse - returns: the port from the URL

func GzipBase64

func GzipBase64(data interface{}) (string, error)

GzipBase64 It takes a string, compresses it, and then base64 encodes it

  • data: the data to compress and encode as a string or []byte
  • returns: the compressed and encoded data as a string and an error if there was a problem compressing or encoding the data

func InsertString

func InsertString(orig []string, index int, value string) []string

InsertString inserts a string into a slice of strings - orig: the original slice of strings - index: the index to insert the string at - value: the string to insert - returns: the new slice of strings

func IsNumber

func IsNumber(s string) bool

IsNumber returns true if a string is a number - s: the string to check - returns: true if the string is a number

func RemoveSpacesForHyphens

func RemoveSpacesForHyphens(value string) (string, error)

RemoveSpacesForHyphens It takes a string, converts it to lowercase, replaces all spaces with hyphens, and returns the string - value: the string to convert - returns: the converted string and an error if there was a problem converting the string

func RemoveSpacesForUnderscores

func RemoveSpacesForUnderscores(value string) string

RemoveSpacesForUnderscores It takes a string, converts it to lowercase, and replaces all spaces with underscores - value: the string to convert - returns: the converted string

Types

This section is empty.

Jump to

Keyboard shortcuts

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