diff --git a/go.mod b/go.mod index 8117cba4c..1813a94cb 100644 --- a/go.mod +++ b/go.mod @@ -104,7 +104,7 @@ require ( gitlab.com/bboehmke/sunny v0.17.0 go.bug.st/serial v1.7.1 go.uber.org/mock v0.6.0 - go.yaml.in/yaml/v4 v4.0.0-rc.5 + go.yaml.in/yaml/v4 v4.0.0-rc.5.0.20260613141257-7afcb0919cb5 golang.org/x/crypto v0.53.0 golang.org/x/crypto/x509roots/fallback v0.0.0-20260609182332-5f2de1a9f1e2 golang.org/x/exp v0.0.0-20260611194520-c48552f49976 diff --git a/go.sum b/go.sum index 95c5003d4..89f12ba06 100644 --- a/go.sum +++ b/go.sum @@ -574,8 +574,8 @@ go.yaml.in/yaml/v2 v2.4.4 h1:tuyd0P+2Ont/d6e2rl3be67goVK4R6deVxCUX5vyPaQ= go.yaml.in/yaml/v2 v2.4.4/go.mod h1:gMZqIpDtDqOfM0uNfy0SkpRhvUryYH0Z6wdMYcacYXQ= go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= -go.yaml.in/yaml/v4 v4.0.0-rc.5 h1:JVliQq9EGOYaTgMi+k8BhUJyqcGk4ZqeuiN1Cirba9c= -go.yaml.in/yaml/v4 v4.0.0-rc.5/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0= +go.yaml.in/yaml/v4 v4.0.0-rc.5.0.20260613141257-7afcb0919cb5 h1:FN2nHSMZESIAuZHWbZPsqsduWNnLLMaJ3cVNojwa5pg= +go.yaml.in/yaml/v4 v4.0.0-rc.5.0.20260613141257-7afcb0919cb5/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= diff --git a/server/db/settings/setting.go b/server/db/settings/setting.go index b9f07c61d..e4979e642 100644 --- a/server/db/settings/setting.go +++ b/server/db/settings/setting.go @@ -15,9 +15,8 @@ import ( "github.com/evcc-io/evcc/server/db" "github.com/evcc-io/evcc/util" - "github.com/evcc-io/evcc/util/yaml" "github.com/samber/lo" - goyaml "go.yaml.in/yaml/v4" + "go.yaml.in/yaml/v4" "gorm.io/gorm" ) @@ -136,7 +135,7 @@ func SetJson(key string, val any) error { func SetYaml(key string, val any) error { var b bytes.Buffer - err := goyaml.NewEncoder(&b).Encode(val) + err := yaml.NewEncoder(&b).Encode(val) if err == nil { SetString(key, strings.TrimSpace(b.String())) } diff --git a/server/http_config_device_handler.go b/server/http_config_device_handler.go index 6eb4128a1..cc322220d 100644 --- a/server/http_config_device_handler.go +++ b/server/http_config_device_handler.go @@ -22,9 +22,9 @@ import ( "github.com/evcc-io/evcc/tariff" "github.com/evcc-io/evcc/util/config" "github.com/evcc-io/evcc/util/templates" - "github.com/evcc-io/evcc/util/yaml" "github.com/evcc-io/evcc/vehicle" "github.com/gorilla/mux" + "go.yaml.in/yaml/v4" ) func devicesConfig[T any](class templates.Class, h config.Handler[T], hidePrivate bool) ([]map[string]any, error) { diff --git a/server/http_config_helper.go b/server/http_config_helper.go index b498dce23..df62e1791 100644 --- a/server/http_config_helper.go +++ b/server/http_config_helper.go @@ -16,9 +16,9 @@ import ( "github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util/config" "github.com/evcc-io/evcc/util/templates" - "github.com/evcc-io/evcc/util/yaml" "github.com/go-viper/mapstructure/v2" "github.com/samber/lo" + "go.yaml.in/yaml/v4" ) const ( diff --git a/server/http_global_settings_handler.go b/server/http_global_settings_handler.go index 5b3a1dc5a..a268e0821 100644 --- a/server/http_global_settings_handler.go +++ b/server/http_global_settings_handler.go @@ -12,8 +12,8 @@ import ( "github.com/evcc-io/evcc/core/keys" "github.com/evcc-io/evcc/server/db/settings" "github.com/evcc-io/evcc/util/redact" - "github.com/evcc-io/evcc/util/yaml" "github.com/gorilla/mux" + "go.yaml.in/yaml/v4" ) func settingsGetStringHandler(key string) http.HandlerFunc { diff --git a/util/config/custom.go b/util/config/custom.go index 9a1bc34f5..6beed02a5 100644 --- a/util/config/custom.go +++ b/util/config/custom.go @@ -1,8 +1,8 @@ package config import ( - "github.com/evcc-io/evcc/util/yaml" "github.com/spf13/cast" + "go.yaml.in/yaml/v4" ) // CustomDevice promotes an embedded yaml type to the top-level type diff --git a/util/error_test.go b/util/error_test.go index f8c0b9ac4..10528e1ae 100644 --- a/util/error_test.go +++ b/util/error_test.go @@ -15,8 +15,8 @@ func TestYamlFloat(t *testing.T) { func TestYamlEmpty(t *testing.T) { var res map[string]any - err := yaml.Unmarshal([]byte(""), &res) - require.ErrorContains(t, err, "no documents in stream") + require.NoError(t, yaml.Unmarshal([]byte(""), &res)) + require.Nil(t, res) } func TestYamlCommentsOnly(t *testing.T) { @@ -24,8 +24,8 @@ func TestYamlCommentsOnly(t *testing.T) { # another comment ` var res map[string]any - err := yaml.Unmarshal([]byte(b), &res) - require.ErrorContains(t, err, "no documents in stream") + require.NoError(t, yaml.Unmarshal([]byte(b), &res)) + require.Nil(t, res) } func TestYamlError(t *testing.T) { diff --git a/util/templates/funcmap.go b/util/templates/funcmap.go index 719a141ab..d345e7ff2 100644 --- a/util/templates/funcmap.go +++ b/util/templates/funcmap.go @@ -10,7 +10,7 @@ import ( "time" "github.com/Masterminds/sprig/v3" - "github.com/evcc-io/evcc/util/yaml" + "go.yaml.in/yaml/v4" ) func yamlQuote(value string) string { diff --git a/util/templates/render_instance.go b/util/templates/render_instance.go index 89ffaf19a..ebde89e58 100644 --- a/util/templates/render_instance.go +++ b/util/templates/render_instance.go @@ -6,7 +6,7 @@ import ( "os" "github.com/evcc-io/evcc/util" - "github.com/evcc-io/evcc/util/yaml" + "go.yaml.in/yaml/v4" ) // Instance is an actual instantiated template diff --git a/util/yaml/yaml.go b/util/yaml/yaml.go deleted file mode 100644 index d4c7b8284..000000000 --- a/util/yaml/yaml.go +++ /dev/null @@ -1,20 +0,0 @@ -package yaml - -import ( - "strings" - - goyaml "go.yaml.in/yaml/v4" -) - -func Marshal(data any) ([]byte, error) { - return goyaml.Marshal(data) -} - -// Unmarshal invokes unmarshaler, ignoring empty document errors -func Unmarshal(b []byte, res any) error { - err := goyaml.Unmarshal(b, res) - if err != nil && strings.Contains(err.Error(), "no documents in stream") { - err = nil - } - return err -}