MCPcopy Index your code
hub / github.com/getsops/sops / ValToString

Function ValToString

stores/stores.go:589–607  ·  view source on GitHub ↗

ValToString converts a simple value to a string. It does not handle complex values (arrays and mappings).

(v interface{})

Source from the content-addressed store, hash-verified

587// ValToString converts a simple value to a string.
588// It does not handle complex values (arrays and mappings).
589func ValToString(v interface{}) string {
590 switch v := v.(type) {
591 case float64:
592 result := strconv.FormatFloat(v, 'G', -1, 64)
593 // If the result can be confused with an integer, make sure we have at least one decimal digit
594 if !strings.ContainsRune(result, '.') && !strings.ContainsRune(result, 'E') {
595 result = strconv.FormatFloat(v, 'f', 1, 64)
596 }
597 return result
598 case bool:
599 return strconv.FormatBool(v)
600 case time.Time:
601 return v.Format(time.RFC3339)
602 case fmt.Stringer:
603 return v.String()
604 default:
605 return fmt.Sprintf("%v", v)
606 }
607}

Callers 4

EmitPlainFileMethod · 0.92
encodeTreeMethod · 0.92
mainFunction · 0.92
TestValToStringFunction · 0.85

Calls 2

FormatMethod · 0.80
StringMethod · 0.45

Tested by 1

TestValToStringFunction · 0.68