Skip to content

Commit

Permalink
Merge branch 'pshevtsov-apps-reader'
Browse files Browse the repository at this point in the history
  • Loading branch information
rverton committed Jun 18, 2020
2 parents 92f42cc + a9d33df commit fb291b5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
7 changes: 6 additions & 1 deletion cmd/webanalyze/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,12 @@ func main() {
var wg sync.WaitGroup
hosts := make(chan string)

if wa, err = webanalyze.NewWebAnalyzer(apps); err != nil {
appsFile, err := os.Open(apps)
if err != nil {
log.Fatalf("error: can not open apps file %s: %s", apps, err)
}
defer appsFile.Close()
if wa, err = webanalyze.NewWebAnalyzer(appsFile); err != nil {
log.Fatalf("initialization failed: %v", err)
}

Expand Down
14 changes: 4 additions & 10 deletions wappalyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,10 @@ func DownloadFile(from, to string) error {
return err
}

// load apps from file
func (wa *WebAnalyzer) loadApps(filename string) error {
f, err := os.Open(filename)
if err != nil {
return err
}
defer f.Close()

dec := json.NewDecoder(f)
if err = dec.Decode(&wa.appDefs); err != nil {
// load apps from io.Reader
func (wa *WebAnalyzer) loadApps(r io.Reader) error {
dec := json.NewDecoder(r)
if err := dec.Decode(&wa.appDefs); err != nil {
return err
}

Expand Down
7 changes: 4 additions & 3 deletions webanalyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"crypto/tls"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
Expand Down Expand Up @@ -49,13 +50,13 @@ func (m *Match) updateVersion(version string) {
}
}

// NewWebAnalyzer initializes webanalyzer by passing a filename of the
// NewWebAnalyzer initializes webanalyzer by passing a reader of the
// app definition and an schedulerChan, which allows the scanner to
// add scan jobs on its own
func NewWebAnalyzer(appsFile string) (*WebAnalyzer, error) {
func NewWebAnalyzer(apps io.Reader) (*WebAnalyzer, error) {
wa := new(WebAnalyzer)

if err := wa.loadApps(appsFile); err != nil {
if err := wa.loadApps(apps); err != nil {
return nil, err
}

Expand Down

0 comments on commit fb291b5

Please sign in to comment.