json_decoder

package module
v0.0.0-...-a6c780b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2025 License: MIT Imports: 6 Imported by: 0

README

JSON Decoder

Table of Content

Authors

Name GitHub
Klim Sidorov @entrlcom-klim

Examples

package main

import (
	"net/http"
	"time"

	"flida.dev/unit"

	"flida.dev/json-decoder"
)

const limit = unit.B * 128 // 128 B.

type HTTPRequestBody struct {
	DateOfBirth time.Time `json:"date_of_birth"`
	Name        string    `json:"name"`
}

func ServeHTTP(w http.ResponseWriter, r *http.Request) {
	var body HTTPRequestBody

	if err := json_decoder.NewHTTPRequestDecoder(limit).Decode(w, r, &body); err != nil {
		// TODO: ...
		return
    }

	// ...
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidJSON           = errors.New("invalid json")
	ErrRequestEntityTooLarge = errors.New("request entity too large")
)
View Source
var ErrUnsupportedMediaType = errors.New("unsupported media type")

Functions

func Decode

func Decode(r io.Reader, v any) error

Types

type HTTPRequestDecoder

type HTTPRequestDecoder struct {
	// contains filtered or unexported fields
}

func NewHTTPRequestDecoder

func NewHTTPRequestDecoder(limit int64) HTTPRequestDecoder

func (HTTPRequestDecoder) Decode

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL