Skip to content

interview question keeping company name secret to avoid copy and pasting ;-)

Notifications You must be signed in to change notification settings

marcsantiago/search_keyword

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

search_keyword

interview question keeping company name secret to avoid copy and pasting ;-) Example Use: go run main.go -in example_input_and_output/urls.txt -out example_input_and_output/results.txt -keyword "sign up"

search

import "github.com/marcsantiago/search_keyword/search"

Package search searches for a keyword within the html of pages (safe for concurrent use)

search.go

var (
    // ErrURLEmpty to warn users that they passed an empty string in
    ErrURLEmpty = fmt.Errorf("the url string is empty")
    // ErrDomainMissing domain was missing from the url
    ErrDomainMissing = fmt.Errorf("url domain e.g .com, .net was missing")
)
type Result struct {
    // Keyword is the passed keyword. It is an interface because it can be a string or regular expression
    Keyword interface{}
    // URL is the url passed in
    URL string
    // Found determines whether or not the keyword was matched on the page
    Found bool
}

Result is the basic return type for Search and SearchWithRegex

type Results []Result

Results is the plural of results which implements the Sort interface. Sorting by URL. If the slice needs to be sorted then the user can call sort.Sort

func (Results) Len

func (slice Results) Len() int

func (Results) Less

func (slice Results) Less(i, j int) bool

func (Results) Swap

func (slice Results) Swap(i, j int)
type Scanner struct {
    // contains filtered or unexported fields
}

Scanner is the basic structure used to interact with the html content of the page

func NewScanner(limit int, enableLogging bool) *Scanner

NewScanner returns a new scanner that takes a limit as a paramter to limit the number of goroutines spinning up

func (sc *Scanner) ResultsToReader() (io.Reader, error)

ResultsToReader sorts a slice of Result to an io.Reader so that the end user can decide how they want that data csv, text, etc

func (*Scanner) Search

func (sc *Scanner) Search(URL, keyword string) (err error)

Search looks for the passed keyword in the html respose


Generated by godoc2md

About

interview question keeping company name secret to avoid copy and pasting ;-)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages