diff --git a/mimetype/yaml/yaml.go b/mimetype/yaml/yaml.go new file mode 100644 index 00000000..730f15c7 --- /dev/null +++ b/mimetype/yaml/yaml.go @@ -0,0 +1,23 @@ +// SPDX-FileCopyrightText: 2024 caixw +// +// SPDX-License-Identifier: MIT + +// Package yaml 支持 YAML 编码的序列化操作 +package yaml + +import ( + "io" + + "gopkg.in/yaml.v3" + + "github.com/issue9/web" +) + +const ( + Mimetype = "application/yaml" + ProblemMimetype = "application/problem+yaml" +) + +func Marshal(_ *web.Context, v any) ([]byte, error) { return yaml.Marshal(v) } + +func Unmarshal(r io.Reader, v any) error { return yaml.NewDecoder(r).Decode(v) } diff --git a/mimetype/yaml/yaml_test.go b/mimetype/yaml/yaml_test.go new file mode 100644 index 00000000..514519c2 --- /dev/null +++ b/mimetype/yaml/yaml_test.go @@ -0,0 +1,12 @@ +// SPDX-FileCopyrightText: 2024 caixw +// +// SPDX-License-Identifier: MIT + +package yaml + +import "github.com/issue9/web" + +var ( + _ web.MarshalFunc = Marshal + _ web.UnmarshalFunc = Unmarshal +)