Skip to content

Commit

Permalink
clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
ryansu committed Jun 16, 2021
1 parent 8b4f3fc commit ed03d9b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions component/gin/gin.go → component/gin/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (g *Component) OnAfterInit() {
err = g.server.ListenAndServe()
}

if err != nil {
if err != http.ErrServerClosed {
cherryLogger.Infof("[component = %s] run error = %s", g.name, err)
}
}()
Expand All @@ -160,10 +160,13 @@ func (g *Component) OnBeforeStop() {
}

func (g *Component) OnStop() {
err := g.server.Shutdown(context.Background())
cherryLogger.Infof("[component = %s] shutdown gin component on %s", g.name, g.options.Address)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)

defer cancel()

if err != nil {
if err := g.server.Shutdown(ctx); err != nil {
cherryLogger.Info(err.Error())
}

cherryLogger.Infof("[component = %s] shutdown gin component on %s", g.name, g.options.Address)
}
4 changes: 2 additions & 2 deletions net/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (a *Agent) Kick(reason string) error {
cherryLogger.Warn(err)
}

cherryLogger.Debugf("kick session[%s] reason[%s]", a.Session, reason)
cherryLogger.Debugf("kick session[%s], reason[%s]", a.Session, reason)
return nil
}

Expand Down Expand Up @@ -291,7 +291,7 @@ func (a *Agent) write() {
case bytes := <-a.chWrite:
_, err := a.conn.Write(bytes)
if err != nil {
cherryLogger.Error(err)
cherryLogger.Warn(err)
return
}
case <-ticker.C:
Expand Down

0 comments on commit ed03d9b

Please sign in to comment.