X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fcypherpunks.ru%2Fgovpn%2Fstats.go;h=2fa90e49f39bb24799b608a349e9ea5cf9fea99b;hb=ca13f5e54da2d88a65b99814e13c23834ae44342;hp=01e321d48e415eb470159491c449d1739ade9785;hpb=5a55ad42b9b740659e8e89963403c27f7704e50a;p=govpn.git diff --git a/src/cypherpunks.ru/govpn/stats.go b/src/cypherpunks.ru/govpn/stats.go index 01e321d..2fa90e4 100644 --- a/src/cypherpunks.ru/govpn/stats.go +++ b/src/cypherpunks.ru/govpn/stats.go @@ -1,6 +1,6 @@ /* GoVPN -- simple secure free software virtual private network daemon -Copyright (C) 2014-2016 Sergey Matveev +Copyright (C) 2014-2017 Sergey Matveev This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -46,37 +46,45 @@ func StatsProcessor(stats string, peers *KnownPeers) { "port": stats, } - logger.WithFields(fields).WithField("port", stats).Debug("Stats are going to listen") + logger.WithFields(fields).WithField( + "port", stats, + ).Debug("Stats are going to listen") statsPort, err := net.Listen("tcp", stats) if err != nil { - logger.WithError(err).WithField("stats", stats).Error("Can't listen stats server") + logger.WithError(err).WithField( + "stats", stats, + ).Error("Can't listen stats server") return } for { conn, err = statsPort.Accept() if err != nil { - logger.WithFields(fields).WithError(err).Error("Couldn't accept connection") + logger.WithFields(fields).WithError(err).Error("Can't accept connection") continue } deadLine := time.Now().Add(rwTimeout) if err = conn.SetDeadline(deadLine); err != nil { - logger.WithFields(fields).WithField("deadline", deadLine.String()).WithError(err).Error("Couldn't set deadline") + logger.WithFields(fields).WithField( + "deadline", deadLine.String(), + ).WithError(err).Error("Can't set deadline") } else if _, err = conn.Read(buf); err != nil { - logger.WithFields(fields).WithError(err).Error("Couldn't read buffer") + logger.WithFields(fields).WithError(err).Error("Can't read buffer") } else if _, err = conn.Write([]byte("HTTP/1.0 200 OK\r\nContent-Type: application/json\r\n\r\n")); err != nil { - logger.WithFields(fields).WithError(err).Error("Couldn't write HTTP headers") + logger.WithFields(fields).WithError(err).Error("Can't write HTTP headers") } else { var peersList []*Peer for _, peer := range *peers { peersList = append(peersList, *peer) } if err = json.NewEncoder(conn).Encode(peersList); err != nil { - logger.WithFields(fields).WithField("peers", len(peersList)).WithError(err).Error("Couldn't encode to JSON") + logger.WithFields(fields).WithField( + "peers", len(peersList), + ).WithError(err).Error("Can't encode to JSON") } } if err = conn.Close(); err != nil { - logger.WithFields(fields).WithError(err).Error("Couldn't close connection") + logger.WithFields(fields).WithError(err).Error("Can't close connection") } } }