options.go 562 B

1234567891011121314151617181920212223242526272829303132333435
  1. package mhayaConnector
  2. import (
  3. clog "github.com/mhaya/logger"
  4. )
  5. type (
  6. Options struct {
  7. address string
  8. certFile string
  9. keyFile string
  10. chanSize int
  11. }
  12. Option func(*Options)
  13. )
  14. func WithCert(certFile, keyFile string) Option {
  15. return func(o *Options) {
  16. if certFile != "" && keyFile != "" {
  17. o.certFile = certFile
  18. o.keyFile = keyFile
  19. } else {
  20. clog.Errorf("Cert config error.[cert = %s,key = %s]", certFile, keyFile)
  21. }
  22. }
  23. }
  24. func WithChanSize(size int) Option {
  25. return func(o *Options) {
  26. if size > 1 {
  27. o.chanSize = size
  28. }
  29. }
  30. }