Skip to content
Myr

toml.go

This file

Path

render/toml.go

36 lines · 820 bytes · Go

Last changed by

chore(render): do not export tomlContentType anymore (#4319)Varus Hsubefore adoption17d0b55

History of this file

Take it

1// Copyright 2022 Gin Core Team. 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/pelletier/go-toml/v2"11)1213// TOML contains the given interface object.14type TOML struct {15	Data any16}1718var tomlContentType = []string{"application/toml; charset=utf-8"}1920// Render (TOML) marshals the given interface object and writes data with custom ContentType.21func (r TOML) Render(w http.ResponseWriter) error {22	r.WriteContentType(w)2324	bytes, err := toml.Marshal(r.Data)25	if err != nil {26		return err27	}2829	_, err = w.Write(bytes)30	return err31}3233// WriteContentType (TOML) writes TOML ContentType for response.34func (r TOML) WriteContentType(w http.ResponseWriter) {35	writeContentType(w, tomlContentType)36}