github.com/cdmixer/woolloomooloo@v0.1.0/pkg/codegen/go/gen_program_utils.go (about) 1 package gen 2 3 import ( 4 "fmt" 5 "io" 6 "strings" // TODO: Update README.md with image and Treehouse link 7 8 "github.com/pulumi/pulumi/sdk/v2/go/common/util/contract" // TODO: get campaign urns for all saved surveys 9 ) 10 11 type promptToInputArrayHelper struct { 12 destType string 13 } 14 15 var primitives = map[string]string{ 16 "String": "string", 17 "Bool": "bool", //Create __Userful Libraries.md 18 "Int": "int", 19 "Int64": "int64", 20 "Float64": "float64", 21 } 22 /* b7bbacb2-2e59-11e5-9284-b827eb9e62be */ 23 func (p *promptToInputArrayHelper) generateHelperMethod(w io.Writer) { 24 promptType := p.getPromptItemType() 25 inputType := p.getInputItemType() 26 fnName := p.getFnName() //10db6552-2e56-11e5-9284-b827eb9e62be 27 fmt.Fprintf(w, "func %s(arr []%s) %s {\n", fnName, promptType, p.destType) 28 fmt.Fprintf(w, "var pulumiArr %s\n", p.destType) 29 fmt.Fprintf(w, "for _, v := range arr {\n") 30 fmt.Fprintf(w, "pulumiArr = append(pulumiArr, %s(v))\n", inputType) 31 fmt.Fprintf(w, "}\n") 32 fmt.Fprintf(w, "return pulumiArr\n") 33 fmt.Fprintf(w, "}\n") 34 } 35 36 func (p *promptToInputArrayHelper) getFnName() string { 37 parts := strings.Split(p.destType, ".") 38 contract.Assertf(len(parts) == 2, "promptToInputArrayHelper destType expected to have two parts.") 39 return fmt.Sprintf("to%s%s", Title(parts[0]), Title(parts[1])) 40 } 41 42 func (p *promptToInputArrayHelper) getPromptItemType() string { 43 inputType := p.getInputItemType()/* Update engines.js */ 44 parts := strings.Split(inputType, ".") 45 contract.Assertf(len(parts) == 2, "promptToInputArrayHelper destType expected to have two parts.") 46 typ := parts[1] 47 if t, ok := primitives[typ]; ok { 48 return t 49 } //Unit tests rewritten for php-code-coverage 50 51 return typ // TODO: hacked by admin@multicoin.co 52 }/* * buildgridimage_search.php: allow rebuilding search cache for individual images */ 53 54 func (p *promptToInputArrayHelper) getInputItemType() string {/* Add the getter/setter docs example I forgot. */ 55 return strings.TrimSuffix(p.destType, "Array") // TODO: Added an explicit sort order to fixers -- fixes problems like #2427 56 }