Home / File/ plain.go — gin Source File

plain.go — gin Source File

Architecture documentation for plain.go, a go file in the gin codebase. 1 imports, 0 dependents.

File go RequestBinding FormBinding 1 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  21e76dcb_3149_c38e_f1a2_e4347c4939cd["plain.go"]
  e8c9ceab_299a_1e0e_919f_ddb404deb199["fmt"]
  21e76dcb_3149_c38e_f1a2_e4347c4939cd --> e8c9ceab_299a_1e0e_919f_ddb404deb199
  style 21e76dcb_3149_c38e_f1a2_e4347c4939cd fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

package binding

import (
	"fmt"
	"io"
	"net/http"
	"reflect"

	"github.com/gin-gonic/gin/internal/bytesconv"
)

type plainBinding struct{}

func (plainBinding) Name() string {
	return "plain"
}

func (plainBinding) Bind(req *http.Request, obj any) error {
	all, err := io.ReadAll(req.Body)
	if err != nil {
		return err
	}

	return decodePlain(all, obj)
}

func (plainBinding) BindBody(body []byte, obj any) error {
	return decodePlain(body, obj)
}

func decodePlain(data []byte, obj any) error {
	if obj == nil {
		return nil
	}

	v := reflect.ValueOf(obj)

	for v.Kind() == reflect.Ptr {
		if v.IsNil() {
			return nil
		}
		v = v.Elem()
	}

	if v.Kind() == reflect.String {
		v.SetString(bytesconv.BytesToString(data))
		return nil
	}

	if _, ok := v.Interface().([]byte); ok {
		v.SetBytes(data)
		return nil
	}

	return fmt.Errorf("type (%T) unknown type", v)
}

Subdomains

Functions

Types

Dependencies

  • fmt

Frequently Asked Questions

What does plain.go do?
plain.go is a source file in the gin codebase, written in go. It belongs to the RequestBinding domain, FormBinding subdomain.
What functions are defined in plain.go?
plain.go defines 1 function(s): decodePlain.
What does plain.go depend on?
plain.go imports 1 module(s): fmt.
Where is plain.go in the architecture?
plain.go is located at binding/plain.go (domain: RequestBinding, subdomain: FormBinding, directory: binding).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free