options.go 606 B

123456789101112131415161718192021222324252627282930313233343536
  1. package ds_sdk
  2. import "time"
  3. type DataSource struct {
  4. Name string
  5. Type string
  6. Spec map[string]any
  7. }
  8. type Options struct {
  9. // 必传
  10. token string
  11. baseUrl string
  12. namespace string
  13. // 选传
  14. timeout time.Duration
  15. dataSourceMap map[string]DataSource
  16. }
  17. type Option func(opts *Options)
  18. func WithTimeout(timeout time.Duration) Option {
  19. return func(opts *Options) {
  20. opts.timeout = timeout
  21. }
  22. }
  23. func WithDataSource(dataSources []DataSource) Option {
  24. return func(opts *Options) {
  25. for _, dataSource := range dataSources {
  26. opts.dataSourceMap[dataSource.Name] = dataSource
  27. }
  28. }
  29. }