http

package
v0.1.28 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Failure

func Failure(render JSONResponseRender, cause error)

func SetDefaultConvertErrorFunc

func SetDefaultConvertErrorFunc(f ConvertErrorFunc)

func Success

func Success(render JSONResponseRender, message string, data ...interface{})

Types

type ConvertErrorFunc

type ConvertErrorFunc func(err error) errorsext.Error

type FailureResponse

type FailureResponse struct {
	// 错误码,跟 http-status 一致,并且在 grpc 中可以转换成 grpc-status
	Code int `json:"code"`
	// 错误原因,定义为业务判定错误码
	Reason string `json:"reason"`
	// 错误信息,为用户可读的信息,可作为用户提示内容
	Message   string                 `json:"message"`
	Details   map[string]interface{} `json:"details,omitempty"`
	Timestamp time.Time              `json:"timestamp"`
}

type JSONResponseRender

type JSONResponseRender interface {
	JSON(code int, data interface{})
}

type SuccessResponse

type SuccessResponse struct {
	Code      int         `json:"code"`
	Message   string      `json:"message"`
	Data      interface{} `json:"data,omitempty"`
	Timestamp time.Time   `json:"timestamp"`
}

Jump to

Keyboard shortcuts

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