You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

dfstore.go 1.9 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright 2022 The Dragonfly Authors
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package config
  17. import (
  18. "errors"
  19. "fmt"
  20. "net/url"
  21. )
  22. type DfstoreConfig struct {
  23. // Address of the object storage service.
  24. Endpoint string `yaml:"endpoint,omitempty" mapstructure:"endpoint,omitempty"`
  25. // Filter is used to generate a unique Task ID by
  26. // filtering unnecessary query params in the URL,
  27. // it is separated by & character.
  28. Filter string `yaml:"filter,omitempty" mapstructure:"filter,omitempty"`
  29. // Mode is the mode in which the backend is written,
  30. // including WriteBack and AsyncWriteBack.
  31. Mode int `yaml:"mode,omitempty" mapstructure:"mode,omitempty"`
  32. // MaxReplicas is the maximum number of
  33. // replicas of an object cache in seed peers.
  34. MaxReplicas int `yaml:"maxReplicas,omitempty" mapstructure:"mode,maxReplicas"`
  35. }
  36. // New dfstore configuration.
  37. func NewDfstore() *DfstoreConfig {
  38. url := url.URL{
  39. Scheme: "http",
  40. Host: fmt.Sprintf("%s:%d", "127.0.0.1", DefaultObjectStorageStartPort),
  41. }
  42. return &DfstoreConfig{
  43. Endpoint: url.String(),
  44. MaxReplicas: DefaultObjectMaxReplicas,
  45. }
  46. }
  47. func (cfg *DfstoreConfig) Validate() error {
  48. if cfg.Endpoint == "" {
  49. return errors.New("dfstore requires parameter endpoint")
  50. }
  51. if _, err := url.ParseRequestURI(cfg.Endpoint); err != nil {
  52. return fmt.Errorf("invalid endpoint: %w", err)
  53. }
  54. return nil
  55. }