- A personal golang library without any third-party library, inspired by shomali11/util, require
Go >= 1.13
.
- xcolor
- xcondition
- xmodule
- xnumber
- xorderedmap
- xpointer
- xreflect
- xruntime
- xslice
- xstatus
- xstring
- xtesting
- xtime
- xtime/zones
- None
A personal GoLang library without any third-party library.
License: MIT License
Go >= 1.13
.Maybe add a xmap
package. Need to add a function to convert []interface{}
to map[string]interface{}
or map[interface{}]interface{}
. See Aoi-hosizora/ahlib-mx#10 (comment).
By the way, also add some helper functions for converting between map[T1]T2
.
ahlib/xmodule/xmodule_logger.go
Lines 130 to 140 in 33afdaf
Should be renamed to
var LogLeftArrowFunc func()
func logLeftArrowFunc() {
if LogLeftArrowFunc != nil {
LogLeftArrowFunc()
return
}
// ...
}
Add StiOfXXX
functions in xslice
just like ItsOfXXX
.
Lines 59 to 65 in 21424a4
func StiOfString(slice []string) []interface{} { }
type SortSlice struct {
s []interface{}
less func(i, j int) bool
swap func(i, j int)
}
func (s SortSlice) Len() int {
return len(s.s)
}
func (s SortSlice) Less(i, j int) bool {
return s.less(i, j)
}
func (s SortSlice) Swap(i, j int) {
s.swap(i, j)
}
func NewSortSlice(s []interface{}, less func(i, j int) bool) SortSlice {
return SortSlice{
s: s,
less: less,
swap: func(i, j int) { s[i], s[j] = s[j], s[i] },
}
}
func ReverseSortSlice(s SortSlice) SortSlice {
return SortSlice{
s: s.s,
less: func(i, j int) bool {
return !s.less(i, j)
},
swap: s.swap,
}
}
func Sort(s []interface{}, less func(i, j int) bool) {
interfaceSlice := NewSortSlice(s, less)
sort.Sort(interfaceSlice)
}
func StableSort(s []interface{}, less func(i, j int) bool) {
interfaceSlice := NewSortSlice(s, less)
sort.Stable(interfaceSlice)
}
func Sti(slice interface{}) []interface{} {
if slice == nil {
return nil
}
v := reflect.ValueOf(slice)
if v.Type().Kind() != reflect.Slice {
panic("Sti: parameter must be a slice")
}
l := v.Len()
arr := make([]interface{}, l)
for idx := 0; idx < l; idx++ {
arr[idx] = v.Index(idx).Interface()
}
return arr
}
func Its(slice []interface{}, model interface{}) interface{} {
if model == nil {
panic("Its: model must be non-nil")
}
if slice == nil {
return nil
}
t := reflect.TypeOf(model)
l := len(slice)
out := reflect.MakeSlice(reflect.SliceOf(t), l, l)
for idx := range slice {
v := reflect.ValueOf(slice[idx])
out.Index(idx).Set(v)
}
return out.Interface()
}
// SliceToInterfaceMap returns a map[interface{}]interface{} from an interface slice.
func SliceToInterfaceMap(args []interface{}) map[interface{}]interface{} {
out := make(map[interface{}]interface{})
l := len(args)
for i := 0; i < l; i += 2 {
keyIdx := i
valueIdx := i + 1
if i+1 >= l {
break
}
key := args[keyIdx]
value := args[valueIdx]
out[key] = value
}
return out
}
// SliceToInterfaceMap returns a map[string]interface{} from an interface slice.
func SliceToStringMap(args []interface{}) map[string]interface{} {
out := make(map[string]interface{})
l := len(args)
for i := 0; i < l; i += 2 {
keyIdx := i
valueIdx := i + 1
if i+1 >= l {
break
}
keyItf := args[keyIdx]
value := args[valueIdx]
key := ""
if keyItf == nil {
continue
}
if k, ok := keyItf.(string); ok {
key = k
} else {
key = fmt.Sprintf("%v", keyItf)
}
out[key] = value
}
return out
}
Add msgAndArgs...
argument for functions in xtesting
, and use testing.TB
and not testing.T
.
Refactor progress:
Test progress:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.