Created
March 31, 2014 21:03
-
-
Save LeoAdamek/9902189 to your computer and use it in GitHub Desktop.
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
| /** | |
| * 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