1// Copyright 2014 Manu Martinez-Almeida.  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
5package render
6
7import (
8	"net/http"
9
10	"gopkg.in/yaml.v2"
11)
12
13type YAML struct {
14	Data interface{}
15}
16
17var yamlContentType = []string{"application/x-yaml; charset=utf-8"}
18
19func (r YAML) Render(w http.ResponseWriter) error {
20	r.WriteContentType(w)
21
22	bytes, err := yaml.Marshal(r.Data)
23	if err != nil {
24		return err
25	}
26
27	w.Write(bytes)
28	return nil
29}
30
31func (r YAML) WriteContentType(w http.ResponseWriter) {
32	writeContentType(w, yamlContentType)
33}
34