diff --git a/internal/config/config.go b/internal/config/config.go index 621cfa0..6ae6b55 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -22,8 +22,8 @@ import ( "github.com/yusing/go-proxy/internal/notif" "github.com/yusing/go-proxy/internal/proxmox" proxy "github.com/yusing/go-proxy/internal/route/provider" + "github.com/yusing/go-proxy/internal/serialization" "github.com/yusing/go-proxy/internal/task" - "github.com/yusing/go-proxy/internal/utils" F "github.com/yusing/go-proxy/internal/utils/functional" "github.com/yusing/go-proxy/internal/utils/strutils/ansi" "github.com/yusing/go-proxy/internal/watcher" @@ -223,7 +223,7 @@ func (cfg *Config) load() gperr.Error { } model := config.DefaultConfig() - if err := utils.UnmarshalValidateYAML(data, model); err != nil { + if err := serialization.UnmarshalValidateYAML(data, model); err != nil { gperr.LogFatal(errMsg, err) } diff --git a/internal/homepage/homepage.go b/internal/homepage/homepage.go index 2d9bcc3..13d78bb 100644 --- a/internal/homepage/homepage.go +++ b/internal/homepage/homepage.go @@ -5,7 +5,7 @@ import ( "slices" "github.com/yusing/go-proxy/internal/homepage/widgets" - "github.com/yusing/go-proxy/internal/utils" + "github.com/yusing/go-proxy/internal/serialization" ) type ( @@ -32,7 +32,7 @@ type ( ) func init() { - utils.RegisterDefaultValueFactory(func() *ItemConfig { + serialization.RegisterDefaultValueFactory(func() *ItemConfig { return &ItemConfig{ Show: true, } diff --git a/internal/homepage/list_icons.go b/internal/homepage/list_icons.go index 734282d..cb96ba8 100644 --- a/internal/homepage/list_icons.go +++ b/internal/homepage/list_icons.go @@ -12,8 +12,8 @@ import ( "github.com/lithammer/fuzzysearch/fuzzy" "github.com/yusing/go-proxy/internal/common" "github.com/yusing/go-proxy/internal/logging" + "github.com/yusing/go-proxy/internal/serialization" "github.com/yusing/go-proxy/internal/task" - "github.com/yusing/go-proxy/internal/utils" "github.com/yusing/go-proxy/internal/utils/strutils" ) @@ -99,7 +99,7 @@ func InitIconListCache() { iconsCache.Lock() defer iconsCache.Unlock() - err := utils.LoadJSONIfExist(common.IconListCachePath, iconsCache) + err := serialization.LoadJSONIfExist(common.IconListCachePath, iconsCache) if err != nil { logging.Error().Err(err).Msg("failed to load icons") } else if len(iconsCache.Icons) > 0 { @@ -113,7 +113,7 @@ func InitIconListCache() { } task.OnProgramExit("save_icons_cache", func() { - utils.SaveJSON(common.IconListCachePath, iconsCache, 0o644) + serialization.SaveJSON(common.IconListCachePath, iconsCache, 0o644) }) } @@ -142,7 +142,7 @@ func ListAvailableIcons() (*Cache, error) { iconsCache.LastUpdate = time.Now() - err := utils.SaveJSON(common.IconListCachePath, iconsCache, 0o644) + err := serialization.SaveJSON(common.IconListCachePath, iconsCache, 0o644) if err != nil { logging.Warn().Err(err).Msg("failed to save icons") } diff --git a/internal/homepage/widgets/widgets.go b/internal/homepage/widgets/widgets.go index e653b69..8aea2af 100644 --- a/internal/homepage/widgets/widgets.go +++ b/internal/homepage/widgets/widgets.go @@ -4,7 +4,7 @@ import ( "context" "github.com/yusing/go-proxy/internal/gperr" - "github.com/yusing/go-proxy/internal/utils" + "github.com/yusing/go-proxy/internal/serialization" ) type ( @@ -42,7 +42,7 @@ func (cfg *Config) UnmarshalMap(m map[string]any) error { if !ok { return gperr.New("invalid config") } - if err := utils.MapUnmarshalValidate(m, &cfg.Config); err != nil { + if err := serialization.MapUnmarshalValidate(m, &cfg.Config); err != nil { return err } return nil diff --git a/internal/jsonstore/jsonstore.go b/internal/jsonstore/jsonstore.go index 54ff2ed..cf7c036 100644 --- a/internal/jsonstore/jsonstore.go +++ b/internal/jsonstore/jsonstore.go @@ -12,8 +12,8 @@ import ( "github.com/yusing/go-proxy/internal/common" "github.com/yusing/go-proxy/internal/gperr" "github.com/yusing/go-proxy/internal/logging" + "github.com/yusing/go-proxy/internal/serialization" "github.com/yusing/go-proxy/internal/task" - "github.com/yusing/go-proxy/internal/utils" ) type namespace string @@ -77,7 +77,7 @@ func loadNS[T store](ns namespace) T { func save() error { errs := gperr.NewBuilder("failed to save data stores") for ns, store := range stores { - if err := utils.SaveJSON(filepath.Join(storesPath, string(ns)+".json"), &store, 0o644); err != nil { + if err := serialization.SaveJSON(filepath.Join(storesPath, string(ns)+".json"), &store, 0o644); err != nil { errs.Add(err) } } diff --git a/internal/net/gphttp/middleware/cidr_whitelist.go b/internal/net/gphttp/middleware/cidr_whitelist.go index 6b9271f..5b6559b 100644 --- a/internal/net/gphttp/middleware/cidr_whitelist.go +++ b/internal/net/gphttp/middleware/cidr_whitelist.go @@ -7,7 +7,7 @@ import ( "github.com/go-playground/validator/v10" gphttp "github.com/yusing/go-proxy/internal/net/gphttp" "github.com/yusing/go-proxy/internal/net/types" - "github.com/yusing/go-proxy/internal/utils" + "github.com/yusing/go-proxy/internal/serialization" F "github.com/yusing/go-proxy/internal/utils/functional" ) @@ -34,7 +34,7 @@ var ( ) func init() { - utils.MustRegisterValidation("status_code", func(fl validator.FieldLevel) bool { + serialization.MustRegisterValidation("status_code", func(fl validator.FieldLevel) bool { statusCode := fl.Field().Int() return gphttp.IsStatusCodeValid(int(statusCode)) }) diff --git a/internal/net/gphttp/middleware/middleware.go b/internal/net/gphttp/middleware/middleware.go index 213aa10..bab1cb8 100644 --- a/internal/net/gphttp/middleware/middleware.go +++ b/internal/net/gphttp/middleware/middleware.go @@ -12,7 +12,7 @@ import ( "github.com/yusing/go-proxy/internal/logging" gphttp "github.com/yusing/go-proxy/internal/net/gphttp" "github.com/yusing/go-proxy/internal/net/gphttp/reverseproxy" - "github.com/yusing/go-proxy/internal/utils" + "github.com/yusing/go-proxy/internal/serialization" ) type ( @@ -118,14 +118,14 @@ func (m *Middleware) apply(optsRaw OptionsRaw) gperr.Error { "priority": optsRaw["priority"], "bypass": optsRaw["bypass"], } - if err := utils.MapUnmarshalValidate(commonOpts, &m.commonOptions); err != nil { + if err := serialization.MapUnmarshalValidate(commonOpts, &m.commonOptions); err != nil { return err } optsRaw = maps.Clone(optsRaw) for k := range commonOpts { delete(optsRaw, k) } - return utils.MapUnmarshalValidate(optsRaw, m.impl) + return serialization.MapUnmarshalValidate(optsRaw, m.impl) } func (m *Middleware) finalize() error { diff --git a/internal/route/provider/docker.go b/internal/route/provider/docker.go index 36c1811..111018d 100755 --- a/internal/route/provider/docker.go +++ b/internal/route/provider/docker.go @@ -12,7 +12,7 @@ import ( "github.com/yusing/go-proxy/internal/gperr" "github.com/yusing/go-proxy/internal/logging" "github.com/yusing/go-proxy/internal/route" - U "github.com/yusing/go-proxy/internal/utils" + "github.com/yusing/go-proxy/internal/serialization" "github.com/yusing/go-proxy/internal/utils/strutils" "github.com/yusing/go-proxy/internal/watcher" ) @@ -180,7 +180,7 @@ func (p *DockerProvider) routesFromContainerLabels(container *docker.Container) } // deserialize map into entry object - err := U.MapUnmarshalValidate(entryMap, r) + err := serialization.MapUnmarshalValidate(entryMap, r) if err != nil { errs.Add(err.Subject(alias)) } else { @@ -189,7 +189,7 @@ func (p *DockerProvider) routesFromContainerLabels(container *docker.Container) } if wildcardProps != nil { for _, re := range routes { - if err := U.MapUnmarshalValidate(wildcardProps, re); err != nil { + if err := serialization.MapUnmarshalValidate(wildcardProps, re); err != nil { errs.Add(err.Subject(docker.WildcardAlias)) break } diff --git a/internal/route/provider/file.go b/internal/route/provider/file.go index 6c23a60..6d964cc 100644 --- a/internal/route/provider/file.go +++ b/internal/route/provider/file.go @@ -10,7 +10,7 @@ import ( "github.com/yusing/go-proxy/internal/gperr" "github.com/yusing/go-proxy/internal/logging" "github.com/yusing/go-proxy/internal/route" - "github.com/yusing/go-proxy/internal/utils" + "github.com/yusing/go-proxy/internal/serialization" W "github.com/yusing/go-proxy/internal/watcher" ) @@ -34,7 +34,7 @@ func FileProviderImpl(filename string) (ProviderImpl, error) { } func validate(data []byte) (routes route.Routes, err gperr.Error) { - err = utils.UnmarshalValidateYAML(data, &routes) + err = serialization.UnmarshalValidateYAML(data, &routes) return }