Pārlūkot izejas kodu

新增消息内容格式化

dcsunny 4 gadi atpakaļ
vecāks
revīzija
015b4bf160
1 mainītis faili ar 22 papildinājumiem un 0 dzēšanām
  1. 22 0
      third_party/we_message.go

+ 22 - 0
third_party/we_message.go

@@ -0,0 +1,22 @@
+package third_party
+
+import (
+	"bytes"
+	"fmt"
+	"text/template"
+	"time"
+)
+
+func TextContentParse(content string, nickname string) string {
+	t, _ := template.New("text").Parse(content)
+	buf := new(bytes.Buffer)
+	err := t.Execute(buf, map[string]interface{}{
+		"DateTime": time.Now().Format("1月2日"),
+		"Nickname": nickname,
+	})
+	if err != nil {
+		fmt.Printf("格式转换出错了,content:%s,err:%s", content, err)
+		return content
+	}
+	return string(buf.Bytes())
+}