From f617c9cda4c1604bc9b494747dc757a01a435ce7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Mon, 28 Apr 2025 11:52:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0ini=E5=BA=8F=E5=88=97?= =?UTF-8?q?=E5=8C=96=E8=83=BD=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ini.go | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ toml.go | 2 +- 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 ini.go diff --git a/ini.go b/ini.go new file mode 100644 index 0000000..1eea5fe --- /dev/null +++ b/ini.go @@ -0,0 +1,67 @@ +// Package serialize ... +// +// Description : serialize ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 2025-04-28 11:32 +package serialize + +import ( + "errors" + "github.com/go-ini/ini" + "io" +) + +var ( + Ini = &ownIni{} +) + +type ownIni struct { +} + +func (o *ownIni) UnmarshalWithNumber(byteData []byte, receiver any) error { + if nil == receiver { + return errors.New("receiver is nil") + } + return ini.MapTo(receiver, byteData) +} + +func (o *ownIni) UnmarshalWithNumberIgnoreError(byteData []byte, receiver any) { + _ = o.UnmarshalWithNumber(byteData, receiver) +} + +func (o *ownIni) UnmarshalWithNumberForIOReader(ioReader io.ReadCloser, receiver any) error { + if nil == receiver { + return errors.New("receiver is nil") + } + return ini.MapTo(receiver, ioReader) +} + +func (o *ownIni) UnmarshalWithNumberForIOReaderIgnoreError(ioReader io.ReadCloser, receiver any) { + _ = o.UnmarshalWithNumberForIOReader(ioReader, receiver) +} + +func (o *ownIni) UnmarshalWithNumberForString(input string, receiver any) error { + return o.UnmarshalWithNumber([]byte(input), receiver) +} + +func (o *ownIni) UnmarshalWithNumberForStringIgnoreError(input string, receiver any) { + _ = o.UnmarshalWithNumberForString(input, receiver) +} + +func (o *ownIni) MarshalForByte(input any) ([]byte, error) { + return JSON.MarshalForByte(input) +} + +func (o *ownIni) MarshalForByteIgnoreError(input any) []byte { + return JSON.MarshalForByteIgnoreError(input) +} + +func (o *ownIni) MarshalForString(input any) (string, error) { + return JSON.MarshalForString(input) +} + +func (o *ownIni) MarshalForStringIgnoreError(input any) string { + return JSON.MarshalForStringIgnoreError(input) +} diff --git a/toml.go b/toml.go index 72c8b0b..e22da4d 100644 --- a/toml.go +++ b/toml.go @@ -15,7 +15,7 @@ import ( ) var ( - Toml *ownToml + Toml = &ownToml{} ) type ownToml struct {