diff options
| author | Shulhan <ms@kilabit.info> | 2022-08-16 23:21:43 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2022-08-16 23:21:43 +0700 |
| commit | d769cfe466e2a5f96d396f91f6000c4fc604d836 (patch) | |
| tree | dcea4cfcdb198cc46c97830f2eb17b4fde4f4d98 /halog.go | |
| parent | 1ade2eebf51bd64c60b797c077b436b3221202bf (diff) | |
| download | haminer-d769cfe466e2a5f96d396f91f6000c4fc604d836.tar.xz | |
all: use fixed []byte for consuming UDP packet
Instead of using struct UDPPacket to read UDP packet from HAproxy log,
simplify it by using fixed, reusable size of []byte directly.
Diffstat (limited to 'halog.go')
| -rw-r--r-- | halog.go | 21 |
1 files changed, 10 insertions, 11 deletions
@@ -365,26 +365,25 @@ func (halog *Halog) Parse(in []byte, reqHeaders []string) (ok bool) { // // It will return nil and false if UDP packet is nil, have zero length, or // cannot be parsed (rejected). -func (halog *Halog) ParseUDPPacket(p *UDPPacket, reqHeaders []string) bool { - if p == nil { - return false - } - if len(p.Bytes) == 0 { +func (halog *Halog) ParseUDPPacket(packet []byte, reqHeaders []string) bool { + if len(packet) == 0 { return false } - var in []byte + var ( + endIdx int + in []byte + ) - if p.Bytes[0] == '<' { - endIdx := bytes.IndexByte(p.Bytes, '>') + if packet[0] == '<' { + endIdx = bytes.IndexByte(packet, '>') if endIdx < 0 { return false } - in = make([]byte, len(p.Bytes)) - copy(in, p.Bytes[endIdx+1:]) + in = packet[endIdx+1:] } else { - in = p.Bytes + in = packet } return halog.Parse(in, reqHeaders) |
