From e5efa6c5d88b1d449eee3a36032851bd536871d9 Mon Sep 17 00:00:00 2001 From: Makis Maropoulos Date: Thu, 2 Jun 2016 19:39:32 +0300 Subject: [PATCH] Print the banner at PreListen state with a smaller animation --- iris.go | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/iris.go b/iris.go index aee43b83..20b38d7c 100644 --- a/iris.go +++ b/iris.go @@ -8,9 +8,9 @@ import ( "sync" - "time" - "strconv" + "sync/atomic" + "time" "github.com/fatih/color" "github.com/kataras/iris/config" @@ -192,27 +192,33 @@ func (s *Iris) printBanner() { } }() - i := 0 + var i uint64 = 0 + printTicker.OnTick(func() { - if len(banner) <= i { + if len(banner) <= int(atomic.LoadUint64(&i)) { printTicker.Stop() c.Add(color.FgGreen) stationsRunning++ c.Println() - if stationsRunning > 1 { - c.Println("Server[" + strconv.Itoa(stationsRunning) + "]") + + if s.server != nil && s.server.IsListening() { + if stationsRunning > 1 { + c.Println("Server[" + strconv.Itoa(stationsRunning) + "]") + + } + c.Printf("%s: Running at %s\n", time.Now().Format(config.TimeFormat), s.server.Config.ListeningAddr) + } - c.Printf("%s: Running at %s\n", time.Now().Format(config.TimeFormat), s.server.Config.ListeningAddr) c.DisableColor() return } c.Printf("%c", banner[i]) - i++ + atomic.AddUint64(&i, 1) }) - printTicker.Start(time.Duration(1) * time.Millisecond) + printTicker.Start(time.Duration(500) * time.Nanosecond) } @@ -222,6 +228,11 @@ func (s *Iris) printBanner() { // returns the station's Server (*server.Server) // it's a non-blocking func func (s *Iris) PreListen(opt config.Server) *server.Server { + // run the printBanner with nice animation until PreListen and PostListen finish + if !s.config.DisableBanner { + s.printBanner() + } + // set the logger's state s.logger.SetEnable(!s.config.DisableLog) // router preparation, runs only once even if called more than one time. @@ -261,9 +272,6 @@ func (s *Iris) PostListen() { // set the websocket s.initWebsocketServer() - if !s.config.DisableBanner { - s.printBanner() - } s.plugins.DoPostListen(s) }