model

package
v0.0.0-...-a12012e Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultLimit = 10
	DefaultSort  = "created_at"
	DefaultOrder = "desc"
)

Variables

This section is empty.

Functions

func IsClientError

func IsClientError(code Code) bool

func IsRetryableCode

func IsRetryableCode(code Code) bool

func IsServerError

func IsServerError(code Code) bool

func ToHTTPStatus

func ToHTTPStatus(code Code) int

Types

type Code

type Code uint
const (
	CodeErrInternal        Code = 1000
	CodeErrTimeout         Code = 1001 // retryable
	CodeErrTooManyRequests Code = 1002 // retryable
	CodeErrUnavailable     Code = 1003 // retryable

	CodeErrValidation   Code = 2000
	CodeErrNotFound     Code = 2001 // retryable
	CodeErrUnauthorized Code = 2002
	CodeErrForbidden    Code = 2003
	CodeErrTooLarge     Code = 2004
)

func FromFiberError

func FromFiberError(err *fiber.Error) Code

func FromGRPCError

func FromGRPCError(status *status.Status) Code

type Error

type Error struct {
	// Code should be unique and identifiable. It is used to determine the type of error.
	Code Code `example:"1000" json:"code" validate:"required"`
	// Title is a short, human-readable title of the error. It is used to determine the type of error.
	Title string `example:"Internal Server Error" json:"title" validate:"optional"`
	// Message is a human-readable description of the error. Should not be used to display to the user.
	Message string `example:"An unexpected error occurred. Please try again later." json:"message" validate:"optional"`
}

Error model @Description Represents a client-facing API error.

func NewError

func NewError(code Code, message ...string) Error

type RequestPagination

type RequestPagination struct {
	// Token is a base64 string that can be used to retrieve the next page of results.
	// If not present, retrieve the first page.
	Token string `default:"" example:"Vk4gV29ya2RheSBFeGFtcGxl" format:"base64" json:"token" validate:"optional"`
	// Limit is the maximum number of items to return in the response.
	// The default value is 10.
	Limit uint `default:"10" example:"10" json:"limit" maximum:"100" minimum:"1" validate:"required"`
}

RequestPagination godoc @Description Represents a pagination request.

type ResponsePagination

type ResponsePagination struct {
	// NextToken is a token that can be used to retrieve the next page of results.
	// If this field is not present, it means that there are no more results to retrieve.
	NextToken string `example:"Vk4gV29ya2RheSBFeGFtcGxl" format:"base64" json:"next_token" validate:"optional"`
	// PreviousToken a token that can be used to retrieve the previous page of results.
	// If this field is not present, it means that there are no more results to retrieve.
	PreviousToken string `example:"Vk4gV29ya2RheSBFeGFtcGxl" format:"base64" json:"previous_token" validate:"optional"`
	// Total is the total number of items in the list.
	Total uint `example:"100" json:"total" minimum:"0" validate:"required"`
	// TotalPages is the total number of pages in the list.
	TotalPages uint `example:"10" json:"total_pages" minimum:"0" validate:"required"`
}

ResponsePagination godoc @Description Represents a pagination response.

Jump to

Keyboard shortcuts

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