chore: change interface{} to any (#2818)

* chore: change interface{} to any

* chore: update goctl version to 1.5.0

* chore: update goctl deps
This commit is contained in:
Kevin Wan
2023-01-24 16:32:02 +08:00
committed by GitHub
parent 7e0ac77139
commit ae87114282
221 changed files with 1910 additions and 2207 deletions

View File

@@ -9,12 +9,12 @@ import (
)
// Marshal marshals v into json bytes.
func Marshal(v interface{}) ([]byte, error) {
func Marshal(v any) ([]byte, error) {
return json.Marshal(v)
}
// MarshalToString marshals v into a string.
func MarshalToString(v interface{}) (string, error) {
func MarshalToString(v any) (string, error) {
data, err := Marshal(v)
if err != nil {
return "", err
@@ -24,7 +24,7 @@ func MarshalToString(v interface{}) (string, error) {
}
// Unmarshal unmarshals data bytes into v.
func Unmarshal(data []byte, v interface{}) error {
func Unmarshal(data []byte, v any) error {
decoder := json.NewDecoder(bytes.NewReader(data))
if err := unmarshalUseNumber(decoder, v); err != nil {
return formatError(string(data), err)
@@ -34,7 +34,7 @@ func Unmarshal(data []byte, v interface{}) error {
}
// UnmarshalFromString unmarshals v from str.
func UnmarshalFromString(str string, v interface{}) error {
func UnmarshalFromString(str string, v any) error {
decoder := json.NewDecoder(strings.NewReader(str))
if err := unmarshalUseNumber(decoder, v); err != nil {
return formatError(str, err)
@@ -44,7 +44,7 @@ func UnmarshalFromString(str string, v interface{}) error {
}
// UnmarshalFromReader unmarshals v from reader.
func UnmarshalFromReader(reader io.Reader, v interface{}) error {
func UnmarshalFromReader(reader io.Reader, v any) error {
var buf strings.Builder
teeReader := io.TeeReader(reader, &buf)
decoder := json.NewDecoder(teeReader)
@@ -55,7 +55,7 @@ func UnmarshalFromReader(reader io.Reader, v interface{}) error {
return nil
}
func unmarshalUseNumber(decoder *json.Decoder, v interface{}) error {
func unmarshalUseNumber(decoder *json.Decoder, v any) error {
decoder.UseNumber()
return decoder.Decode(v)
}