-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
60 lines (53 loc) · 1.82 KB
/
config.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package retable
import (
"context"
"reflect"
"time"
)
var (
// DefaultStructFieldNaming provides the default StructFieldNaming
// using "col" as title tag, ignores "-" titled fields,
// and uses SpacePascalCase for untagged fields.
// Implements the Viewer interface.
DefaultStructFieldNaming = StructFieldNaming{
Tag: "col",
Ignore: "-",
Untagged: SpacePascalCase,
}
// DefaultStructFieldNamingIgnoreUntagged provides the default StructFieldNaming
// using "col" as title tag, ignores "-" titled as well as untitled fields.
// Implements the Viewer interface.
DefaultStructFieldNamingIgnoreUntagged = StructFieldNaming{
Tag: "col",
Ignore: "-",
Untagged: UseTitle("-"),
}
// SelectViewer selects the best matching Viewer implementation
// for the passed table type.
// By default it returns a StringsViewer for a [][]string table
// and the DefaultStructRowsViewer for all other cases.
SelectViewer = func(table any) (Viewer, error) {
if _, ok := table.([][]string); ok {
return new(StringsViewer), nil
}
return &DefaultStructFieldNaming, nil
}
)
// DefaultStructRowsViewer returns a StructRowsViewer
// that uses DefaultStructFieldNaming and no MapIndices.
func DefaultStructRowsViewer() *StructRowsViewer {
return &StructRowsViewer{StructFieldNaming: DefaultStructFieldNaming}
}
// NoTagsStructRowsViewer returns a StructRowsViewer
// that uses the struct field names as column titles
// without considering struct field tags.
func NoTagsStructRowsViewer() *StructRowsViewer {
return &StructRowsViewer{}
}
var (
typeOfError = reflect.TypeOf((*error)(nil)).Elem()
typeOfContext = reflect.TypeOf((*context.Context)(nil)).Elem()
typeOfView = reflect.TypeOf((*View)(nil)).Elem()
typeOfTime = reflect.TypeOf(time.Time{})
typeOfEmptyStruct = reflect.TypeOf(struct{}{})
)