response

package
v0.0.0-...-815ad63 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var File_pkg_response_response_meta_proto protoreflect.FileDescriptor

Functions

func HTTPStatusCodeToGRPCCode

func HTTPStatusCodeToGRPCCode(code int) codes.Code

Types

type IStatus

type IStatus interface {
	IsError() bool
	Error() string
	MessageOrDefault() string
}

type Log

type Log struct {
	Response   Response `json:"response"`
	Message    string   `json:"message"`
	Caller     string   `json:"caller"`
	StackTrace []string `json:"stack_trace"`
}

type Meta

type Meta struct {
	Total       int64 `json:"total"`
	PageCurrent int32 `json:"page"`
	Limit       int32 `json:"limit"`
}

type Response

type Response struct {
	Status ResponseStatus `json:"status"`
	Data   any            `json:"data,omitempty"`
	Meta   *ResponseMeta  `json:"meta,omitempty"`
}

type ResponseBadRequest

type ResponseBadRequest struct {
	Status ResponseStatusBadRequest `json:"status"`
}

type ResponseErrorWithoutDetails

type ResponseErrorWithoutDetails struct {
	Status ResponseStatusWithoutDetails `json:"status"`
}

type ResponseMeta

type ResponseMeta struct {
	Total int64         `protobuf:"varint,1,opt,name=total,proto3" json:"total" example:"100"`
	Limit int32         `protobuf:"varint,2,opt,name=limit,proto3" json:"limit" example:"10"`
	Page  *ResponsePage `protobuf:"bytes,3,opt,name=page,proto3" json:"page"`
	// contains filtered or unexported fields
}

func ResponseMetaSetup

func ResponseMetaSetup(total int64, limit, pageCurrent int32) *ResponseMeta

func (*ResponseMeta) Descriptor deprecated

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

Deprecated: Use ResponseMeta.ProtoReflect.Descriptor instead.

func (*ResponseMeta) GetLimit

func (x *ResponseMeta) GetLimit() int32

func (*ResponseMeta) GetPage

func (x *ResponseMeta) GetPage() *ResponsePage

func (*ResponseMeta) GetTotal

func (x *ResponseMeta) GetTotal() int64

func (*ResponseMeta) ProtoMessage

func (*ResponseMeta) ProtoMessage()

func (*ResponseMeta) ProtoReflect

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

func (*ResponseMeta) Reset

func (x *ResponseMeta) Reset()

func (*ResponseMeta) String

func (x *ResponseMeta) String() string

type ResponsePage

type ResponsePage struct {
	First    int32  `protobuf:"varint,1,opt,name=first,proto3" json:"first" example:"1"`
	Previous *int32 `protobuf:"varint,2,opt,name=previous,proto3,oneof" json:"previous" example:"2"`
	Current  int32  `protobuf:"varint,3,opt,name=current,proto3" json:"current" example:"3"`
	Next     *int32 `protobuf:"varint,4,opt,name=next,proto3,oneof" json:"next" example:"4"`
	Last     int32  `protobuf:"varint,5,opt,name=last,proto3" json:"last" example:"9"`
	// contains filtered or unexported fields
}

func ResponsePageSetup

func ResponsePageSetup(total int64, limit, pageCurrent int32) *ResponsePage

func (*ResponsePage) Descriptor deprecated

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

Deprecated: Use ResponsePage.ProtoReflect.Descriptor instead.

func (*ResponsePage) GetCurrent

func (x *ResponsePage) GetCurrent() int32

func (*ResponsePage) GetFirst

func (x *ResponsePage) GetFirst() int32

func (*ResponsePage) GetLast

func (x *ResponsePage) GetLast() int32

func (*ResponsePage) GetNext

func (x *ResponsePage) GetNext() int32

func (*ResponsePage) GetPrevious

func (x *ResponsePage) GetPrevious() int32

func (*ResponsePage) ProtoMessage

func (*ResponsePage) ProtoMessage()

func (*ResponsePage) ProtoReflect

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

func (*ResponsePage) Reset

func (x *ResponsePage) Reset()

func (*ResponsePage) String

func (x *ResponsePage) String() string

type ResponseStatus

type ResponseStatus struct {
	Code    string `json:"code" example:"200.1"`
	Message string `json:"message" example:"OK"`
	Details any    `json:"details,omitempty"`
}

type ResponseStatusBadRequest

type ResponseStatusBadRequest struct {
	Code    string                   `json:"code" example:"400.1"`
	Message string                   `json:"message" example:"Bad Request"`
	Details []*errdetails.BadRequest `json:"details,omitempty"`
}

type ResponseStatusWithoutDetails

type ResponseStatusWithoutDetails struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

type ResponseSuccess

type ResponseSuccess struct {
	Status ResponseStatusWithoutDetails `json:"status"`
	Data   any                          `json:"data,omitempty"`
}

type ResponseSuccessWithMeta

type ResponseSuccessWithMeta struct {
	Status ResponseStatusWithoutDetails `json:"status"`
	Data   any                          `json:"data,omitempty"`
	Meta   *ResponseMeta                `json:"meta,omitempty"`
}

type Status

type Status struct {
	// HTTP status codes as registered with IANA. See: https://go.dev/src/net/http/status.go
	Code int `json:"code"`

	// message for ui/ux
	Message string `json:"message"`

	// message for engineer
	CauseError error    `json:"cause_error"`
	StackTrace []string `json:"stack_trace"`

	Data    any                    `json:"data"`
	Meta    *Meta                  `json:"meta"`
	Details []protoadapt.MessageV1 `json:"details"`

	Caller string `json:"caller"`
}

use this Status to wrap error across all apps including non http app

func NewStatusBadRequest

func NewStatusBadRequest(langCode, field, message, reason string, err error) *Status

func NewStatusCode

func NewStatusCode(code int) *Status

func NewStatusData

func NewStatusData(code int, data any) *Status

func NewStatusDataMeta

func NewStatusDataMeta(code int, data any, meta *Meta) *Status

func NewStatusDetails

func NewStatusDetails(code int, message string, details ...protoadapt.MessageV1) *Status

func NewStatusError

func NewStatusError(code int, err error) *Status

func NewStatusMessage

func NewStatusMessage(code int, message string, err error) *Status

func NewStatusMessageData

func NewStatusMessageData(code int, message string, data any, err error) *Status

func NewStatusSuccess

func NewStatusSuccess(code int, message string, data any) *Status

func (*Status) BadRequests

func (s *Status) BadRequests() []*errdetails.BadRequest

func (*Status) CauseErrorMessageOrDefault

func (s *Status) CauseErrorMessageOrDefault() string

func (*Status) Error

func (s *Status) Error() string

func (*Status) GRPCStatus

func (s *Status) GRPCStatus() *status.Status

func (*Status) IsError

func (s *Status) IsError() bool

func (*Status) MessageOrDefault

func (s *Status) MessageOrDefault() string

type StatusHolder

type StatusHolder struct {
	Status *Status
}

Jump to

Keyboard shortcuts

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