|
@@ -4,6 +4,8 @@ import (
|
|
|
"errors"
|
|
"errors"
|
|
|
"fmt"
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
+ "github.com/ghodss/yaml"
|
|
|
|
|
+
|
|
|
"github.com/zu1k/proxypool/config"
|
|
"github.com/zu1k/proxypool/config"
|
|
|
"github.com/zu1k/proxypool/pkg/getter"
|
|
"github.com/zu1k/proxypool/pkg/getter"
|
|
|
)
|
|
)
|
|
@@ -15,7 +17,7 @@ func InitConfigAndGetters(path string) (err error) {
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- if s := config.Config.Sources; len(s) == 0 {
|
|
|
|
|
|
|
+ if s := config.Config.SourceFiles; len(s) == 0 {
|
|
|
return errors.New("no sources")
|
|
return errors.New("no sources")
|
|
|
} else {
|
|
} else {
|
|
|
initGetters(s)
|
|
initGetters(s)
|
|
@@ -23,9 +25,20 @@ func InitConfigAndGetters(path string) (err error) {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func initGetters(sources []config.Source) {
|
|
|
|
|
|
|
+func initGetters(sourceFiles []string) {
|
|
|
Getters = make([]getter.Getter, 0)
|
|
Getters = make([]getter.Getter, 0)
|
|
|
- for _, source := range sources {
|
|
|
|
|
|
|
+ for _, path := range sourceFiles {
|
|
|
|
|
+ source := config.Source{}
|
|
|
|
|
+ data, err := config.ReadFile(path)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ fmt.Errorf("Init SourceFile Error: %s\n", err.Error())
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+ err = yaml.Unmarshal(data, &source)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ fmt.Errorf("Init SourceFile Error: %s\n", err.Error())
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
g, err := getter.NewGetter(source.Type, source.Options)
|
|
g, err := getter.NewGetter(source.Type, source.Options)
|
|
|
if err == nil && g != nil {
|
|
if err == nil && g != nil {
|
|
|
Getters = append(Getters, g)
|
|
Getters = append(Getters, g)
|