// parse template 2 file func (servicedDeploy *ServiceDeployWebSocketController) ParseTemplate(ws *websocket.Conn, service entity.Service) bool { writeStringMessage(ws, "Load templateList") template, templateLoadErr := entity.LoadTemplateList(service.Id) if templateLoadErr != nil { writeStringMessage(ws, fmt.Sprintf("Error,%s", templateLoadErr)) return false } writeStringMessage(ws, "Load componentList") component, componentErr := entity.LoadComponentList(service.Id) if componentErr != nil { writeStringMessage(ws, fmt.Sprintf("Error,%s", componentErr)) return false } writeStringMessage(ws, "Parse template") data := make(map[string]string) if len(component) > 0 { for _, item := range component { data[item.Name] = item.Value } } for _, templatefile := range template { if templatefile.FileType == utils.FileTypes_Template { if templatefile.TargetFile == "" { writeStringMessage(ws, fmt.Sprintf("%s TargetFile is null,please set the value", templatefile.Name)) } if templatefile.TemplateFile == "" { writeStringMessage(ws, fmt.Sprintf("%s TemplateFile is null,please set the value", templatefile.Name)) } result, err := utils.ParseTemplateFile2File(templatefile.TargetFile, data, templatefile.TemplateFile) if !result { writeStringMessage(ws, fmt.Sprintf("Error,%s", err)) return result } } } writeStringMessage(ws, "Parse template successful") return true }
fmt.Println(result) fmt.Println(errors) }) It("Test ...string for args []string", func() { // str := []string{"hello", "kity", "hi", "lucy"} Tarry("hello", "kity", "hi", "lucy") }) It("Test parse from map", func() { mmap := make(map[string]string) mmap["mysql_ip"] = "10.162.2.146" mmap["mysql_port"] = "3306" mmap["mysql_user"] = "******" mmap["mysql_passwd"] = "123456" templatesfile := "/home/ubuntu/customservice/cfweb/templates/app-data.xml" utils.ParseTemplateFile2File("/home/ubuntu/temp/app-data.xml", mmap, templatesfile) }) }) type Person struct { Name string Age string } func Tarry(str ...string) { fmt.Println(str) }