# README
values - arbitrary variable type utilities
A collection of utilities for working with interface{}
type things.
Installation
> go get github.com/go-corelibs/values@latest
Examples
IsEmpty
func main() {
empty := values.IsEmpty("") // empty == true
empty = values.IsEmpty(0) // empty == true
empty = values.IsEmpty(nil) // empty == true
empty = values.IsEmpty(-1) // empty == false
empty = values.IsEmpty(&struct{}{}) // empty == false
}
Go-CoreLibs
Go-CoreLibs is a repository of shared code between the Go-Curses and Go-Enjin projects.
License
Copyright 2024 The Go-CoreLibs Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use file except in compliance with the License.
You may obtain a copy of the license at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
# Functions
Compare ensures the given values are consistent and if so, uses the following table of type checking and operation:
| type | operation | |---------------|--------------------------| | Comparable | a.Equals(b) | | time.Time | a.Unix() == b.Unix() | | time.Duration | a.String() == b.String() | | default | reflect.DeepEqual |.
DeepCopy create a deep copy of src.
ExtractIntValue checks if the key is present and if so, tries to convert the interface{} value into an int.
GetKeyedBool uses GetKeyedType to retrieve a bool value.
GetKeyedType uses GetKeyedValue and only returns the value if it is of the specified `kind`.
GetKeyedValue uses reflection to inspect the data given and if it's a struct or map, check for the named key and return [reflect.Value] and ok equals true if the value is a valid [reflect.Value].
IsBoolFalse returns true if the (case-insensitive) value given is one of the following: "false", "no", "off", "-1", "0", "f" or "n", and returns false for everything else.
IsBoolTrue returns true if the (case-insensitive) value given is one of the following: "", "true", "yes", "on" "1", "t" or "y", and returns false for everything else.
IsEmpty return true if the arbitrary value is empty (or zero).
IsNil returns true if the given value is actually nil, even if the type is defined with a nil state
IsNil uses reflection.
IsTrue is a convenience wrapper around IsTruthy, discarding the "ok" return value.
IsTruthy will return true if the given value correlates to a "known true" value (case-insensitive).
RecastValue attempts to re-cast the `input` as a generic value type and if the re-casting fails, checks if the input is actually a pointer to the generic value type and derives the correct type by de-referencing the pointer
Example:
var input interface{} = int64(10) v, ok := RecastValue[int64](input) // v=int64(10), ok=true.
Ref returns a pointer to the given value, useful when dealing with testing with Go structures that require pointers to strings.
ToBoolValue tries to derive a boolean state from the given interface{} value
| Input type | Return state | |---------------|--------------| | bool | (as-is) | | string|[]byte | IsTruthy | | maths.Number | int > 0 |.
ToIndirect checks if the value is a pointer type that fulfills the [sqldriver.Valuer] interface and if not, returns a reflect.Indirect interface of the value.
ToString returns the string representation of an arbitrary value.
TypeOf is a convenience wrapper around `fmt.Sprintf("%T", value)`.
# Interfaces
No description provided by the author