MCPcopy
hub / github.com/alecthomas/kong / floatDecoder

Function floatDecoder

mapper.go:428–456  ·  view source on GitHub ↗
(bits int)

Source from the content-addressed store, hash-verified

426}
427
428func floatDecoder(bits int) MapperFunc {
429 return func(ctx *DecodeContext, target reflect.Value) error {
430 t, err := ctx.Scan.PopValue("float")
431 if err != nil {
432 return err
433 }
434 switch v := t.Value.(type) {
435 case string:
436 n, err := strconv.ParseFloat(v, bits)
437 if err != nil {
438 return fmt.Errorf("expected a float but got %q (%T)", t, t.Value)
439 }
440 target.SetFloat(n)
441
442 case float32:
443 target.SetFloat(float64(v))
444
445 case float64:
446 target.SetFloat(v)
447
448 case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:
449 target.Set(reflect.ValueOf(v))
450
451 default:
452 return fmt.Errorf("expected an int but got %q (%T)", t, t.Value)
453 }
454 return nil
455 }
456}
457
458func mapDecoder(r *Registry) MapperFunc {
459 return func(ctx *DecodeContext, target reflect.Value) error {

Callers 1

RegisterDefaultsMethod · 0.85

Calls 3

PopValueMethod · 0.80
ErrorfMethod · 0.80
SetMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…