Skip to content

Commit

Permalink
read me example changes
Browse files Browse the repository at this point in the history
  • Loading branch information
takama committed Jan 31, 2015
1 parent bf9133d commit 2e32035
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func main() {

Real example:
```go
// Example of the daemon with echo service
// Example of a daemon with echo service
package main

import (
Expand All @@ -57,6 +57,8 @@ const (
port = ":9977"
)

var stdlog, errlog *log.Logger

// Service has embedded daemon
type Service struct {
daemon.Daemon
Expand Down Expand Up @@ -111,8 +113,8 @@ func (service *Service) Manage() (string, error) {
case conn := <-listen:
go handleClient(conn)
case killSignal := <-interrupt:
log.Println("Got signal:", killSignal)
log.Println("Stoping listening on ", listener.Addr())
stdlog.Println("Got signal:", killSignal)
stdlog.Println("Stoping listening on ", listener.Addr())
listener.Close()
if killSignal == os.Interrupt {
return "Daemon was interruped by system signal", nil
Expand Down Expand Up @@ -147,20 +149,24 @@ func handleClient(client net.Conn) {
}
}

func init() {
stdlog = log.New(os.Stdout, "", log.Ldate|log.Ltime)
errlog = log.New(os.Stderr, "", log.Ldate|log.Ltime)
}

func main() {
srv, err := daemon.New(name, description)
if err != nil {
fmt.Println("Error: ", err)
errlog.Println("Error: ", err)
os.Exit(1)
}
service := &Service{srv}
status, err := service.Manage()
if err != nil {
fmt.Println(status, "\nError: ", err)
errlog.Println(status, "\nError: ", err)
os.Exit(1)
}
fmt.Println(status)

}
```

Expand Down

0 comments on commit 2e32035

Please sign in to comment.