mirror of
https://github.com/vbatts/talks.git
synced 2025-05-23 05:12:31 +00:00
2013-03: adding an old learning lunch
This commit is contained in:
parent
68f582d393
commit
24cea0199b
17 changed files with 718 additions and 0 deletions
40
2013/03-golang-learning-lunch/6-inheritance/main.go
Normal file
40
2013/03-golang-learning-lunch/6-inheritance/main.go
Normal file
|
@ -0,0 +1,40 @@
|
|||
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Job struct {
|
||||
Command string
|
||||
*log.Logger
|
||||
}
|
||||
|
||||
func NewJob(cmd string) *Job {
|
||||
return &Job{ cmd, log.New(os.Stderr, "[Job] ", log.Ldate)}
|
||||
}
|
||||
|
||||
func (j *Job) Run() ([]byte, error) {
|
||||
j.Printf("Running [%s] ...", j.Command)
|
||||
out, err := exec.Command(j.Command).Output()
|
||||
if (err != nil) {
|
||||
j.Fatal(err)
|
||||
return nil, err
|
||||
}
|
||||
j.Printf("Command returned [%s]", out)
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
job := NewJob("uptime")
|
||||
job.Run()
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
job.Run()
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue