Skip to content
Myr

yaml.go

This file

Path

render/yaml.go

36 lines · 821 bytes · Go

Last changed by

chroe: migrate yaml package to github.com/goccy/go-yaml (#4272)M. Ilham Surya Pratamabefore adoptioncf47752

History of this file

Take it

1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.2// Use of this source code is governed by a MIT style3// license that can be found in the LICENSE file.45package render67import (8	"net/http"910	"github.com/goccy/go-yaml"11)1213// YAML contains the given interface object.14type YAML struct {15	Data any16}1718var yamlContentType = []string{"application/yaml; charset=utf-8"}1920// Render (YAML) marshals the given interface object and writes data with custom ContentType.21func (r YAML) Render(w http.ResponseWriter) error {22	r.WriteContentType(w)2324	bytes, err := yaml.Marshal(r.Data)25	if err != nil {26		return err27	}2829	_, err = w.Write(bytes)30	return err31}3233// WriteContentType (YAML) writes YAML ContentType for response.34func (r YAML) WriteContentType(w http.ResponseWriter) {35	writeContentType(w, yamlContentType)36}