| 616 | // Output: {"foo":"bar","v4":"192.168.0.1","v6":"2001:db8:85a3::8a2e:370:7334","message":"hello world"} |
| 617 | } |
| 618 | func ExampleContext_IPPrefix() { |
| 619 | pfxV4 := net.IPNet{IP: net.IP{192, 168, 0, 100}, Mask: net.CIDRMask(24, 32)} |
| 620 | pfxV6 := net.IPNet{IP: net.IP{0x20, 0x01, 0x0d, 0xb8, 0x85, 0xa3, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x2e, 0x03, 0x70, 0x73, 0x00}, Mask: net.CIDRMask(64, 128)} |
| 621 | |
| 622 | dst := bytes.Buffer{} |
| 623 | log := New(&dst).With(). |
| 624 | Str("foo", "bar"). |
| 625 | IPPrefix("v4", pfxV4). |
| 626 | IPPrefix("v6", pfxV6). |
| 627 | Logger() |
| 628 | |
| 629 | log.Log().Msg("hello world") |
| 630 | |
| 631 | fmt.Println(decodeIfBinaryToString(dst.Bytes())) |
| 632 | // Output: {"foo":"bar","v4":"192.168.0.100/24","v6":"2001:db8:85a3::8a2e:370:7300/64","message":"hello world"} |
| 633 | } |
| 634 | func ExampleContext_MACAddr() { |
| 635 | mac := net.HardwareAddr{0x12, 0x34, 0x56, 0x78, 0x90, 0xab} |
| 636 | |