1
0

options.go 615 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package source
  2. import (
  3. "context"
  4. "gogs.baozhida.cn/zoie/OAuth-core/config/encoder"
  5. "gogs.baozhida.cn/zoie/OAuth-core/config/encoder/json"
  6. )
  7. type Options struct {
  8. // Encoder
  9. Encoder encoder.Encoder
  10. // for alternative data
  11. Context context.Context
  12. }
  13. type Option func(o *Options)
  14. func NewOptions(opts ...Option) Options {
  15. options := Options{
  16. Encoder: json.NewEncoder(),
  17. Context: context.Background(),
  18. }
  19. for _, o := range opts {
  20. o(&options)
  21. }
  22. return options
  23. }
  24. // WithEncoder sets the source encoder
  25. func WithEncoder(e encoder.Encoder) Option {
  26. return func(o *Options) {
  27. o.Encoder = e
  28. }
  29. }