response

package
v0.0.0-...-08ad29a Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ContentTypeApplicationJson = &header{
		Key:   "Content-Type",
		Value: []string{"application/json"},
	}

	ContentTypeText = &header{
		Key:   "Content-Type",
		Value: []string{"text/plain; charset=utf-8"},
	}
)

Functions

func Encoder

func Encoder(w http.ResponseWriter, res Response)

Encoder encode the response

func ErrEncoder

func ErrEncoder(w http.ResponseWriter, e Error)

Encoder encode the error response which sends to the client

func NewHeader

func NewHeader(key string, values ...string) *header

NewHeader returns a pointer to header with given key and values which can be passed to http response

func WithHeader

func WithHeader(h ...*header) (out []*header)

Types

type Error

type Error struct {
	// Error code to be send to the client
	// 		ex:- http.StatusOk
	Code int `json:"-"`

	// Mgs is the descriptive error message sent to the client
	Mgs string `json:"message"`

	// AppErrorCode is the application specific error code which is
	// documented against all the possible errors
	AppErrorCode int `json:"app_error_code"`

	// Actual error occured
	Error error `json:"-"`
}

Error is the error message response object which will be sent to the client on event of any error

type Response

type Response struct {
	Body   interface{}
	Code   int
	Header []*header
}

Jump to

Keyboard shortcuts

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