Git Product home page Git Product logo

Comments (7)

FitzBogard avatar FitzBogard commented on May 28, 2024
image

from go-zero.

FitzBogard avatar FitzBogard commented on May 28, 2024
image

from go-zero.

FitzBogard avatar FitzBogard commented on May 28, 2024
image

from go-zero.

Issues-translate-bot avatar Issues-translate-bot commented on May 28, 2024

Bot detected the issue body's language is not English, translate it automatically. πŸ‘―πŸ‘­πŸ»πŸ§‘β€πŸ€β€πŸ§‘πŸ‘«πŸ§‘πŸΏβ€πŸ€β€πŸ§‘πŸ»πŸ‘©πŸΎβ€πŸ€β€πŸ‘¨πŸΏπŸ‘¬πŸΏ


image

from go-zero.

FitzBogard avatar FitzBogard commented on May 28, 2024
func convertTypeFromString(kind reflect.Kind, str string) (any, error) {
	switch kind {
	case reflect.Bool:
		switch strings.ToLower(str) {
		case "1", "true":
			return true, nil
		case "0", "false":
			return false, nil
		default:
			return false, errTypeMismatch
		}
	case reflect.Int:
		return strconv.ParseInt(str, 10, intSize)
	case reflect.Int8:
		return strconv.ParseInt(str, 10, 8)
	case reflect.Int16:
		return strconv.ParseInt(str, 10, 16)
	case reflect.Int32:
		return strconv.ParseInt(str, 10, 32)
	case reflect.Int64:
		return strconv.ParseInt(str, 10, 64)
	case reflect.Uint:
		return strconv.ParseUint(str, 10, intSize)
	case reflect.Uint8:
		return strconv.ParseUint(str, 10, 8)
	case reflect.Uint16:
		return strconv.ParseUint(str, 10, 16)
	case reflect.Uint32:
		return strconv.ParseUint(str, 10, 32)
	case reflect.Uint64:
		return strconv.ParseUint(str, 10, 64)
	case reflect.Float32:
		return strconv.ParseFloat(str, 32)
	case reflect.Float64:
		return strconv.ParseFloat(str, 64)
	case reflect.String:
		return str, nil
	default:
		return nil, errUnsupportedType
	}
}

So when I specify a field which type is []any, the element in this any slice should check data type twice in convertTypeFromString, or it will return error

from go-zero.

kesonan avatar kesonan commented on May 28, 2024

json.Number implements the fmt.Stringer interface, so it is treated as a string, and the received type is interface{}, but convertTypeFromString obviously does not support interface. This has always been explained, and even the API syntax does not Any and interface{} types are supported, so we do not consider this issue an issue.

from go-zero.

FitzBogard avatar FitzBogard commented on May 28, 2024

So if we want to declare a variable of type []any in the request body, go-zero cannot match the need?

from go-zero.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.