yaml.go 708 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2018 Gin Core Team. All rights reserved.
  2. // Use of this source code is governed by a MIT style
  3. // license that can be found in the LICENSE file.
  4. package binding
  5. /*
  6. import (
  7. "bytes"
  8. "io"
  9. "net/http"
  10. "gopkg.in/yaml.v2"
  11. )
  12. type yamlBinding struct{}
  13. func (yamlBinding) Name() string {
  14. return "yaml"
  15. }
  16. func (yamlBinding) Bind(req *http.Request, obj interface{}) error {
  17. return decodeYAML(req.Body, obj)
  18. }
  19. func (yamlBinding) BindBody(body []byte, obj interface{}) error {
  20. return decodeYAML(bytes.NewReader(body), obj)
  21. }
  22. func decodeYAML(r io.Reader, obj interface{}) error {
  23. decoder := yaml.NewDecoder(r)
  24. if err := decoder.Decode(obj); err != nil {
  25. return err
  26. }
  27. return nil
  28. }
  29. // */