初版功能完成
ci / Go checks (ubuntu-latest) (push) Has been cancelled
ci / Go checks (windows-latest) (push) Has been cancelled

This commit is contained in:
qsc
2026-08-29 13:12:17 +08:00
commit 142e5dc7d6
217 changed files with 21313 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
// Package config loads only non-sensitive RemLink YAML configuration.
package config
import (
"errors"
"fmt"
"io"
"os"
"gopkg.in/yaml.v3"
)
func decodeStrict(path string, target any) error {
file, err := os.Open(path)
if err != nil {
return fmt.Errorf("open config %q: %w", path, err)
}
defer file.Close()
decoder := yaml.NewDecoder(file)
decoder.KnownFields(true)
if err := decoder.Decode(target); err != nil {
if errors.Is(err, io.EOF) {
return fmt.Errorf("config %q is empty", path)
}
return fmt.Errorf("decode config %q: %w", path, err)
}
var extra any
if err := decoder.Decode(&extra); !errors.Is(err, io.EOF) {
if err != nil {
return fmt.Errorf("decode trailing YAML document in %q: %w", path, err)
}
return fmt.Errorf("config %q must contain exactly one YAML document", path)
}
return nil
}