goyave.dev/goyave/v4@v4.4.11/util/typeutil/typeutil.go (about)

     1  package typeutil
     2  
     3  import (
     4  	"fmt"
     5  	"strconv"
     6  )
     7  
     8  // Map is an alias to map[string]interface{}
     9  // Useful and a cleaner way to create a JSON response object
    10  type Map map[string]interface{}
    11  
    12  // ToFloat64 convert a numeric value to float64.
    13  func ToFloat64(value interface{}) (float64, error) {
    14  	return strconv.ParseFloat(ToString(value), 64)
    15  }
    16  
    17  // ToString convert a value to string.
    18  func ToString(value interface{}) string {
    19  	return fmt.Sprintf("%v", value)
    20  }