xservice

package module
v0.0.0-...-0083930 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: GPL-2.0 Imports: 12 Imported by: 0

README

xservice lib

https://gitlab.com/al-coder/xservice

Version

version="0.1.2-alpha"

Functions:

func Iff(b bool, tArg any, fArg any) any using: fmt.Println(xservice.Iff(false, "1", "2")) => "2"

Acknowledgments

Todo

  • Spread everything through different .go files (system.go, net.go, etc.).

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CRLF string

OS independed line terminator

View Source
var ErrAny error = errors.New("test error")

ErrAny designated for InsideWraped(ErrAny, <any error, not nil>) to responce 'true'

View Source
var ErrBadArgument = errors.New("bad argument")

Functions

func BytesEqual

func BytesEqual(b, a byte, ignoreCase bool) bool

Check if 2 bytes are equal. Use ignoreCase = true to ignore case sensitivity.

func CleanHost

func CleanHost(sUrl string) (string, error)

e.g.: "*(n).example.org" / "127.0.0.1?a=0" -> ".example.org" OR IP(127.0.0.1)

func CompareArrays

func CompareArrays[T cmp.Ordered](a, b []T) bool

using: b := CompareArrays[uint8]([]uint8("123"), []uint8("456")). True means equal.

func DoLocked

func DoLocked(f func())

func FuncFullname

func FuncFullname(f any) string

Provide Unit file & Function name of the Function in format of "common.go^FuncFullnameDec:" Where "common.go" - name of implemented Function file. And "FuncFullnameDec" - name of the function itself in string

func FuncFullnameColon

func FuncFullnameColon(f any, fArg ...any) string

func GenShaB64Hash

func GenShaB64Hash(ab *string) (string, error)

GenShaB64Hash generate Base64 of Sha512 hash. Max final length = 88 bytes.

func GetWD

func GetWD() (string, error)

Get working directory (path to the binary file). Getwd() from the Standart Library provides current/active path, wich is not always path to the binary file.

func Iff

func Iff[T any](b bool, tArg T, fArg T) T

using: fmt.Println(xservice.Iff(false, "1", "2"))

func InRange

func InRange[T IInt](x, db, de T) bool

Using: xservice.InRange(7, 0, 9) = true)

func Inn

func Inn[T IInnConstraint](b T, a *[]T, ignoreCase ...bool) bool

Using: xservice.Inn(byte('0'), []byte("1110")) Use ignoreCase = true to ignore case sensitivity.

func InnIdx

func InnIdx[T IInnConstraint](b T, a *[]T, ignoreCase ...bool) (r int)

Using: xservice.InnIdx[byte](byte('0'), []byte("1110")) Returns the position of the first encounter of the element in the array or -1 if not found. Use ignoreCase = true to ignore case sensitivity.

func InsideWraped

func InsideWraped(err, wrapped error) bool

Check if error 'err' inside recursevely unwrapped error 'wrapped'. Use ErrAny to get 'true' in responce for any not nil error.

func NilOrEmpty

func NilOrEmpty(s *string) bool

NilOrEmpty returns true if argument is nil or empty.

func PathAbs

func PathAbs(base string, path string) (string, error)

PathAbs() returns an absolute representation of path wih base if any.

Otherwise it returns filepath.Abs().

If path already absolute, base would be ignored.

func PathExists

func PathExists(path string) (bool, os.FileInfo, error)

File/Dir Exists

func SetTimer

func SetTimer(ms int, afterFunc func())

func StrEqual

func StrEqual(s1, s2 string, ignoreCase bool) bool

Check if 2 strings are equal. Use ignoreCase = true to ignore case sensitivity.

func StringContainsPart

func StringContainsPart(s, substr string, iPartSize int) bool

using: StringContainsPart("absolutely", "abso", 3) == true, as "abs" same as "bso" are parts of "absolutely". if iPartSize > len(substr) then iPartSize = len(substr)

func WrapErr

func WrapErr(f any, fArgs []any, err error, desc string) error

WrapErr wraps the provided error, if it's not nil, with provided arguments and the description. Once the provided error is nil, but the description is provided, WrapErr makes the new error based on the description and the arguments. If both the error and the description are empty, WrapErr returns nil ignoring the presence of arguments.

Types

type EIgnored

type EIgnored func(error) error

func Egnore

func Egnore(strErr string) EIgnored

Egnore provides function to ignore errors with the specific message.

Example:

egnore := Egnore("invalid duration")
err = egnore(err) //egnore() turns any error with err.Error() == "invalid duration" to nil.

type IInnConstraint

type IInnConstraint interface {
	~byte | string
}

type IInt

type IInt interface {
	int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | float32 | float64
}

type MapParam

type MapParam map[string]string

func MapParamStr

func MapParamStr(prm, prmSeparator, keyValSeparator string) MapParam

Param string to map ------------------------------------------------------------- Example:

prm == "host=localhost port=5432 dbname=postgres"
prmSeparator == " "
keyValSeparator == "="

func (MapParam) Array

func (mp MapParam) Array(keyValSeparator string) (result []string)

Array:

map[string]string{"host": "localhost", "port": "5432", "dbname": "postgres"} -> []string{"host=localhost", "port=5432", "dbname=postgres"}

for that, keyValSeparator needs to = "=".

func (MapParam) Join

func (mp MapParam) Join(prmSeparator, keyValSeparator string) (result string)

Join:

map[string]string{"host": "localhost", "port": "5432", "dbname": "postgres"} -> "host=localhost port=5432 dbname=postgres"

for that, prmSeparator needs to = " " and keyValSeparator needs to = "=".

type TAnyArray

type TAnyArray []any

type TAnyList

type TAnyList struct {
	// contains filtered or unexported fields
}

func NewAnyList

func NewAnyList(a any) (ret *TAnyList)

func (*TAnyList) Append

func (c *TAnyList) Append(arg any) *TAnyList

func (*TAnyList) Find

func (c *TAnyList) Find(arg any) int

func (*TAnyList) GetList

func (c *TAnyList) GetList() *TAnyArray

func (*TAnyList) ValueExists

func (c *TAnyList) ValueExists(arg any) bool

type TStringList

type TStringList []string

TStringList------------------------------------------------------------- Obsolated - remove!

func NewStringList

func NewStringList(arg string, trimEmptyStrings bool) (ret *TStringList)

func (*TStringList) Append

func (c *TStringList) Append(value string) *TStringList

func (*TStringList) HasValue

func (c *TStringList) HasValue(arg string) bool

func (*TStringList) Index

func (c *TStringList) Index(arg string) int

func (*TStringList) Insert

func (c *TStringList) Insert(index int, value string) *TStringList

func (*TStringList) Remove

func (c *TStringList) Remove(index int) *TStringList

func (*TStringList) String

func (c *TStringList) String() (ret string)

func (*TStringList) Text

func (c *TStringList) Text(arg string) (ret string)

func (*TStringList) TrimStrings

func (c *TStringList) TrimStrings() *TStringList

type WrError

type WrError struct {
	// contains filtered or unexported fields
}

func (WrError) Error

func (wr WrError) Error() string

func (WrError) Unwrap

func (wr WrError) Unwrap() error

Jump to

Keyboard shortcuts

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