core

package module
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: MIT Imports: 0 Imported by: 1

README

Core Intro

Use Package logo

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:

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

Regex Patterns
Path RegEx Patterns

Issues

Notes

Contributors

License

MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmptyAnysPtr

func EmptyAnysPtr() *[]interface{}

func EmptyBoolsPtr

func EmptyBoolsPtr() *[]bool

func EmptyBytePtr

func EmptyBytePtr() *[]byte

func EmptyFloat32Ptr

func EmptyFloat32Ptr() *[]float32

func EmptyFloat64Ptr

func EmptyFloat64Ptr() *[]float64

func EmptyIntsPtr

func EmptyIntsPtr() *[]int

func EmptyPointerStringsPtr

func EmptyPointerStringsPtr() *[]*string

func EmptyStringToIntMapPtr

func EmptyStringToIntMapPtr() *map[string]int

func EmptyStringsMapPtr

func EmptyStringsMapPtr() *map[string]string

func EmptyStringsPtr

func EmptyStringsPtr() *[]string

func PointerStringsPtrByCapacity

func PointerStringsPtrByCapacity(length, cap int) *[]*string

func StringsPtrByCapacity

func StringsPtrByCapacity(length, cap int) *[]string

func StringsPtrByLength

func StringsPtrByLength(length int) *[]string

Types

This section is empty.

Directories

Path Synopsis
cmd
coreimpl
coresort
coreunique
coreutils
enums
internal
tests

Jump to

Keyboard shortcuts

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