ioutil

package
v0.0.0-...-e3cadf0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2024 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package ioutil provides functions for IO operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromJSON

func FromJSON(i interface{}, r io.Reader) error

FromJSON deserializes the object from JSON string in an io.Reader to the given interface.

func ToJSON

func ToJSON(i interface{}, w io.Writer) error

ToJSON serializes the given interface into a string-based JSON format.

Types

type ErrorWriter

type ErrorWriter interface {
	// Error writes msg to http.ResponseWriter and the status code.
	Error(w http.ResponseWriter, msg string, status int)
}

ErrorWriter is an interface for writing a generic errors like http.Error func.

type GenericError

type GenericError struct {
	// The error message.
	//
	// example: Very useful error message
	Message string `json:"message"`
}

GenericError is a generic error message returned by a server.

type JSONErrorWriter

type JSONErrorWriter struct {
	Logger *log.Logger
}

JSONErrorWriter interpreters an error in json format and write to http.ResponseWriter.

func (JSONErrorWriter) Error

func (ew JSONErrorWriter) Error(w http.ResponseWriter, message string, status int)

Error is a helper function to write a generic error to the response writer with the given status code and message.

Jump to

Keyboard shortcuts

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