yuresp

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodeOK int = iota
	CodeErr
)

返回code值

Variables

Functions

func GzipPbRespOK

func GzipPbRespOK(w http.ResponseWriter, m proto.Message) error

GzipPbRespOK gzip压缩pb返回正确

func PbRespError

func PbRespError(w http.ResponseWriter, err error) error

PbRespOK pb返回错误

func PbRespOK

func PbRespOK(w http.ResponseWriter, m proto.Message) error

PbRespOK pb返回正确

Types

type PbResp

type PbResp struct {
	Code    int32      `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"`
	Message string     `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"`
	Data    *anypb.Any `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"`
	// contains filtered or unexported fields
}

http返回结果

func (*PbResp) Descriptor deprecated

func (*PbResp) Descriptor() ([]byte, []int)

Deprecated: Use PbResp.ProtoReflect.Descriptor instead.

func (*PbResp) GetCode

func (x *PbResp) GetCode() int32

func (*PbResp) GetData

func (x *PbResp) GetData() *anypb.Any

func (*PbResp) GetMessage

func (x *PbResp) GetMessage() string

func (*PbResp) ProtoMessage

func (*PbResp) ProtoMessage()

func (*PbResp) ProtoReflect

func (x *PbResp) ProtoReflect() protoreflect.Message

func (*PbResp) Reset

func (x *PbResp) Reset()

func (*PbResp) String

func (x *PbResp) String() string

type Resp

type Resp[T any] struct {
	Code int    `json:"code"`
	Msg  string `json:"msg,omitempty"`
	Data T      `json:"data,omitempty"`
}

Resp http统一返回结构

func NewResp

func NewResp[T any](code int, msg string, data T) *Resp[T]

NewResp 创建一个返回结构

func RespErr

func RespErr(err error) *Resp[any]

RespErr 创建一个返回error的结构

func RespMsg

func RespMsg(code int, msg string) *Resp[any]

RespMsg 创建一个返回字符串信息的结构

func RespOK

func RespOK[T any](data T) *Resp[T]

RespOK 创建一个返回OK的结构

Jump to

Keyboard shortcuts

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