github.com/alkemics/goflow@v0.2.1/wrappers/constants/utils.go (about) 1 package constants 2 3 import ( 4 "strconv" 5 "strings" 6 7 "github.com/alkemics/goflow" 8 ) 9 10 type constant struct { 11 name string 12 typ string 13 imp goflow.Import 14 } 15 16 func findConstant(inputName string, constants []constant) constant { 17 var cst constant 18 for _, c := range constants { 19 if c.name == inputName { 20 cst = c 21 } 22 } 23 return cst 24 } 25 26 func findHardcodedValue(inputName string) constant { 27 var typ string 28 if strings.HasPrefix(inputName, "\"") && strings.HasSuffix(inputName, "\"") { 29 typ = "string" 30 } else if _, err := strconv.ParseFloat(inputName, 64); err == nil { 31 // Handles ints and floats 32 typ = "@number" 33 } else if _, err := strconv.ParseBool(inputName); err == nil { 34 // Booleans need to be handled after the numbers because `1` is a valid 35 // boolean. 36 typ = "bool" 37 } 38 if typ == "" { 39 return constant{} 40 } 41 return constant{ 42 name: inputName, 43 typ: typ, 44 imp: goflow.Import{}, 45 } 46 }