Compare commits
4 Commits
feature/js
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| c9ba29f9f6 | |||
| 86c1a4a3a9 | |||
| 8d68e6106e | |||
| 0c3d7b7e92 |
@@ -15,6 +15,8 @@ import "io"
|
|||||||
//
|
//
|
||||||
// Date : 16:55 2024/10/23
|
// Date : 16:55 2024/10/23
|
||||||
type Serializable interface {
|
type Serializable interface {
|
||||||
|
// Unmarshal 反序列化
|
||||||
|
Unmarshal(byteData []byte, receiver any) error
|
||||||
// UnmarshalWithNumber 反序列化,同时解析数字
|
// UnmarshalWithNumber 反序列化,同时解析数字
|
||||||
UnmarshalWithNumber(byteData []byte, receiver any) error
|
UnmarshalWithNumber(byteData []byte, receiver any) error
|
||||||
// UnmarshalWithNumberIgnoreError 反序列化,同时解析数字, 忽略结果的成功与失败
|
// UnmarshalWithNumberIgnoreError 反序列化,同时解析数字, 忽略结果的成功与失败
|
||||||
|
|||||||
5
file.go
5
file.go
@@ -10,7 +10,6 @@ package serialize
|
|||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"errors"
|
"errors"
|
||||||
"git.zhangdeman.cn/zhangdeman/consts"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -19,11 +18,13 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"git.zhangdeman.cn/zhangdeman/consts"
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
|
|
||||||
"git.zhangdeman.cn/zhangdeman/util/define"
|
"git.zhangdeman.cn/zhangdeman/util/define"
|
||||||
|
|
||||||
"github.com/go-ini/ini"
|
"gopkg.in/ini.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
14
go.mod
14
go.mod
@@ -5,10 +5,12 @@ go 1.23.0
|
|||||||
toolchain go1.24.2
|
toolchain go1.24.2
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20240618042405-6ee2c904644e
|
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20260110085649-492e9bae2f71
|
||||||
github.com/BurntSushi/toml v1.5.0
|
git.zhangdeman.cn/zhangdeman/util v0.0.0-20260105024213-3d76b1bcde5a
|
||||||
github.com/go-ini/ini v1.67.0
|
github.com/BurntSushi/toml v1.6.0
|
||||||
|
github.com/sbabiv/xml2map v1.2.1
|
||||||
|
gopkg.in/ini.v1 v1.67.1
|
||||||
gopkg.in/yaml.v3 v3.0.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250425024726-cc17224cb995
|
)
|
||||||
github.com/stretchr/testify v1.9.0 // indirect
|
|
||||||
)
|
require github.com/stretchr/testify v1.11.1 // indirect
|
||||||
|
|||||||
32
go.sum
32
go.sum
@@ -1,26 +1,42 @@
|
|||||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250425024726-cc17224cb995 h1:LmPRAf0AsxRVFPibdpZR89ajlsz8hof2IvMMyTqiEq4=
|
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20260110085649-492e9bae2f71 h1:ivFHFIHbviWLvyQyCKw0C0Nd8hfobp9lPpKbbxdTtDY=
|
||||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250425024726-cc17224cb995/go.mod h1:5p8CEKGBxi7qPtTXDI3HDmqKAfIm5i/aBWdrbkbdNjc=
|
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20260110085649-492e9bae2f71/go.mod h1:5p8CEKGBxi7qPtTXDI3HDmqKAfIm5i/aBWdrbkbdNjc=
|
||||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20240618042405-6ee2c904644e h1:Q973S6CcWr1ICZhFI1STFOJ+KUImCl2BaIXm6YppBqI=
|
git.zhangdeman.cn/zhangdeman/util v0.0.0-20260105024213-3d76b1bcde5a h1:IGUsWz204BTQlD2l4kenlwJQS4Av2RS2kfUHZ5QVrmw=
|
||||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20240618042405-6ee2c904644e/go.mod h1:VpPjBlwz8U+OxZuxzHQBv1aEEZ3pStH6bZvT21ADEbI=
|
git.zhangdeman.cn/zhangdeman/util v0.0.0-20260105024213-3d76b1bcde5a/go.mod h1:OKI+RVVfRTUf/ox9uDMydtos2YDFr+/UuU4FFZKgPYY=
|
||||||
github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
|
github.com/BurntSushi/toml v1.6.0 h1:dRaEfpa2VI55EwlIW72hMRHdWouJeRF7TPYhI+AUQjk=
|
||||||
github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
github.com/BurntSushi/toml v1.6.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
||||||
|
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 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A=
|
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
|
||||||
github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
|
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g=
|
github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g=
|
||||||
github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k=
|
github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k=
|
||||||
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
|
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
|
||||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
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/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/sbabiv/xml2map v1.2.1 h1:1lT7t0hhUvXZCkdxqtq4n8/ZCnwLWGq4rDuDv5XOoFE=
|
||||||
|
github.com/sbabiv/xml2map v1.2.1/go.mod h1:2TPoAfcaM7+Sd4iriPvzyntb2mx7GY+kkQpB/GQa/eo=
|
||||||
github.com/smarty/assertions v1.15.0 h1:cR//PqUBUiQRakZWqBiFFQ9wb8emQGDb0HeGdqGByCY=
|
github.com/smarty/assertions v1.15.0 h1:cR//PqUBUiQRakZWqBiFFQ9wb8emQGDb0HeGdqGByCY=
|
||||||
github.com/smarty/assertions v1.15.0/go.mod h1:yABtdzeQs6l1brC900WlRNwj6ZR55d7B+E8C6HtKdec=
|
github.com/smarty/assertions v1.15.0/go.mod h1:yABtdzeQs6l1brC900WlRNwj6ZR55d7B+E8C6HtKdec=
|
||||||
github.com/smartystreets/goconvey v1.8.1 h1:qGjIddxOk4grTu9JPOU31tVfq3cNdBlNa5sSznIX1xY=
|
github.com/smartystreets/goconvey v1.8.1 h1:qGjIddxOk4grTu9JPOU31tVfq3cNdBlNa5sSznIX1xY=
|
||||||
github.com/smartystreets/goconvey v1.8.1/go.mod h1:+/u4qLyY6x1jReYOp7GOM2FSt8aP9CzCZL03bI28W60=
|
github.com/smartystreets/goconvey v1.8.1/go.mod h1:+/u4qLyY6x1jReYOp7GOM2FSt8aP9CzCZL03bI28W60=
|
||||||
|
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/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
||||||
|
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.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
|
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
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 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
|
||||||
|
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||||
|
gopkg.in/ini.v1 v1.67.1 h1:tVBILHy0R6e4wkYOn3XmiITt/hEVH4TFMYvAX2Ytz6k=
|
||||||
|
gopkg.in/ini.v1 v1.67.1/go.mod h1:x/cyOwCgZqOkJoDIJ3c1KNHMo10+nLGAhh+kn3Zizss=
|
||||||
|
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 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
|||||||
6
ini.go
6
ini.go
@@ -9,7 +9,7 @@ package serialize
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/go-ini/ini"
|
"gopkg.in/ini.v1"
|
||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -20,6 +20,10 @@ var (
|
|||||||
type ownIni struct {
|
type ownIni struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (o *ownIni) Unmarshal(byteData []byte, receiver any) error {
|
||||||
|
return o.UnmarshalWithNumber(byteData, receiver)
|
||||||
|
}
|
||||||
|
|
||||||
func (o *ownIni) UnmarshalWithNumber(byteData []byte, receiver any) error {
|
func (o *ownIni) UnmarshalWithNumber(byteData []byte, receiver any) error {
|
||||||
if nil == receiver {
|
if nil == receiver {
|
||||||
return errors.New("receiver is nil")
|
return errors.New("receiver is nil")
|
||||||
|
|||||||
9
json.go
9
json.go
@@ -33,6 +33,10 @@ func init() {
|
|||||||
type ownJSON struct {
|
type ownJSON struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (oj *ownJSON) Unmarshal(byteData []byte, receiver any) error {
|
||||||
|
return oj.UnmarshalWithNumber(byteData, receiver)
|
||||||
|
}
|
||||||
|
|
||||||
// UnmarshalWithNumber 解析json
|
// UnmarshalWithNumber 解析json
|
||||||
//
|
//
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
@@ -74,6 +78,11 @@ func (oj *ownJSON) UnmarshalWithNumberForIOReaderIgnoreError(ioReader io.ReadClo
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnmarshalForString ...
|
||||||
|
func (oj *ownJSON) UnmarshalForString(input string, receiver any) error {
|
||||||
|
return oj.Unmarshal([]byte(input), receiver)
|
||||||
|
}
|
||||||
|
|
||||||
// UnmarshalWithNumberForString 字符串转结构体
|
// UnmarshalWithNumberForString 字符串转结构体
|
||||||
//
|
//
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
|
|||||||
4
toml.go
4
toml.go
@@ -21,6 +21,10 @@ var (
|
|||||||
type ownToml struct {
|
type ownToml struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (o *ownToml) Unmarshal(byteData []byte, receiver any) error {
|
||||||
|
return o.UnmarshalWithNumber(byteData, receiver)
|
||||||
|
}
|
||||||
|
|
||||||
func (o *ownToml) Parse(byteData []byte, receiver any) (*toml.MetaData, error) {
|
func (o *ownToml) Parse(byteData []byte, receiver any) (*toml.MetaData, error) {
|
||||||
if nil == receiver {
|
if nil == receiver {
|
||||||
return nil, errors.New("receiver is nil")
|
return nil, errors.New("receiver is nil")
|
||||||
|
|||||||
10
xml.go
10
xml.go
@@ -10,6 +10,7 @@ package serialize
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
|
"github.com/sbabiv/xml2map"
|
||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -19,8 +20,15 @@ var (
|
|||||||
|
|
||||||
type ownXml struct{}
|
type ownXml struct{}
|
||||||
|
|
||||||
|
func (o *ownXml) Unmarshal(byteData []byte, receiver any) error {
|
||||||
|
return o.UnmarshalWithNumber(byteData, receiver)
|
||||||
|
}
|
||||||
func (o *ownXml) UnmarshalWithNumber(byteData []byte, receiver any) error {
|
func (o *ownXml) UnmarshalWithNumber(byteData []byte, receiver any) error {
|
||||||
return xml.NewDecoder(bytes.NewReader(byteData)).Decode(receiver)
|
res, err := xml2map.NewDecoder(bytes.NewReader(byteData)).Decode()
|
||||||
|
if nil != err {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return JSON.Transition(res, receiver)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *ownXml) UnmarshalWithNumberIgnoreError(byteData []byte, receiver any) {
|
func (o *ownXml) UnmarshalWithNumberIgnoreError(byteData []byte, receiver any) {
|
||||||
|
|||||||
3
yml.go
3
yml.go
@@ -40,6 +40,9 @@ func (o *ownYml) MarshalForStringIgnoreError(input any) string {
|
|||||||
return string(o.MarshalForByteIgnoreError(input))
|
return string(o.MarshalForByteIgnoreError(input))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (o *ownYml) Unmarshal(byteData []byte, receiver any) error {
|
||||||
|
return o.UnmarshalWithNumber(byteData, receiver)
|
||||||
|
}
|
||||||
func (o *ownYml) UnmarshalWithNumber(byteData []byte, receiver any) error {
|
func (o *ownYml) UnmarshalWithNumber(byteData []byte, receiver any) error {
|
||||||
return yaml.NewDecoder(bytes.NewReader(byteData)).Decode(receiver)
|
return yaml.NewDecoder(bytes.NewReader(byteData)).Decode(receiver)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user