httpencoder

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContentTypeHeader = "Content-Type"
	ContentType       = "application/json; charset=utf-8"
)

Predefined http encoder content type

Variables

This section is empty.

Functions

func CodeAndMessageFrom

func CodeAndMessageFrom(err error) (int, interface{})

CodeAndMessageFrom helper

func EncodeError

func EncodeError(l logger, codeAndMessageFrom func(err error) (int, interface{})) httptransport.ErrorEncoder

EncodeError ...

func EncodeResponse

func EncodeResponse(_ context.Context, w http.ResponseWriter, response interface{}) error

EncodeResponse is the common method to encode all response types to the client. I chose to do it this way because, since we're using JSON, there's no reason to provide anything more specific. It's certainly possible to specialize on a per-response (per-method) basis.

func EncodeResponseAsIs

func EncodeResponseAsIs(_ context.Context, w http.ResponseWriter, response interface{}) error

EncodeResponse is the common method to encode all response types to the client. I chose to do it this way because, since we're using JSON, there's no reason to provide anything more specific. It's certainly possible to specialize on a per-response (per-method) basis.

Types

type BoolResultResponse

type BoolResultResponse struct {
	Result bool `json:"result"`
}

BoolResultResponse struct

func BoolResult

func BoolResult(result bool) BoolResultResponse

BoolResult response helper

type ErrorResponse

type ErrorResponse struct {
	Code      int         `json:"code"`
	Error     string      `json:"error"`
	Message   string      `json:"message,omitempty"`
	Details   interface{} `json:"details,omitempty"`
	RequestID string      `json:"request_id,omitempty"`
}

Error represents an error response

type ListMeta

type ListMeta struct {
	TotalItems   int64 `json:"total_items,omitempty"`
	ItemsPerPage int32 `json:"items_per_page,omitempty"`
	Page         int32 `json:"page,omitempty"`
	Limit        int32 `json:"limit,omitempty"`
	Offset       int32 `json:"offset,omitempty"`
}

type ListResponse

type ListResponse struct {
	Data interface{} `json:"data,omitempty"`
	Meta ListMeta    `json:"meta,omitempty"`
}

ListResponse struct

type Response

type Response struct {
	Data interface{}            `json:"data,omitempty"`
	Meta map[string]interface{} `json:"meta,omitempty"`
}

Response struct

Jump to

Keyboard shortcuts

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