Skip to content

Commit

Permalink
new feature: import option
Browse files Browse the repository at this point in the history
  • Loading branch information
narukoshin committed Feb 26, 2022
1 parent cb1e8c6 commit 823b14f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
39 changes: 27 additions & 12 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit 823b14f

Please # to comment.