-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.go
More file actions
39 lines (30 loc) · 914 Bytes
/
Copy pathstring.go
File metadata and controls
39 lines (30 loc) · 914 Bytes
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
package htmldump
import (
"fmt"
"reflect"
)
func isStringOrPointerToString(fieldType reflect.Type) bool {
if fieldType.Kind() == reflect.Pointer {
return fieldType.Elem().Kind() == reflect.String
}
return fieldType.Kind() == reflect.String
}
// Generate HTML table for a string.
func stringToHTML(doc *htmlDocument, reflectedString reflect.Value) error {
if reflectedString.Kind() != reflect.String {
return fmt.Errorf(`[stringToHTML] only accepts string, got %s`, reflectedString.Kind())
}
table := new(tableT)
table.Caption(fmt.Sprintf("String (length: %d) ", len(reflectedString.String()))).
stringBody(reflectedString).
toHTML(doc)
return nil
}
func (table *tableT) stringBody(reflectedString reflect.Value) *tableT {
str := reflectedString.String()
var row rowT
row.addCell(cellT{value: "Value", key: true})
row.addCell(cellT{value: str})
table.addBodyRow(row)
return table
}