-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathh.go
46 lines (40 loc) · 907 Bytes
/
h.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import "encoding/json"
// 字符串属性结构
type AttrStringStruct struct {
Key string
Value string
}
// 对象属性结构
type AttrInterfaceStruct struct {
Key string
Value interface{}
}
// 生成一个element tag
func H(eleName string, child string, attr string) string {
return "<" + eleName + attr + ">" + child + "</" + eleName + ">"
}
// 返回一串value为字符串的props字符串
func AttrString(attr []AttrStringStruct) string {
a := " "
if len(attr) > 0 {
for i := range attr {
a += attr[i].Key + `="` + attr[i].Value + `" `
}
}
return a
}
// 返回一串value为对象的props字符串
func AttrInterface(attr []AttrInterfaceStruct) string {
a := " "
if len(attr) > 0 {
for i := range attr {
atr, _ := json.Marshal(attr[i].Value)
if string(atr) == "{}" {
continue
}
a += attr[i].Key + `={` + string(atr) + `} `
}
}
return a
}