Skip to content

Commit

Permalink
clear access ua count when month is over
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxkad committed Dec 18, 2023
1 parent 7fa5474 commit 7589dc9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 36 deletions.
5 changes: 5 additions & 0 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ func (cr *Cluster) GetHandler() (handler http.Handler) {
used := time.Since(start)
if config.RecordServeInfo {
addr, _, _ := net.SplitHostPort(req.RemoteAddr)
if used > time.Minute {
used = used.Truncate(time.Second)
}else if used > time.Second {
used = used.Truncate(time.Microsecond)
}
logInfof("Serve %d | %12v | %-15s | %s | %-4s %s | %q", srw.status, used, addr, req.Proto, req.Method, req.RequestURI, ua)
}
if 200 > srw.status && srw.status >= 400 {
Expand Down
44 changes: 8 additions & 36 deletions socketio.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,10 @@ func ParseEPT(id string) EPacketType {
if len(id) != 1 {
return EP_UNKNOWN
}
switch id {
case "0":
return EP_OPEN
case "1":
return EP_CLOSE
case "2":
return EP_PING
case "3":
return EP_PONG
case "4":
return EP_MESSAGE
}
return EP_UNKNOWN
return EPTFromByte(id[0])
}

func GetEPT(id byte) EPacketType {
func EPTFromByte(id byte) EPacketType {
switch id {
case 0:
return EP_OPEN
Expand Down Expand Up @@ -174,26 +162,10 @@ func ParseSPT(id string) SPacketType {
if len(id) != 1 {
return SP_UNKNOWN
}
switch id {
case "0":
return SP_CONNECT
case "1":
return SP_DISCONNECT
case "2":
return SP_EVENT
case "3":
return SP_ACK
case "4":
return SP_CONNECT_ERROR
case "5":
return SP_BINARY_EVENT
case "6":
return SP_BINARY_ACK
}
return SP_UNKNOWN
return SPTFromByte(id[0])
}

func GetSPT(id byte) SPacketType {
func SPTFromByte(id byte) SPacketType {
switch id {
case 0:
return SP_CONNECT
Expand Down Expand Up @@ -238,12 +210,12 @@ func (p *EPacket) WriteTo(w io.Writer) (n int, err error) {
}

func (p *EPacket) ReadFrom(r io.Reader) (n int, err error) {
t := []byte{0}
n, err = r.Read(t)
var t [1]byte
n, err = r.Read(t[:])
if err != nil || n == 0 {
return
}
p.typ = GetEPT(t[0] - '0')
p.typ = EPTFromByte(t[0] - '0')
if p.typ == EP_UNKNOWN {
return n, fmt.Errorf("Unexpected packet id %c", t[0])
}
Expand Down Expand Up @@ -304,7 +276,7 @@ func (p *SPacket) ParseBuffer(r *bytes.Reader) (err error) {
if err != nil {
return
}
p.typ = GetSPT(b - '0')
p.typ = SPTFromByte(b - '0')
if p.typ == SP_UNKNOWN {
return fmt.Errorf("Unexpected packet id %c", b)
}
Expand Down
1 change: 1 addition & 0 deletions stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func (d *statData) update(newData *statInstData) {
for i := d.Date.Month + 1; i < now.Month; i++ {
d.Months[i] = statInstData{}
}
clear(d.Accesses)
// update history data
if iscont {
if now.Day == 0 && d.Date.IsLastDay() {
Expand Down

0 comments on commit 7589dc9

Please sign in to comment.