options.go 577 B

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