diff --git a/encoding/gcharset/gcharset.go b/encoding/gcharset/gcharset.go index 2caf48612..676821195 100644 --- a/encoding/gcharset/gcharset.go +++ b/encoding/gcharset/gcharset.go @@ -4,7 +4,7 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -// Package charset implements character-set conversion functionality. +// Package gcharset implements character-set conversion functionality. // // Supported Character Set: // @@ -21,8 +21,10 @@ package gcharset import ( "bytes" + "context" "github.com/gogf/gf/v2/errors/gcode" "github.com/gogf/gf/v2/errors/gerror" + "github.com/gogf/gf/v2/internal/intlog" "io/ioutil" "golang.org/x/text/encoding" @@ -104,8 +106,9 @@ func getEncoding(charset string) encoding.Encoding { if c, ok := charsetAlias[charset]; ok { charset = c } - if e, err := ianaindex.MIB.Encoding(charset); err == nil && e != nil { - return e + enc, err := ianaindex.MIB.Encoding(charset) + if err != nil { + intlog.Error(context.TODO(), err) } - return nil + return enc } diff --git a/encoding/ghash/ghash.go b/encoding/ghash/ghash.go index 7d69d4fc6..5f2cd52d7 100644 --- a/encoding/ghash/ghash.go +++ b/encoding/ghash/ghash.go @@ -7,7 +7,7 @@ // Package ghash provides some classic hash functions(uint32/uint64) in go. package ghash -// BKDR Hash Function +// BKDRHash implements the classic BKDR hash algorithm for 32 bits. func BKDRHash(str []byte) uint32 { var seed uint32 = 131 // 31 131 1313 13131 131313 etc.. var hash uint32 = 0 @@ -17,7 +17,7 @@ func BKDRHash(str []byte) uint32 { return hash } -// BKDR Hash Function 64 +// BKDRHash64 implements the classic BKDR hash algorithm for 64 bits. func BKDRHash64(str []byte) uint64 { var seed uint64 = 131 // 31 131 1313 13131 131313 etc.. var hash uint64 = 0 @@ -27,7 +27,7 @@ func BKDRHash64(str []byte) uint64 { return hash } -// SDBM Hash +// SDBMHash implements the classic SDBM hash algorithm for 32 bits. func SDBMHash(str []byte) uint32 { var hash uint32 = 0 for i := 0; i < len(str); i++ { @@ -37,7 +37,7 @@ func SDBMHash(str []byte) uint32 { return hash } -// SDBM Hash 64 +// SDBMHash64 implements the classic SDBM hash algorithm for 64 bits. func SDBMHash64(str []byte) uint64 { var hash uint64 = 0 for i := 0; i < len(str); i++ { @@ -47,7 +47,7 @@ func SDBMHash64(str []byte) uint64 { return hash } -// RS Hash Function +// RSHash implements the classic RS hash algorithm for 32 bits. func RSHash(str []byte) uint32 { var b uint32 = 378551 var a uint32 = 63689 @@ -59,7 +59,7 @@ func RSHash(str []byte) uint32 { return hash } -// RS Hash Function 64 +// RSHash64 implements the classic RS hash algorithm for 64 bits. func RSHash64(str []byte) uint64 { var b uint64 = 378551 var a uint64 = 63689 @@ -71,7 +71,7 @@ func RSHash64(str []byte) uint64 { return hash } -// JS Hash Function +// JSHash implements the classic JS hash algorithm for 32 bits. func JSHash(str []byte) uint32 { var hash uint32 = 1315423911 for i := 0; i < len(str); i++ { @@ -80,7 +80,7 @@ func JSHash(str []byte) uint32 { return hash } -// JS Hash Function 64 +// JSHash64 implements the classic JS hash algorithm for 64 bits. func JSHash64(str []byte) uint64 { var hash uint64 = 1315423911 for i := 0; i < len(str); i++ { @@ -89,7 +89,7 @@ func JSHash64(str []byte) uint64 { return hash } -// P. J. Weinberger Hash Function +// PJWHash implements the classic PJW hash algorithm for 32 bits. func PJWHash(str []byte) uint32 { var BitsInUnignedInt uint32 = 4 * 8 var ThreeQuarters uint32 = (BitsInUnignedInt * 3) / 4 @@ -106,7 +106,7 @@ func PJWHash(str []byte) uint32 { return hash } -// P. J. Weinberger Hash Function 64 +// PJWHash64 implements the classic PJW hash algorithm for 64 bits. func PJWHash64(str []byte) uint64 { var BitsInUnignedInt uint64 = 4 * 8 var ThreeQuarters uint64 = (BitsInUnignedInt * 3) / 4 @@ -123,7 +123,7 @@ func PJWHash64(str []byte) uint64 { return hash } -// ELF Hash Function +// ELFHash implements the classic ELF hash algorithm for 32 bits. func ELFHash(str []byte) uint32 { var hash uint32 = 0 var x uint32 = 0 @@ -137,7 +137,7 @@ func ELFHash(str []byte) uint32 { return hash } -// ELF Hash Function 64 +// ELFHash64 implements the classic ELF hash algorithm for 64 bits. func ELFHash64(str []byte) uint64 { var hash uint64 = 0 var x uint64 = 0 @@ -151,7 +151,7 @@ func ELFHash64(str []byte) uint64 { return hash } -// DJB Hash Function +// DJBHash implements the classic DJB hash algorithm for 32 bits. func DJBHash(str []byte) uint32 { var hash uint32 = 5381 for i := 0; i < len(str); i++ { @@ -160,7 +160,7 @@ func DJBHash(str []byte) uint32 { return hash } -// DJB Hash Function 64. +// DJBHash64 implements the classic DJB hash algorithm for 64 bits. func DJBHash64(str []byte) uint64 { var hash uint64 = 5381 for i := 0; i < len(str); i++ { @@ -169,7 +169,7 @@ func DJBHash64(str []byte) uint64 { return hash } -// AP Hash Function +// APHash implements the classic AP hash algorithm for 32 bits. func APHash(str []byte) uint32 { var hash uint32 = 0 for i := 0; i < len(str); i++ { @@ -182,7 +182,7 @@ func APHash(str []byte) uint32 { return hash } -// AP Hash Function 64 +// APHash64 implements the classic AP hash algorithm for 64 bits. func APHash64(str []byte) uint64 { var hash uint64 = 0 for i := 0; i < len(str); i++ { diff --git a/encoding/ghash/ghash_z_unit_basic_test.go b/encoding/ghash/ghash_z_unit_basic_test.go index b1b97d536..3da11ffcc 100755 --- a/encoding/ghash/ghash_z_unit_basic_test.go +++ b/encoding/ghash/ghash_z_unit_basic_test.go @@ -1,3 +1,9 @@ +// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. +// +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, +// You can obtain one at https://github.com/gogf/gf. + package ghash_test import ( diff --git a/encoding/gjson/gjson_z_example_conversion_test.go b/encoding/gjson/gjson_z_example_conversion_test.go index 4299256fe..9c3ec2f90 100644 --- a/encoding/gjson/gjson_z_example_conversion_test.go +++ b/encoding/gjson/gjson_z_example_conversion_test.go @@ -48,10 +48,10 @@ func Example_conversionNormalFormats() { // ====================== // YAML: // users: - // array: - // - John - // - Ming - // count: 1 + // array: + // - John + // - Ming + // count: 1 // // ====================== // TOML: diff --git a/encoding/gjson/gjson_z_unit_load_test.go b/encoding/gjson/gjson_z_unit_load_test.go index 09797bf74..d517e8de9 100644 --- a/encoding/gjson/gjson_z_unit_load_test.go +++ b/encoding/gjson/gjson_z_unit_load_test.go @@ -246,3 +246,46 @@ enable=true } }) } + +func Test_Load_YamlWithV3(t *testing.T) { + content := ` +# CLI tool, only in development environment. +# https://goframe.org/pages/viewpage.action?pageId=3673173 +gfcli: + gen: + dao: + - path : "../../pkg/oss/oss/internal" + group : "oss" + stdTime : true + descriptionTag : true + noJsonTag : true + noModelComment : true + overwriteDao : true + modelFileForDao : "model_dao.go" + tablesEx : | + bpmn_info, + dlocker, + dlocker_detail, + message_table, + monitor_data, + resource_param_info, + version_info, + version_topology_info, + work_flow, + work_flow_step_info, + work_flow_undo_step_info + + - path : "../../pkg/oss/workflow/internal" + group : "workflow" + stdTime : true + descriptionTag : true + noJsonTag : true + noModelComment : true + overwriteDao : true + modelFileForDao : "model_dao.go" +` + gtest.C(t, func(t *gtest.T) { + _, err := gjson.LoadContent(content) + t.AssertNil(err) + }) +} diff --git a/encoding/gyaml/gyaml.go b/encoding/gyaml/gyaml.go index 2061ac06c..3dfe52879 100644 --- a/encoding/gyaml/gyaml.go +++ b/encoding/gyaml/gyaml.go @@ -8,32 +8,50 @@ package gyaml import ( + "github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/internal/json" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" "github.com/gogf/gf/v2/util/gconv" ) -func Encode(v interface{}) ([]byte, error) { - return yaml.Marshal(v) +func Encode(value interface{}) (out []byte, err error) { + if out, err = yaml.Marshal(value); err != nil { + err = gerror.Wrap(err, `encode value to yaml failed`) + } + return } -func Decode(v []byte) (interface{}, error) { - var result map[string]interface{} - if err := yaml.Unmarshal(v, &result); err != nil { +func Decode(value []byte) (interface{}, error) { + var ( + result map[string]interface{} + err error + ) + if err = yaml.Unmarshal(value, &result); err != nil { + err = gerror.Wrap(err, `decode yaml failed`) return nil, err } return gconv.MapDeep(result), nil } -func DecodeTo(v []byte, result interface{}) error { - return yaml.Unmarshal(v, result) +func DecodeTo(value []byte, result interface{}) (err error) { + err = yaml.Unmarshal(value, result) + if err != nil { + err = gerror.Wrap(err, `encode yaml to value failed`) + } + return } -func ToJson(v []byte) ([]byte, error) { - if r, err := Decode(v); err != nil { +func ToJson(value []byte) (out []byte, err error) { + var ( + result interface{} + ) + if result, err = Decode(value); err != nil { return nil, err } else { - return json.Marshal(r) + if out, err = json.Marshal(result); err != nil { + err = gerror.Wrap(err, `convert yaml to json failed`) + } + return out, err } } diff --git a/go.mod b/go.mod index 930ea3f06..002be54d1 100644 --- a/go.mod +++ b/go.mod @@ -16,5 +16,5 @@ require ( go.opentelemetry.io/otel/trace v1.0.0 golang.org/x/net v0.0.0-20210520170846-37e1c6afe023 golang.org/x/text v0.3.6 - gopkg.in/yaml.v2 v2.4.0 + gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b ) diff --git a/go.sum b/go.sum index 3265432cc..af0926c5d 100644 --- a/go.sum +++ b/go.sum @@ -15,14 +15,6 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWpgI= github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU= -github.com/getkin/kin-openapi v0.76.0 h1:j77zg3Ec+k+r+GA3d8hBoXpAc6KX9TbBPrwQGBIy2sY= -github.com/getkin/kin-openapi v0.76.0/go.mod h1:660oXbgy5JFMKreazJaQTw7o+X00qeSyhcnluiMv+Xg= -github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= -github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY= -github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= -github.com/go-openapi/swag v0.19.5 h1:lTz6Ys4CmqqCQmZPBlbQENR1/GucA2bzYTE12Pw4tFY= -github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= github.com/go-redis/redis/v8 v8.11.3 h1:GCjoYp8c+yQTJfc0n69iwSiHjvuAdruxl7elnZCxgt8= github.com/go-redis/redis/v8 v8.11.3/go.mod h1:xNJ9xDG09FsIPwh3bWdk+0oDWHbtF9rPN0F/oD9XeKc= github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= @@ -44,20 +36,11 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grokify/html-strip-tags-go v0.0.1 h1:0fThFwLbW7P/kOiTBs03FsJSV9RM2M/Q/MOnCQxKMo0= github.com/grokify/html-strip-tags-go v0.0.1/go.mod h1:2Su6romC5/1VXOQMaWL2yb618ARB8iVo6/DR99A6d78= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= -github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e h1:hB2xlXdHp/pmPZq0y3QnmWAArdw9PqbmotexnWx/FU8= -github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= @@ -80,7 +63,6 @@ github.com/onsi/gomega v1.15.0/go.mod h1:cIuvLEne0aoVhAgh/O6ac0Op8WWw9H6eYCriF+t 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/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= @@ -141,9 +123,8 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2 google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= @@ -154,3 +135,5 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=