Core
Intro
All common core infrastructure and constants combined package.
Git Clone
git clone https://gitlab.com/auk-go/core.git
Prerequisites
- Update git to latest 2.29
- Update or install the latest of Go 1.17.8
- Either add your ssh key to your gitlab account
- Or, use your access token to clone it.
Installation
go get gitlab.com/auk-go/core
Why core?
It makes our other go-packages DRY and concise. It was the first package in the auk-go ecosystem that is core of
everything.
It was first designed for constants, later it got enhanced with:
- codestack
- very powerful to deal with codestack
- chmodhelper
- enums
- base logic for generating stuff
- coresort
- coremath
- deals with integer, ..., all type - min, max
- coretests
- deals with basic functionality for test
- corevalidator
- LineValidator
- Deals with validation
- Helps to do integration tests
- coreversion - deals with all kinds of versioning stuff.
- deals with version (major, minor, patch -- data type)
- regexnew
- LazyRegex - doesn't compile until needed but only once (lock / non lock)
- CreateLock - Create Lazy lock in a loop or running process.
- Create - Create - use create to get lazyregex when created in global vars
- converters (move from type to type)
- corecsv
- errorcore
- coreutils
- issetter.value - 4 Valued Booleans, instead using bool* use this.
- 4 Valued Booleans
- One Approach
- Uninitialized
- True
- False
- Wildcard / Any
- Or,
- Uninitialized
- Set
- Unset
- Wildcard / Any
- coredata
- coreapi
- coredynamic - dynamic data type
- AnyCollection - deals with collection of interface means any
- AnySliceValToInterfacesAsync
- AnyToReflectVal
- AnyTypeMapToMapStringAny
- BytesConverter
- CastedResult
- CastTo
- Dynamic
- DynamicCollection
- DynamicStatus
- funcs - smart converter functions
- IsAnyTypesOf
- KeyVal
- KeyValCollection
- LeftRight
- LengthOfReflect
- MapAnyItemsDiff
- MapAsKeyValSlice
- MapKeysStringSlice
- MapKeysStringSliceAnyMust
- MapKeysStringSliceAnySorted
- MapKeysStringSliceAnySortedMust
- MustBeAcceptedTypes
- NotAcceptedTypesErr
- PonterOrNonPointer
- PointerOrNonPointerUsingReflectValue
- ReflectInterfaceVal
- ReflectKindValidation
- ReflectSetFromTo
- ReflectTypeValidation
- ReflectValToInterfaces
- ReflectValToInterfacesAsync
- ReflectValToInterfacesUsingProcessor
- SafeTypeName
- SafeZeroSet
- SimpleRequest
- SimpleResult
- SliceItemsAsStrings
- SliceItemsAsStringsAny
- SliceItemsAsStringsAnyMust
- SliceItemsProcessorAsStrings
- SliceItemsSimpleProcessorAsStrings
- Type
- TypeMustBeSame
- TypeName
- TypeNames
- TypeNamesReferenceString
- TypeNamesString
- TypeNamesStringUsingReflectType
- TypeNamesUsingReflectType
- TypeNotEqualErr
- TypeSameStatus
- TypeIndexOf
- TypeStatus
- ValueStatus
- ZeroSet
- ZeroSetAny
- corejson
- Result
- ResultCollection
- SerializerLogic (corejson.Serialize.Method)
- corejson.Serialize.StringsApply
- corejson.Serialize.Apply
- corejson.Serialize.FromBytes
- corejson.Serialize.FromStrings
- corejson.Serialize.FromStringsSpread
- corejson.Serialize.FromString
- corejson.Serialize.FromInteger
- corejson.Serialize.FromInteger64
- corejson.Serialize.FromBool
- corejson.Serialize.FromIntegers
- corejson.Serialize.FromStringer
- corejson.Serialize.UsingAnyPtr
- corejson.Serialize.UsingAny
- corejson.Serialize.Raw
- corejson.Serialize.Marshal
- corejson.Serialize.ApplyMust
- corejson.Serialize.ToBytesMust
- corejson.Serialize.ToSafeBytesMust
- corejson.Serialize.ToSafeBytesSwallowErr
- corejson.Serialize.ToBytesSwallowErr
- corejson.Serialize.ToBytesErr
- corejson.Serialize.ToString
- corejson.Serialize.ToStringMust
- corejson.Serialize.ToStringErr
- corejson.Serialize.ToPrettyStringErr
- corejson.Serialize.ToPrettyStringIncludingErr
- DeserializerLogic (corejson.Deserialize.Method)
- corejson.Deserialize.StringsApply
- corejson.Deserialize.Apply
- corejson.Deserialize.UsingStringPtr
- corejson.Deserialize.UsingError
- corejson.Deserialize.UsingErrorWhichJsonResult
- corejson.Deserialize.UsingResult
- corejson.Deserialize.ApplyMust
- corejson.Deserialize.UsingString
- corejson.Deserialize.FromString
- corejson.Deserialize.FromTo
- corejson.Deserialize.MapAnyToPointer
- corejson.Deserialize.UsingStringOption
- corejson.Deserialize.UsingStringIgnoreEmpty
- corejson.Deserialize.UsingBytes
- corejson.Deserialize.UsingBytesPointerMust
- corejson.Deserialize.UsingBytesIf
- corejson.Deserialize.UsingBytesPointerIf
- corejson.Deserialize.UsingBytesPointer
- corejson.Deserialize.UsingBytesMust
- corejson.Deserialize.UsingSafeBytesMust
- corejson.Deserialize.AnyToFieldsMap
- corejson.Deserialize.UsingSerializerTo
- corejson.Deserialize.UsingSerializerFuncTo
- corejson.Deserialize.UsingDeserializerToOption
- corejson.Deserialize.UsingDeserializerDefined
- corejson.Deserialize.UsingDeserializerFuncDefined
- corejson.Deserialize.UsingJsonerToAny
- coreonce - data which generate once
- corepayload - deals with enhance payloads
- corerange - works with ranges
- ostype
- corestr - string related core functionalities and data-types
- hashmap
- hashset - lock features for
map[string]bool
- Collection - List like C# / ArrayList like Java - enhance APIs
- CollectionsOfCollection
- LinkedList
- HashDiff
- CloneSlice
- CharCollectionMap -
map[byte]*Collection
- HashsetsCollection
- KeyValueCollection
- LeftRight - Left, Right string
- LeftMiddleRight
- SimpleStringOnce
- ValidValue
- ValidValues
- ValueStatus
- AnyToString
Examples Json - Deserializer
type Example struct {
A string
B int
SomeMap map[string]string
}
exampleFrom := &Example{
A: "Something",
B: 1,
SomeMap: map[string]string{},
}
exampleTo := &Example{}
err := corejson.Deserialize.FromTo(
exampleFrom,
exampleTo)
// exampleTo will be a copy of public fields From exampleFrom
// exampleFrom := &Example{
// A: "Something",
// B: 1,
// SomeMap: map[string]string{},
// }
Examples
// substituting functions as ternary operator
fmt.Println(conditional.Int(true, 2, 7)) // 2
fmt.Println(conditional.Int(false, 2, 7)) // 7
// making collection from array of strings
stringValues := []string{"hello", "world", "something"}
collectionPtr1 := corestr.NewCollectionPtrUsingStrings(&stringValues, constants.Zero)
fmt.Println(collectionPtr1)
/* outputs:
- hello
- world
- something
*/
// different methods of collection
fmt.Println(collectionPtr1.Length()) // 3
fmt.Println(collectionPtr1.IsEmpty()) // false
// adding more element including empty string
collectionPtr2 := collectionPtr1.AddsLock("else")
fmt.Println(collectionPtr2.Length()) // 4
// checking equality
fmt.Println(collectionPtr1.IsEqualsPtr(collectionPtr2)) // true
// creating CharCollectionMap using collection
sampleMap := collectionPtr1.CharCollectionPtrMap()
fmt.Println(sampleMap)
// methods on CharCollectionMap
fmt.Println(sampleMap.Length()) // 4
fmt.Println(sampleMap.AllLengthsSum()) // 4
fmt.Println(sampleMap.Clear()) // prints: # Summary of `*corestr.CharCollectionMap`, Length ("0") - Sequence `1`
otherMap := sampleMap.Add("another")
fmt.Println(otherMap)
/* prints:
# Summary of `*corestr.CharCollectionMap`, Length ("1") - Sequence `1`
1 . `a` has `1` items.
## Items of `a`
- another
*/
// declaring an empty hashset of length 2 and calling methods on it
newHashSet := corestr.NewHashset(2)
fmt.Println(newHashSet.Length()) // 2
fmt.Println(newHashSet.IsEmpty()) // true
fmt.Println(newHashSet.Items()) // &map[]
// adding items to hashset
strPtr := "new"
newHashSet.AddPtr(&strPtr)
fmt.Println(newHashSet.Items()) // &map[new:true]
// adding map to hashset
newHashSet.AddItemsMap(&map[string]bool{"hi": true, "no": false})
fmt.Println(newHashSet.Items()) // &map[hi:true new:true]
// math operations: getting the larger/smaller value from two given values
fmt.Println(coremath.MaxByte('e', 'i')) // 105 which represents 'i' in ASCII
fmt.Println(coremath.MinByte(23, 5)) // 5
// initializing issetter value
isSetterValue := issetter.False // initializing as false
fmt.Println(isSetterValue.HasInitialized()) // true
fmt.Println(isSetterValue.Value()) // 2
fmt.Println(isSetterValue.IsPositive()) // false
// sorting strings
fruits := []string{"banana", "mango", "apple"}
fmt.Println(strsort.Quick(&fruits)) // &[apple banana mango]
fmt.Println(strsort.QuickDsc(&fruits)) // &[mango banana apple]
// converting pointer strings to strings
mile := "mile"
km := "km"
measures := []*string{&mile, &km}
fmt.Println(converters.PointerStringsToStrings(&measures)) // &[mile km]
fmt.Printf("Type %T", converters.PointerStringsToStrings(&measures)) // Type *[]string
// comparing two int arays
Values := []int{1, 2, 3, 4}
OtherValues := []int{5, 6, 7, 8}
fmt.Println(corecompare.IntArray(Values, OtherValues)) // false
Acknowledgement
Any other packages used
Links
Regex Patterns
Path RegEx Patterns
Issues
Notes
Contributors
License
MIT License