refactor: simplify io code and make utils module independent

This commit is contained in:
yusing
2025-05-23 22:19:14 +08:00
parent ff08c40403
commit f1e204f7fd
24 changed files with 124 additions and 73 deletions

View File

@@ -2,7 +2,7 @@ package notif
import (
"github.com/yusing/go-proxy/internal/gperr"
"github.com/yusing/go-proxy/internal/utils"
"github.com/yusing/go-proxy/internal/serialization"
)
type NotificationConfig struct {
@@ -46,5 +46,5 @@ func (cfg *NotificationConfig) UnmarshalMap(m map[string]any) (err gperr.Error)
Withf("expect %s or %s", ProviderWebhook, ProviderGotify)
}
return utils.MapUnmarshalValidate(m, cfg.Provider)
return serialization.MapUnmarshalValidate(m, cfg.Provider)
}

View File

@@ -4,7 +4,7 @@ import (
"net/http"
"testing"
"github.com/yusing/go-proxy/internal/utils"
"github.com/yusing/go-proxy/internal/serialization"
. "github.com/yusing/go-proxy/internal/utils/testing"
)
@@ -181,7 +181,7 @@ func TestNotificationConfig(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
var cfg NotificationConfig
provider := tt.cfg["provider"]
err := utils.MapUnmarshalValidate(tt.cfg, &cfg)
err := serialization.MapUnmarshalValidate(tt.cfg, &cfg)
if tt.wantErr {
ExpectHasError(t, err)
} else {

View File

@@ -10,12 +10,12 @@ import (
"github.com/yusing/go-proxy/internal/gperr"
"github.com/yusing/go-proxy/internal/logging"
"github.com/yusing/go-proxy/internal/utils"
"github.com/yusing/go-proxy/internal/serialization"
)
type (
Provider interface {
utils.CustomValidator
serialization.CustomValidator
GetName() string
GetURL() string