options.go 786 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package api
  2. type Options struct {
  3. // URL前缀
  4. urlPrefix string
  5. // 端口
  6. port string
  7. // 日志跳过的打印路径
  8. logSkipPaths []string
  9. }
  10. func (options Options) GetPort() string {
  11. return options.port
  12. }
  13. func (options Options) GetUrlPrefix() string {
  14. return options.urlPrefix
  15. }
  16. type Option func(options *Options)
  17. // WithUrlPrefix 设置URL前缀
  18. func WithUrlPrefix(urlPrefix string) Option {
  19. return func(options *Options) {
  20. options.urlPrefix = urlPrefix
  21. }
  22. }
  23. // WithPort 设置端口
  24. func WithPort(port string) Option {
  25. return func(options *Options) {
  26. options.port = port
  27. }
  28. }
  29. // WithLogSkipPaths 设置日志跳过的打印路径
  30. func WithLogSkipPaths(logSkipPaths ...string) Option {
  31. return func(options *Options) {
  32. options.logSkipPaths = logSkipPaths
  33. }
  34. }