mirror of
https://github.com/openobserve/goflow2.git
synced 2025-10-26 01:24:05 +00:00
Due to IP and MAC addresses being a non-standard type, utils.BinaryRead was not able to decode them. Move these two types inside utils.go and teach BinaryRead to use them. Co-authored-by: lspgn <lspgn@users.noreply.github.com>
21 lines
463 B
Go
21 lines
463 B
Go
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"net/netip"
|
|
)
|
|
|
|
type MacAddress []byte // purely for the formatting purpose
|
|
|
|
func (s *MacAddress) MarshalJSON() ([]byte, error) {
|
|
return []byte(fmt.Sprintf("\"%s\"", net.HardwareAddr([]byte(*s)).String())), nil
|
|
}
|
|
|
|
type IPAddress []byte // purely for the formatting purpose
|
|
|
|
func (s IPAddress) MarshalJSON() ([]byte, error) {
|
|
ip, _ := netip.AddrFromSlice([]byte(s))
|
|
return []byte(fmt.Sprintf("\"%s\"", ip.String())), nil
|
|
}
|