Coder Social home page Coder Social logo

jefferyjob / go-easy-utils Goto Github PK

View Code? Open in Web Editor NEW
323.0 6.0 21.0 213 KB

Quick toolbox for common data processing developed by Go language。Go语言开发的常用数据处理的快捷工具箱。

License: Apache License 2.0

Makefile 0.41% Go 99.59%
go utils go-easy-utils

go-easy-utils's People

Contributors

crazyjums avatar dependabot[bot] avatar jefferyjob avatar lbigdate avatar miaomiaozuo avatar qiyanjun123 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

go-easy-utils's Issues

There is a bug in how jsonToStruct parses maps and slices.

There is a bug in how jsonToStruct parses maps and slices.

  1. Does not support parsing map type
  2. Parse the slice type, if the data type is inconsistent, panic error
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

Feature:jsonToStruct supports interface type assignment

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
	}
}

v2.0.0 当前开发中,将会支持 泛型 和 any

v1.0 为了快速适应本公司的业务,所以没有考虑any和泛型
v2.0 当前正在开发和自测中,将会在不久支持泛型和any,以兼容各个业务需求

有不少同学提出这个问题,这里统一回复一下,请大家期待后续版本的发布。

应用go泛型

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.