Skip to content

Commit

Permalink
refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhadfield committed May 20, 2018
1 parent 97488ce commit 3c5efcb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 37 deletions.
3 changes: 2 additions & 1 deletion check.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,9 @@ func checkBodyResponse(pattern vPattern, body io.ReadCloser) (result bool) {

var domainIssues issues

// CheckDomains is called from cmd/subtocheck/main.go to kick off the scans
func CheckDomains(path string, configPath *string, debug *bool, quiet *bool) {
var conf Config
var conf config
if *configPath != "" {
conf = readConfig(*configPath)
}
Expand Down
12 changes: 6 additions & 6 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
"gopkg.in/yaml.v2"
)

type Config struct {
type config struct {
Defined bool
Email Email `yaml:"email"`
Email emailConfig `yaml:"email"`
}

type Email struct {
type emailConfig struct {
Provider string
Host string
Port string
Expand All @@ -30,7 +30,7 @@ type Email struct {
Recipients []string
}

func ParseConfigFileContent(content []byte) (config Config, err error) {
func parseConfigFileContent(content []byte) (config config, err error) {
unmarshalErr := yaml.Unmarshal(content, &config)
if unmarshalErr != nil {
err = errors.WithStack(unmarshalErr)
Expand All @@ -39,7 +39,7 @@ func ParseConfigFileContent(content []byte) (config Config, err error) {
return
}

func readConfig(path string) (config Config) {
func readConfig(path string) (config config) {
var configFileContent []byte
var err error
configFileContent, err = ioutil.ReadFile(path)
Expand All @@ -49,7 +49,7 @@ func readConfig(path string) (config Config) {
fmt.Printf("%+v\n", err)
os.Exit(1)
}
config, err = ParseConfigFileContent(configFileContent)
config, err = parseConfigFileContent(configFileContent)
if err != nil {
fmt.Printf("failed to parse configuration: \"%s\"\n", path)
fmt.Println(" -- error --")
Expand Down
12 changes: 6 additions & 6 deletions email.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ import (

func extractEmail(input string) (output string) {
if strings.Contains(input, "<") {
output = GetStringInBetween(input, "<", ">")
output = getStringInBetween(input, "<", ">")
} else {
output = input
}
return
}

func emailConfigDefined(email Email) (result bool) {
if !reflect.DeepEqual(email, Email{}) {
func emailConfigDefined(email emailConfig) (result bool) {
if !reflect.DeepEqual(email, emailConfig{}) {
result = true
}
return
}

func validateEmailSettings(email Email) (err error) {
func validateEmailSettings(email emailConfig) (err error) {
supportedProviders := []string{"ses", "smtp"}
if emailConfigDefined(email) {
if email.Provider == "" {
Expand All @@ -50,7 +50,7 @@ func validateEmailSettings(email Email) (err error) {
return
}

if !StringInSlice(email.Provider, supportedProviders) {
if !stringInSlice(email.Provider, supportedProviders) {
err = fmt.Errorf("email provider '%s' not supported", email.Provider)
return
}
Expand Down Expand Up @@ -113,7 +113,7 @@ func generateRequestIssueList(requestIssues []issue) (filePath string) {
return
}

func emailResults(email Email, pIssues processedIssues) (err error) {
func emailResults(email emailConfig, pIssues processedIssues) (err error) {
msg := gomail.NewMessage()
msg.SetHeader("From", email.Source)
var emailSubject string
Expand Down
26 changes: 2 additions & 24 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func contains(s []int, e int) bool {
return false
}

func GetStringInBetween(str string, start string, end string) (result string) {
func getStringInBetween(str string, start string, end string) (result string) {
s := strings.Index(str, start)
if s == -1 {
return
Expand All @@ -67,7 +67,7 @@ func GetStringInBetween(str string, start string, end string) (result string) {
return str[s:e]
}

func StringInSlice(a string, list []string) bool {
func stringInSlice(a string, list []string) bool {
for _, b := range list {
if b == a {
return true
Expand All @@ -76,28 +76,6 @@ func StringInSlice(a string, list []string) bool {
return false
}

func StringSliceToLower(input []string) (output []string) {
output = Map(input, strings.ToLower)
return
}

func StringInSliceContents(a string, list []string) bool {
for _, b := range list {
if strings.Contains(a, b) {
return true
}
}
return false
}

func Map(vs []string, f func(string) string) []string {
vsm := make([]string, len(vs))
for i, v := range vs {
vsm[i] = f(v)
}
return vsm
}

// PtrToStr returns a pointer to an existing string
func PtrToStr(s string) *string {
return &s
Expand Down

0 comments on commit 3c5efcb

Please sign in to comment.