data

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2021 License: MIT Imports: 4 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ErrCodeInternal = 10000
	ErrCodeNotFound = 10001
	ErrCodeConflict = 10002
	ErrCodeFriendly = 10003
	ErrCodeValidate = 10004
	ErrCodeFormat   = 10005
)

Variables

View Source
var (
	ErrNotFound = &BaseError{Code: ErrCodeNotFound, Message: "data not found"}
	ErrConflict = &BaseError{Code: ErrCodeConflict, Message: "data is existed or has be updated"}
)

Functions

func BuildNextPageToken

func BuildNextPageToken(pager PagerInfo) (string, error)

It is google web API, please refer https://cloud.google.com/apis/design/design_patterns#list_pagination

func NewConflictError

func NewConflictError(msg string) error

func NewFormatError

func NewFormatError(msg string) error

func NewFriendlyError

func NewFriendlyError(msg string) error

func NewInternalError

func NewInternalError(msg string) error

func NewNotFoundError

func NewNotFoundError(msg string) error

func NewValidateError

func NewValidateError(msg string, items []ValidateErrItem) error

func RecoverPager

func RecoverPager(pager PagerInfo) (bool, error)

Types

type BaseError

type BaseError struct {
	Code      int
	Message   string
	Data      interface{}
	SourceSrv string
}

func (*BaseError) Error

func (e *BaseError) Error() string

func (*BaseError) Is

func (e *BaseError) Is(err error) bool

type CallSrvError

type CallSrvError struct {
	SrvResp *Response
	BaseError
}

type FileResponse

type FileResponse struct {
	Name        string
	ContentType string
	Content     []byte
}

func (*FileResponse) Get

func (r *FileResponse) Get() (name, contentType string, content []byte)

type PagerInfo

type PagerInfo interface {
	GetPageInfo() (pageSize, pageNumber int, pageToken string)
	SetPageNumber(pageNumber int)
}

type Response

type Response struct {
	Code      int         `json:"code"`
	Message   string      `json:"message"`
	Data      interface{} `json:"data"`
	RequestID string      `json:"request_id"`
}

func (*Response) Set

func (r *Response) Set(code int, msg string, data interface{})

func (*Response) SetReqID

func (r *Response) SetReqID(reqId string)

type SortAble

type SortAble struct {
	// format: "field[ desc], field2[ desc]"
	OrderBy string `json:"order_by" form:"order_by" auto_read:"order_by"`
}

func (*SortAble) GetSortInfo

func (s *SortAble) GetSortInfo() []*SortPair

type SortInfo

type SortInfo interface {
	GetSortInfo() []*SortPair
}

type SortPair

type SortPair struct {
	Field        string
	IsDescending bool
}

type SpecCodeResponse

type SpecCodeResponse struct {
	Response
	StatusCode int `json:"-"`
}

func (*SpecCodeResponse) GetStatusCode

func (r *SpecCodeResponse) GetStatusCode() int

type ValidateErrItem

type ValidateErrItem struct {
	ParamName string      `json:"paramName"`
	Reason    string      `json:"reason"`
	Detail    interface{} `json:"detail"`
}

type ValidateError

type ValidateError struct {
	BaseError
}

Jump to

Keyboard shortcuts

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