-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Baiju Muthukadan <[email protected]>
- Loading branch information
Showing
19 changed files
with
302 additions
and
317 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"os" | ||
"os/signal" | ||
"strings" | ||
"time" | ||
) | ||
|
||
func watch(word, fp string) error { | ||
|
||
f, err := os.Open(fp) | ||
if err != nil { | ||
return err | ||
} | ||
r := bufio.NewReader(f) | ||
defer f.Close() | ||
for { | ||
line, err := r.ReadBytes('\n') | ||
if err != nil { | ||
if err.Error() == "EOF" { | ||
time.Sleep(2 * time.Second) | ||
continue | ||
} | ||
fmt.Printf("Error: %s\n%v\n", line, err) | ||
} | ||
if strings.Contains(string(line), word) { | ||
fmt.Printf("%s: Matched: %s\n", fp, line) | ||
} | ||
time.Sleep(2 * time.Second) | ||
} | ||
} | ||
|
||
func main() { | ||
word := os.Args[1] | ||
files := []string{} | ||
for _, f := range os.Args[2:len(os.Args)] { | ||
files = append(files, f) | ||
go watch(word, f) | ||
} | ||
sig := make(chan os.Signal, 1) | ||
done := make(chan bool) | ||
signal.Notify(sig, os.Interrupt) | ||
go func() { | ||
for _ = range sig { | ||
done <- true | ||
} | ||
}() | ||
<-done | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
) | ||
|
||
func main() { | ||
t := time.Now() | ||
switch { | ||
case t.Hour() < 12: | ||
fmt.Println("Good morning!") | ||
case t.Hour() < 17: | ||
fmt.Println("Good afternoon.") | ||
default: | ||
fmt.Println("Good evening.") | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
type Circle struct { | ||
Radius float64 | ||
} | ||
|
||
// Area return the area of a circle for the given radius | ||
func (c Circle) Area() float64 { | ||
return 3.14 * c.Radius * c.Radius | ||
} | ||
|
||
func main() { | ||
c := Circle{5.0} | ||
fmt.Println(c.Area()) | ||
} |
Oops, something went wrong.