options.go 731 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package writer
  2. // Options 可配置参数
  3. type Options struct {
  4. path string
  5. timeFormat string
  6. suffix string //文件扩展名
  7. cap uint
  8. }
  9. func setDefault() Options {
  10. return Options{
  11. path: "/.logs/IotAdmin",
  12. suffix: "log",
  13. }
  14. }
  15. // Option set options
  16. type Option func(*Options)
  17. // WithPath set path
  18. func WithPath(s string) Option {
  19. return func(o *Options) {
  20. o.path = s
  21. }
  22. }
  23. // WithSuffix set suffix
  24. func WithSuffix(s string) Option {
  25. return func(o *Options) {
  26. o.suffix = s
  27. }
  28. }
  29. // WithCap set cap
  30. func WithCap(n uint) Option {
  31. return func(o *Options) {
  32. o.cap = n
  33. }
  34. } // WithTimeFormat set timeFormat
  35. func WithTimeFormat(t string) Option {
  36. return func(o *Options) {
  37. o.timeFormat = t
  38. }
  39. }