refactor: remove net.URL and net.CIDR types, improved unmarshal handling

This commit is contained in:
yusing
2025-04-13 07:06:21 +08:00
parent 1eac48e899
commit fce96ff3be
37 changed files with 236 additions and 292 deletions

View File

@@ -6,7 +6,6 @@ import (
"strings"
"github.com/yusing/go-proxy/internal/gperr"
"github.com/yusing/go-proxy/internal/net/types"
"github.com/yusing/go-proxy/internal/utils/strutils"
)
@@ -24,7 +23,7 @@ type (
Key, Value string
}
Host string
CIDR struct{ types.CIDR }
CIDR struct{ net.IPNet }
)
var ErrInvalidHTTPHeaderFilter = gperr.New("invalid http header filter")

View File

@@ -1,6 +1,7 @@
package accesslog_test
import (
"net"
"net/http"
"testing"
@@ -155,8 +156,11 @@ func TestHeaderFilter(t *testing.T) {
}
func TestCIDRFilter(t *testing.T) {
cidr := []*CIDR{
strutils.MustParse[*CIDR]("192.168.10.0/24"),
cidr := []*CIDR{{
net.IPNet{
IP: net.ParseIP("192.168.10.0"),
Mask: net.CIDRMask(24, 32),
}},
}
ExpectEqual(t, cidr[0].String(), "192.168.10.0/24")
inCIDR := &http.Request{