Skip to content

Commit

Permalink
feat(mimetype/yaml): 支持 YAML 编码
Browse files Browse the repository at this point in the history
  • Loading branch information
caixw committed Nov 12, 2024
1 parent 5f7e8f2 commit 74b130b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
23 changes: 23 additions & 0 deletions mimetype/yaml/yaml.go
Original file line number Diff line number Diff line change
@@ -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) }
12 changes: 12 additions & 0 deletions mimetype/yaml/yaml_test.go
Original file line number Diff line number Diff line change
@@ -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
)

0 comments on commit 74b130b

Please sign in to comment.