refactor: move UnmarshalBase64UrlJSON to encoding to prevent an import loop
This commit is contained in:
parent
039fbc1867
commit
e6034b9aae
|
@ -7,7 +7,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/internal/bases"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/serialize"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/types"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/utils"
|
||||
"github.com/vmihailenco/msgpack/v5"
|
||||
|
@ -213,7 +212,7 @@ func (b CID) MarshalJSON() ([]byte, error) {
|
|||
}
|
||||
|
||||
func (cid *CID) UnmarshalJSON(data []byte) error {
|
||||
decData, err := serialize.UnmarshalBase64UrlJSON(data)
|
||||
decData, err := UnmarshalBase64UrlJSON(data)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
package serialize
|
||||
package encoding
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"github.com/multiformats/go-multibase"
|
||||
)
|
||||
import "encoding/base64"
|
||||
|
||||
func UnmarshalBase64UrlJSON(data []byte) ([]byte, error) {
|
||||
strData := string(data)
|
||||
|
@ -15,15 +12,16 @@ func UnmarshalBase64UrlJSON(data []byte) ([]byte, error) {
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
if strData[0] == 'u' {
|
||||
_, decoded, err := multibase.Decode(strData)
|
||||
if err != nil {
|
||||
decodedData, err := MultibaseDecodeString(strData)
|
||||
if err != nil {
|
||||
if err != ErrMultibaseEncodingNotSupported {
|
||||
return nil, err
|
||||
}
|
||||
return decoded, nil
|
||||
} else {
|
||||
return decodedData, nil
|
||||
}
|
||||
|
||||
decodedData, err := base64.RawURLEncoding.DecodeString(strData)
|
||||
decodedData, err = base64.RawURLEncoding.DecodeString(strData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
|
@ -3,7 +3,6 @@ package encoding
|
|||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/serialize"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/types"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/utils"
|
||||
"github.com/vmihailenco/msgpack/v5"
|
||||
|
@ -101,7 +100,7 @@ func (c EncryptedCID) MarshalJSON() ([]byte, error) {
|
|||
}
|
||||
|
||||
func (c *EncryptedCID) UnmarshalJSON(data []byte) error {
|
||||
decData, err := serialize.UnmarshalBase64UrlJSON(data)
|
||||
decData, err := UnmarshalBase64UrlJSON(data)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in New Issue