repositorypackage
0.2.3
Repository: https://github.com/zipzoft/supporter-go.git
Documentation: pkg.go.dev
# Packages
No description provided by the author
# README
Supporter GO (Helper functions)
Install
go get -u github.com/zipzoft/supporter-go
Usage
Array
import "github.com/zipzoft/supporter-go"
arr := []string{"a", "b", "c"}
// Get the first element of the array.
// Ouput: a
fmt.Println(supporter.First(arr))
// Check array value is exist.
// Output: true
fmt.Println(supporter.InArray("b", arr))
// Interface to Slice
// Output: []string{"a", "b", "c"}
var unknowType interface{} = []string{"a", "b", "c"}
fmt.Println(supporter.ToSlice(unknowType))
// Check array is empty.
// Output: false
fmt.Println(supporter.IsEmpty(arr))
String
import "github.com/zipzoft/supporter-go"
// Check string is empty.
// Output: true
fmt.Println(supporter.IsEmpty(""))
// Match string with regex.
// Output: map[string][]string{"name": {"zipzoft"}, "package": {"supporter-go"}}
fmt.Println(supporter.MatchGroupsAllSub(`(?P<name>\w+)/(?P<package>\w+)`, "zipzoft/supporter-go"))
Dict (Map)
import "github.com/zipzoft/supporter-go"
target := map[string]interface{
"name": "zipzoft",
"package": "supporter-go",
"developers" : []map[string]interface{}{
{"name": "zipzoft", "age": "30"},
{"name": "PA", "age": "20"},
},
}
// Get value from dict.
// Output: zipzoft
fmt.Println(supporter.DataGet(target, "name"))
// Get nested value from dict.
// Output: 20
fmt.Println(supporter.DataGet(target, "developers.1.age"))
Collection
import (
"github.com/zipzoft/supporter-go/collection"
"github.com/zipzoft/supporter-go/collection/pipe"
)
items := []string{"a", "b", "c"}
_collection := collection.NewPipeline(items)
_collection.Pipe(
pipe.Filter(func(item interface{}) bool {
return item.(string) == "b"
}),
pipe.Map(func(item interface{}) interface{} {
return item.(string) + "!"
}),
)
// Output: []string{"b!"}
output, err := _collection.Get()