From 478265cd459d57c64186a4214b918843601c56b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Sun, 1 Dec 2024 14:33:23 +0800 Subject: [PATCH] badoption: Finish netip options --- common/json/badoption/netip.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/common/json/badoption/netip.go b/common/json/badoption/netip.go index 61aef82..f22df43 100644 --- a/common/json/badoption/netip.go +++ b/common/json/badoption/netip.go @@ -35,6 +35,13 @@ func (a *Addr) UnmarshalJSON(content []byte) error { type Prefix netip.Prefix +func (p *Prefix) Build(defaultPrefix netip.Prefix) netip.Prefix { + if p == nil { + return defaultPrefix + } + return netip.Prefix(*p) +} + func (p *Prefix) MarshalJSON() ([]byte, error) { return json.Marshal(netip.Prefix(*p).String()) } @@ -55,6 +62,13 @@ func (p *Prefix) UnmarshalJSON(content []byte) error { type Prefixable netip.Prefix +func (p *Prefixable) Build(defaultPrefix netip.Prefix) netip.Prefix { + if p == nil { + return defaultPrefix + } + return netip.Prefix(*p) +} + func (p *Prefixable) MarshalJSON() ([]byte, error) { prefix := netip.Prefix(*p) if prefix.Bits() == prefix.Addr().BitLen() {