Created
May 11, 2015 22:40
-
-
Save iporsut/ef8fc1c48f229b3f94ae to your computer and use it in GitHub Desktop.
scan line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"flag" | |
"fmt" | |
"os" | |
"strings" | |
) | |
func ReadWantedLines(filename string) chan string { | |
yield := make(chan string, 1) | |
go func() { | |
f, err := os.Open(filename) | |
if err != nil { | |
fmt.Printf("error opening file: %v\n", err) | |
} | |
defer func() { | |
f.Close() | |
close(yield) | |
}() | |
scanner := bufio.NewScanner(f) | |
for scanner.Scan() { | |
s := scanner.Text() | |
fmt.Println("read s=", s) | |
if strings.HasPrefix("wanted=", s) { | |
fmt.Println("wanted s=", s) | |
yield <- s | |
} | |
} | |
}() | |
return yield | |
} | |
func NonComplexProcess(s string) string { | |
return s | |
} | |
func main() { | |
var filename string | |
flag.StringVar(&filename, "f", "", "a filename") | |
flag.Parse() | |
for s := range ReadWantedLines(filename) { | |
fmt.Println(s) | |
if strings.HasPrefix(s, "wanted=") { | |
message := NonComplexProcess(s) | |
fmt.Println(message) | |
} | |
} | |
fmt.Println("finished") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment