代码拉取完成,页面将自动刷新
package yaml
import (
"github.com/emicklei/go-restful/v3"
"gopkg.in/yaml.v3"
)
const (
MIME_YAML = "application/yaml"
)
// NewEntityAccessorJSON returns a new EntityReaderWriter for accessing YAML content.
// This package is already initialized with such an accessor using the MIME_YAML contentType.
func NewEntityAccessorJSON(contentType string) restful.EntityReaderWriter {
return entityYAMLAccess{ContentType: contentType}
}
type entityYAMLAccess struct {
// This is used for setting the Content-Type header when writing
ContentType string
}
// Read unmarshalls the value from YAML
func (e entityYAMLAccess) Read(req *restful.Request, v interface{}) error {
decoder := yaml.NewDecoder(req.Request.Body)
return decoder.Decode(v)
}
// Write marshalls the value to YAML and set the Content-Type Header.
func (e entityYAMLAccess) Write(resp *restful.Response, status int, v interface{}) error {
return writeYAML(resp, status, e.ContentType, v)
}
// write marshalls the value to YAML and set the Content-Type Header.
func writeYAML(resp *restful.Response, status int, contentType string, v interface{}) error {
if v == nil {
resp.WriteHeader(status)
// do not write a nil representation
return nil
}
resp.Header().Set(restful.HEADER_ContentType, contentType)
resp.WriteHeader(status)
return yaml.NewEncoder(resp).Encode(v)
}
func init() {
restful.RegisterEntityAccessor(MIME_YAML, NewEntityAccessorJSON(MIME_YAML))
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。