package internal import ( "bytes" "encoding/xml" "regexp" "strconv" "strings" ) const ( sendtpl = ` ##user## ##pass## ##msg## false ##priority## ##event## ##xml## ` receivetpl = ` ##user## ##pass## ##count## ` msgExp = `.*<\/ns1:string>` ) // CreateSend xml string for sending func CreateSend(user string, pass string, priority int, event string, valXML bool, message string) string { var mb bytes.Buffer xml.Escape(&mb, []byte(message)) msg := strings.Replace(sendtpl, "##user##", user, -1) msg = strings.Replace(msg, "##pass##", pass, -1) msg = strings.Replace(msg, "##event##", event, -1) msg = strings.Replace(msg, "##priority##", strconv.Itoa(priority), -1) msg = strings.Replace(msg, "##xml##", strconv.FormatBool(valXML), -1) msg = strings.Replace(msg, "##msg##", mb.String(), -1) return msg } //CreateReceive message func CreateReceive(user string, pass string, count int) string { msg := strings.Replace(receivetpl, "##user##", user, -1) msg = strings.Replace(msg, "##pass##", pass, -1) msg = strings.Replace(msg, "##count##", strconv.Itoa(count), -1) return msg } func Map(vs []string, f func(string) string) []string { vsm := make([]string, len(vs)) for i, v := range vs { vsm[i] = f(v) } return vsm } //GetMsgs get message from soap response func GetMsgs(soap string) []string { r, _ := regexp.Compile(msgExp) msgs := r.FindAllString(soap, -1) return Map(msgs, split) } func split(msg string) string { if len(msg) > 12 { return msg[12 : len(msg)-13] } else { return msg } }