api

package
v0.0.0-...-2eb6bad Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterCustomCode

func RegisterCustomCode(code int, status, message string) error

RegisterCustomCode was used to register the custom code description, it would overwrite the previous one when conflicted.

func ResponseError

func ResponseError(ctx *gin.Context, statusCode int, err error)

ResponseError would write the error data output with status error

func ResponseWithAccepted

func ResponseWithAccepted(ctx *gin.Context, data interface{})

ResponseWithAccepted would write the success data output with status accepted

func ResponseWithCreated

func ResponseWithCreated(ctx *gin.Context, data interface{})

ResponseWithCreated would write the success data output with status created

func ResponseWithErrors

func ResponseWithErrors(ctx *gin.Context, statusCode, subCode int, errors []interface{})

ResponseWithErrors would write meta with error and empty data

func ResponseWithOK

func ResponseWithOK(ctx *gin.Context, data interface{})

ResponseWithOK would write the success data output with status ok

func ResponseWithSuccess

func ResponseWithSuccess(ctx *gin.Context, statusCode int, data interface{})

ResponseWithSuccess would write the success data output and status into http writer

Types

type Description

type Description struct {
	Status  string
	Message string
}

func CodeDescription

func CodeDescription(code int) Description

type Meta

type Meta struct {
	Code    int           `json:"code"`
	Type    string        `json:"type,omitempty"`
	Message string        `json:"message,omitempty"`
	Errors  []interface{} `json:"errors,omitempty"`
}

func (Meta) IsError

func (m Meta) IsError() bool

IsError return whether the response meta was error or not(http code >= 400)

func (Meta) StatusCode

func (m Meta) StatusCode() int

StatusCode return http status code in meta

func (Meta) SubCode

func (m Meta) SubCode() int

SubCode return sub code in meta

type Response

type Response struct {
	Meta Meta        `json:"meta"`
	Data interface{} `json:"data"`
	// contains filtered or unexported fields
}

func UnmarshalResponse

func UnmarshalResponse(bytes []byte) (*Response, error)

UnmarshalResponse create response

func (*Response) Code

func (r *Response) Code() int

Code return code in response's meta

func (*Response) Errors

func (r *Response) Errors() []interface{}

Errors return errors in response's meta

func (*Response) GetData

func (r *Response) GetData(v interface{}) error

GetData was used to unmarshal the data field into obj

func (*Response) IsError

func (r *Response) IsError() bool

IsError return whether the response was error or not(http code >= 400)

func (*Response) Message

func (r *Response) Message() string

Message return message in response's meta

func (*Response) StatusCode

func (r *Response) StatusCode() int

StatusCode return http status code in response's meta

func (*Response) SubCode

func (r *Response) SubCode() int

SubCode return sub code in response's meta

func (*Response) Type

func (r *Response) Type() string

Type return type in response's meta

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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