Skip to content
Myr

toml.go

This file

Path

binding/toml.go

35 lines · 698 bytes · Go

Last changed by

Not known.

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 binding67import (8	"bytes"9	"io"10	"net/http"1112	"github.com/pelletier/go-toml/v2"13)1415type tomlBinding struct{}1617func (tomlBinding) Name() string {18	return "toml"19}2021func (tomlBinding) Bind(req *http.Request, obj any) error {22	return decodeToml(req.Body, obj)23}2425func (tomlBinding) BindBody(body []byte, obj any) error {26	return decodeToml(bytes.NewReader(body), obj)27}2829func decodeToml(r io.Reader, obj any) error {30	decoder := toml.NewDecoder(r)31	if err := decoder.Decode(obj); err != nil {32		return err33	}34	return validate(obj)35}