refactor: use yaml.v3 everywhere and remove dependency on yaml.v2

This commit is contained in:
5684185+vsariola@users.noreply.github.com
2025-10-19 17:13:00 +03:00
parent f4bb2bc754
commit 8e99c93d14
7 changed files with 20 additions and 11 deletions

View File

@ -1,6 +1,7 @@
package gioui
import (
"bytes"
_ "embed"
"fmt"
"strconv"
@ -10,7 +11,7 @@ import (
"gioui.org/io/event"
"gioui.org/io/key"
"github.com/vsariola/sointu/tracker"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
)
type (
@ -31,7 +32,9 @@ var defaultKeyBindings []byte
func init() {
var keyBindings, userKeybindings []KeyBinding
if err := yaml.UnmarshalStrict(defaultKeyBindings, &keyBindings); err != nil {
dec := yaml.NewDecoder(bytes.NewReader(defaultKeyBindings))
dec.KnownFields(true)
if err := dec.Decode(&keyBindings); err != nil {
panic(fmt.Errorf("failed to unmarshal default keybindings: %w", err))
}
if err := ReadCustomConfig("keybindings.yml", &userKeybindings); err == nil {

View File

@ -1,12 +1,13 @@
package gioui
import (
"bytes"
_ "embed"
"fmt"
"os"
"path/filepath"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
"gioui.org/unit"
)
@ -53,7 +54,9 @@ func ReadCustomConfig(filename string, target any) error {
// return at least the default config, and the warning will just tell if there
// was a problem parsing the custom config.
func ReadConfig(defaultConfig []byte, path string, target any) (warn error) {
if err := yaml.UnmarshalStrict(defaultConfig, target); err != nil {
dec := yaml.NewDecoder(bytes.NewReader(defaultConfig))
dec.KnownFields(true)
if err := dec.Decode(target); err != nil {
panic(fmt.Errorf("ReadConfig %v failed to unmarshal the embedded default config: %w", path, err))
}
return ReadCustomConfig(path, target)