From 0101241d0e93915f9e7042858a89a8ae96f17115 Mon Sep 17 00:00:00 2001 From: dtapps Date: Wed, 20 Dec 2023 14:52:46 +0800 Subject: [PATCH] update --- go.mod | 17 ++++++++++++++++ go.sum | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ gojson.go | 32 ++++++++++++++++++++++++++++- json/go_json.go | 22 ++++++++++++++++++++ json/json.go | 22 ++++++++++++++++++++ json/jsoniter.go | 23 +++++++++++++++++++++ json/sonic.go | 23 +++++++++++++++++++++ version.go | 2 +- 8 files changed, 192 insertions(+), 2 deletions(-) create mode 100644 go.sum create mode 100644 json/go_json.go create mode 100644 json/json.go create mode 100644 json/jsoniter.go create mode 100644 json/sonic.go diff --git a/go.mod b/go.mod index 122c32f..dd0fc07 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,20 @@ module go.dtapp.net/gojson go 1.18 + +require ( + github.com/bytedance/sonic v1.10.2 + github.com/goccy/go-json v0.10.2 + github.com/json-iterator/go v1.1.12 +) + +require ( + github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect + github.com/chenzhuoyu/iasm v0.9.1 // indirect + github.com/klauspost/cpuid/v2 v2.2.6 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/twitchyliquid64/golang-asm v0.15.1 // indirect + golang.org/x/arch v0.6.0 // indirect + golang.org/x/sys v0.15.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..a7d8296 --- /dev/null +++ b/go.sum @@ -0,0 +1,53 @@ +github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= +github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM= +github.com/bytedance/sonic v1.10.2 h1:GQebETVBxYB7JGWJtLBi07OVzWwt+8dWA00gEVW2ZFE= +github.com/bytedance/sonic v1.10.2/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4= +github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= +github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= +github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d h1:77cEq6EriyTZ0g/qfRdp61a3Uu/AWrgIq2s0ClJV1g0= +github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d/go.mod h1:8EPpVsBuRksnlj1mLy4AWzRNQYxauNi62uWcE3to6eA= +github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog= +github.com/chenzhuoyu/iasm v0.9.1 h1:tUHQJXo3NhBqw6s33wkGn9SP3bvrWLdlVIJ3hQBL7P0= +github.com/chenzhuoyu/iasm v0.9.1/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= +github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/klauspost/cpuid/v2 v2.2.6 h1:ndNyv040zDGIDh8thGkXYjnFtiN02M1PVVF+JE/48xc= +github.com/klauspost/cpuid/v2 v2.2.6/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= +github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= +golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/arch v0.6.0 h1:S0JTfE48HbRj80+4tbvZDYsJ3tGv6BUU3XxyZ7CirAc= +golang.org/x/arch v0.6.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= +rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= diff --git a/gojson.go b/gojson.go index a1e046b..572608a 100644 --- a/gojson.go +++ b/gojson.go @@ -1,6 +1,17 @@ package gojson -import "encoding/json" +import ( + "go.dtapp.net/gojson/json" + "strings" +) + +func Marshal(v any) ([]byte, error) { + return json.Marshal(v) +} + +func Unmarshal(data []byte, v any) error { + return json.Unmarshal(data, v) +} func Encode(v interface{}) (string, error) { bytes, err := json.Marshal(v) @@ -45,3 +56,22 @@ func JsonDecodesNoError(data string) []string { _ = json.Unmarshal([]byte(data), &dat) return dat } + +func ParseQueryString(input string) map[string]interface{} { + paramMap := make(map[string]interface{}) + keyValuePairs := strings.Split(input, "&") + for _, pair := range keyValuePairs { + parts := strings.Split(pair, "=") + if len(parts) == 2 { + key := parts[0] + value := parts[1] + paramMap[key] = value + } + } + return paramMap +} + +func IsValidJSON(s string) bool { + var js map[string]interface{} + return json.Unmarshal([]byte(s), &js) == nil +} diff --git a/json/go_json.go b/json/go_json.go new file mode 100644 index 0000000..8fde13c --- /dev/null +++ b/json/go_json.go @@ -0,0 +1,22 @@ +// Copyright 2017 Bo-Yi Wu. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + +//go:build go_json + +package json + +import json "github.com/goccy/go-json" + +var ( + // Marshal is exported by gojson/json package. + Marshal = json.Marshal + // Unmarshal is exported by gojson/json package. + Unmarshal = json.Unmarshal + // MarshalIndent is exported by gojson/json package. + MarshalIndent = json.MarshalIndent + // NewDecoder is exported by gojson/json package. + NewDecoder = json.NewDecoder + // NewEncoder is exported by gojson/json package. + NewEncoder = json.NewEncoder +) diff --git a/json/json.go b/json/json.go new file mode 100644 index 0000000..cf35c3c --- /dev/null +++ b/json/json.go @@ -0,0 +1,22 @@ +// Copyright 2017 Bo-Yi Wu. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + +//go:build !jsoniter && !go_json && !(sonic && avx && (linux || windows || darwin) && amd64) + +package json + +import "encoding/json" + +var ( + // Marshal is exported by gojson/json package. + Marshal = json.Marshal + // Unmarshal is exported by gojson/json package. + Unmarshal = json.Unmarshal + // MarshalIndent is exported by gojson/json package. + MarshalIndent = json.MarshalIndent + // NewDecoder is exported by gojson/json package. + NewDecoder = json.NewDecoder + // NewEncoder is exported by gojson/json package. + NewEncoder = json.NewEncoder +) diff --git a/json/jsoniter.go b/json/jsoniter.go new file mode 100644 index 0000000..75405e4 --- /dev/null +++ b/json/jsoniter.go @@ -0,0 +1,23 @@ +// Copyright 2017 Bo-Yi Wu. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + +//go:build jsoniter + +package json + +import jsoniter "github.com/json-iterator/go" + +var ( + json = jsoniter.ConfigCompatibleWithStandardLibrary + // Marshal is exported by gojson/json package. + Marshal = json.Marshal + // Unmarshal is exported by gojson/json package. + Unmarshal = json.Unmarshal + // MarshalIndent is exported by gojson/json package. + MarshalIndent = json.MarshalIndent + // NewDecoder is exported by gojson/json package. + NewDecoder = json.NewDecoder + // NewEncoder is exported by gojson/json package. + NewEncoder = json.NewEncoder +) diff --git a/json/sonic.go b/json/sonic.go new file mode 100644 index 0000000..58aa3a3 --- /dev/null +++ b/json/sonic.go @@ -0,0 +1,23 @@ +// Copyright 2022 Gin Core Team. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + +//go:build sonic && avx && (linux || windows || darwin) && amd64 + +package json + +import "github.com/bytedance/sonic" + +var ( + json = sonic.ConfigStd + // Marshal is exported by gojson/json package. + Marshal = json.Marshal + // Unmarshal is exported by gojson/json package. + Unmarshal = json.Unmarshal + // MarshalIndent is exported by gojson/json package. + MarshalIndent = json.MarshalIndent + // NewDecoder is exported by gojson/json package. + NewDecoder = json.NewDecoder + // NewEncoder is exported by gojson/json package. + NewEncoder = json.NewEncoder +) diff --git a/version.go b/version.go index f0f6913..6a98b9d 100644 --- a/version.go +++ b/version.go @@ -1,3 +1,3 @@ package gojson -const Version = "1.0.1" +const Version = "1.0.2"