file.go 545 B

12345678910111213141516171819202122232425262728293031
  1. package config
  2. import (
  3. "fmt"
  4. "github.com/go-kratos/kratos/v2/config"
  5. "github.com/go-kratos/kratos/v2/config/file"
  6. )
  7. type FileSource struct {
  8. Format Format
  9. Path string
  10. }
  11. func (s *FileSource) NewSource() (config.Source, error) {
  12. source := file.NewSource(s.Path)
  13. return source, nil
  14. }
  15. func (s *FileSource) Validate() bool {
  16. if !s.Format.Validate() {
  17. return false
  18. }
  19. if s.Path == "" {
  20. return false
  21. }
  22. return true
  23. }
  24. func (s *FileSource) String() string {
  25. return fmt.Sprintf("file source format:%v, path:%v", s.Format, s.Path)
  26. }