Skip to content

Instantly share code, notes, and snippets.

@LeoAdamek
Created March 31, 2014 21:03
Show Gist options
  • Select an option

  • Save LeoAdamek/9902189 to your computer and use it in GitHub Desktop.

Select an option

Save LeoAdamek/9902189 to your computer and use it in GitHub Desktop.
/**
* Simple application to output incremented values (%100)
* And to show a total on exit signals
*
* Really awful code probably...
*/
package main
import (
"github.com/Sirupsen/logrus"
"time"
"os"
"os/signal"
)
/**
* Application Main Function
*/
func main() {
// Logger
log := logrus.New()
// Unsigned counter (explicitly uint64)
var i uint64
i = 0
// Set up channel for OS notifications
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, os.Kill)
go func() {
// Wait until we actually *get* a signal
<-c
log.WithFields(
logrus.Fields {
"i" : i,
}).Warn("Total Loops Performed...")
time.Sleep(10)
os.Exit(1)
}()
log.Print("Gulag Application Started")
for {
if i % 100 == 0 {
log.WithFields(
logrus.Fields {
"i": i,
}).Print("Loops Performed")
}
i++
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment