gorest

package module
v0.8.9 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2022 License: BSD-2-Clause Imports: 5 Imported by: 5

README

gorest

Rest lib based on porterr

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseJsonBody

func ParseJsonBody(r io.ReadCloser, data interface{}) porterr.IError

ParseJsonBody Read json data from request body

func ResponseErrorStrategy added in v0.7.4

func ResponseErrorStrategy(response *http.Response) error

ResponseErrorStrategy Default response strategy

func Send

func Send(writer http.ResponseWriter, response *JsonResponse)

Send response to client

func SendJson

func SendJson(writer http.ResponseWriter, httpCode int, data interface{})

SendJson Sent json into http writer

func SendRawJson added in v0.8.4

func SendRawJson(writer http.ResponseWriter, httpCode int, data json.RawMessage)

SendRawJson send raw JSON

Types

type HttpCodeMap

type HttpCodeMap map[string]int

HttpCodeMap Type for http code mapping

type JsonResponse

type JsonResponse struct {
	// HTTP code
	HttpCode int `json:"-"`
	// Message information
	Message interface{} `json:"message,omitempty"`
	// Body
	Data interface{} `json:"data,omitempty"`
	// Meta information
	Meta interface{} `json:"meta,omitempty"`
	// Error information
	Error interface{} `json:"error,omitempty"`
}

JsonResponse Json response struct

func NewErrorJsonResponse

func NewErrorJsonResponse(e porterr.IError) *JsonResponse

NewErrorJsonResponse New Json Response with error

func NewOkJsonResponse

func NewOkJsonResponse(message interface{}, data interface{}, meta interface{}) *JsonResponse

NewOkJsonResponse New Json Response without error

type Meta

type Meta struct {
	// Current page
	Page int `json:"page,omitempty"`
	// Limit
	Limit int `json:"limit,omitempty"`
	// Total count
	Total int `json:"total,omitempty"`
}

Meta information for pagination

Jump to

Keyboard shortcuts

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