-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoption.go
44 lines (35 loc) · 824 Bytes
/
option.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
package Record2Excel
import (
"github.com/xuri/excelize/v2"
)
type options struct {
headerStyle *excelize.Style
contentStyle *excelize.Style
customStyleFunc func(record any) (style *excelize.Style)
}
var (
defaultHeaderStyle = StyleHorizontalCenter
defaultContentStyle = StyleCenter
)
type Option interface {
apply(*options)
}
type optionFunc func(*options)
func (f optionFunc) apply(opt *options) {
f(opt)
}
func WithHeaderStyle(style *excelize.Style) Option {
return optionFunc(func(o *options) {
o.headerStyle = style
})
}
func WithContentStyle(style *excelize.Style) Option {
return optionFunc(func(o *options) {
o.contentStyle = style
})
}
func WithCustomStyleFunc(f func(record any) (style *excelize.Style)) Option {
return optionFunc(func(o *options) {
o.customStyleFunc = f
})
}