|
@@ -1,9 +1,7 @@
|
|
|
package config
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
- "fmt"
|
|
|
|
|
"github.com/go-kratos/kratos/v2/config"
|
|
"github.com/go-kratos/kratos/v2/config"
|
|
|
- "github.com/go-kratos/kratos/v2/config/file"
|
|
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
type Source interface {
|
|
type Source interface {
|
|
@@ -30,29 +28,3 @@ func (f Format) Validate() bool {
|
|
|
_, ok := formatMap[f]
|
|
_, ok := formatMap[f]
|
|
|
return ok
|
|
return ok
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-// =======================================
|
|
|
|
|
-
|
|
|
|
|
-type FileSource struct {
|
|
|
|
|
- Format Format
|
|
|
|
|
- Path string
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-func (s *FileSource) NewSource() (config.Source, error) {
|
|
|
|
|
- source := file.NewSource(s.Path)
|
|
|
|
|
- return source, nil
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-func (s *FileSource) Validate() bool {
|
|
|
|
|
- if !s.Format.Validate() {
|
|
|
|
|
- return false
|
|
|
|
|
- }
|
|
|
|
|
- if s.Path == "" {
|
|
|
|
|
- return false
|
|
|
|
|
- }
|
|
|
|
|
- return true
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-func (s *FileSource) String() string {
|
|
|
|
|
- return fmt.Sprintf("file source format:%v, path:%v", s.Format, s.Path)
|
|
|
|
|
-}
|
|
|