options.go 716 B

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