jefferyjob / go-easy-utils Goto Github PK
View Code? Open in Web Editor NEWQuick toolbox for common data processing developed by Go language。Go语言开发的常用数据处理的快捷工具箱。
License: Apache License 2.0
Quick toolbox for common data processing developed by Go language。Go语言开发的常用数据处理的快捷工具箱。
License: Apache License 2.0
Tracking issue for:
Tracking issue for:
Tracking issue for:
Tracking issue for:
There is a bug in how jsonToStruct parses maps and slices.
type Target struct {
Followed map[string]bool `json:"followed"`
Fids []string `json:"fids"`
}
func TestJsonToStruct(t *testing.T) {
data := `
{
"followed": {
"43015653": true,
"43015666": false
},
"fids": ["43015653",43015666]
}
`
var event Target
err := JsonToStruct(data, &event)
fmt.Printf("%+v, err:%s \n", event, err)
}
The specific error description is as follows
panic: reflect.Set: value of type float64 is not assignable to type string [recovered]
panic: reflect.Set: value of type float64 is not assignable to type string
At the beginning of the design, due to the strong typing properties of the language, it is not recommended to define data types vaguely. So the definition of interface{}
and any
type is not supported.
However, considering the affordability of some businesses, these two types need to be supported, so this requirement will support the definition of interface{}
and any
type.
func TestJsonToStructAny1(t *testing.T) {
jsonData := `{
"name": "make",
"age": "10"
}`
type Target struct {
Name interface{} `json:"name"`
Age uint `json:"age"`
}
var target Target
err := JsonToStruct(jsonData, &target)
if err != nil {
t.Errorf("err %s", err)
return
}
}
go-easy-utils/jsonUtil/parse_map.go
Line 100 in 3c0b974
I think errors like this can be improved to json_ to_ struct. go, it is convenient for developers to make incorrect type assertions
func Chunk[T any](slice []T, size int) [][]T {
var chunks [][]T
for i := 0; i < len(slice); i += size {
end := i + size
if end > len(slice) {
end = len(slice)
}
chunks = append(chunks, slice[i:end])
}
return chunks
}
Tracking issue for:
v1.0 为了快速适应本公司的业务,所以没有考虑any和泛型
v2.0 当前正在开发和自测中,将会在不久支持泛型和any,以兼容各个业务需求
有不少同学提出这个问题,这里统一回复一下,请大家期待后续版本的发布。
Tracking issue for:
go.mod中go的版本是1.18,已经支持泛型,为何没有应用泛型,存在大量的重复代码和interface{}。
// MergeSlices 将多个slice合并成一个slice
func MergeSlices(slices ...[]interface{}) []interface{} {}
// MergeStrSlices 将多个slice合并成一个slice
func MergeStrSlices(slices ...[]string) []string {}
// MergeIntSlices 将多个slice合并成一个slice
func MergeIntSlices(slices ...[]int) []int {}
可以参考lancet
go-easy-utils/mathUtil/ceil.go
Line 9 in 0811e07
这种方法完全可以不使用反射,可以这样写func Ceil[T float32 | float64](num T) int {
if num == 0{return 0 }
return int(math.Ceil(float64(num)))
}
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.