diff --git a/pkg/config/config.go b/pkg/config/config.go index 54ad388..b9c65a8 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -21,29 +21,44 @@ var ErrConfigNotFound = errors.New("config file not found, please create it to u // Error message if the config file is empty var ErrConfigIsEmpty = errors.New("config file is empty") -func init() { +func init(){ + yml := load_file(YAMLFile) + err := yaml.Unmarshal(yml, &YAMLConfig) + if err != nil { + CError = err + return + } + + // if `import` option is not empty, then importing the file from the option + // if the `import` option is empty, we will use config.yml that is loaded above. + if len(YAMLConfig.Import) != 0 { + yml = load_file(YAMLConfig.Import) + err := yaml.Unmarshal(yml, &YAMLConfig) + if err != nil { + CError = err + return + } + } +} + +func load_file(file_name string) []byte { // Checking if the config file exists - if _, err := os.Stat(YAMLFile); err != nil { + if _, err := os.Stat(file_name); err != nil { CError = ErrConfigNotFound - return + return nil } // Reading config file - yml, err := ioutil.ReadFile(YAMLFile) + yml, err := ioutil.ReadFile(file_name) if err != nil { CError = err - return + return nil } // Checking if the config file is not empty if len(yml) == 0 { CError = ErrConfigIsEmpty - return - } - // writing YML file contents in the struct - err = yaml.Unmarshal(yml, &YAMLConfig) - if err != nil { - CError = err - return + return nil } + return yml } // Checking for errors in the app.Run function diff --git a/pkg/structs/structs.go b/pkg/structs/structs.go index a1a0b0b..d468aac 100644 --- a/pkg/structs/structs.go +++ b/pkg/structs/structs.go @@ -27,6 +27,7 @@ type YAMLCrawl struct { } type YAMLConfig struct { + Import string `yaml:"import"` F []YAMLFields `yaml:"fields"` B YAMLBruteforce `yaml:"bruteforce"` OF YAMLOn_fail `yaml:"on_fail"`