http

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BusinessMsgOk represents the business message for success.
	BusinessMsgOk = "common.ok"

	// BusinessDefaultCodeError represents the business code for error.
	BusinessDefaultCodeError = "common.unknown"

	// BusinessContextCodeError represents the business code for ctx error.
	BusinessContextCodeError = "common.ctx_error"

	// BusinessCodeInvalidParam represents the business code for invalid param.
	BusinessCodeInvalidParam = "common.invalid_param"

	// BusinessCodeUnAuthorized represents the business code for unauthorized.
	BusinessCodeUnAuthorized = "common.unauthorized"
)

Variables

This section is empty.

Functions

func JsonBaseResponse

func JsonBaseResponse(w http.ResponseWriter, v any)

JsonBaseResponse writes v into w with http.StatusOK.

func JsonBaseResponseCtx

func JsonBaseResponseCtx(ctx context.Context, w http.ResponseWriter, v any)

JsonBaseResponseCtx writes v into w with http.StatusOK.

func JsonErrorResponse added in v0.0.9

func JsonErrorResponse(w http.ResponseWriter, code int, v any)

JsonErrorResponse writes err into w.

func JsonErrorResponseCtx added in v0.0.9

func JsonErrorResponseCtx(ctx context.Context, w http.ResponseWriter, code int, v any)

JsonErrorResponseCtx writes err into w.

Types

type BaseResponse

type BaseResponse[T any] struct {
	// Code represents the business code, not the http status code.
	Code string `json:"code"`
	// Msg represents the business message, if Code = BusinessCodeOK,
	// and Msg is empty, then the Msg will be set to BusinessMsgOk.
	Msg string `json:"msg"`
	// Data represents the business data.
	Data T `json:"data,omitempty"`
}

BaseResponse is the base response struct.

Jump to

Keyboard shortcuts

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