types

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: GPL-3.0 Imports: 1 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound            = NewHttpError(http.StatusNotFound)
	ErrBadRequest          = NewHttpError(http.StatusBadRequest)
	ErrServiceUnavailable  = NewHttpError(http.StatusServiceUnavailable)
	ErrInternalServerError = NewHttpError(http.StatusInternalServerError)
)

Functions

func IsError

func IsError(err error) bool

Types

type Error

type Error struct {
	Code     int    `json:"code"`
	Key      string `json:"error,omitempty"`
	Success  bool   `json:"success"`
	Message  string `json:"message"`
	Internal error  `json:"-"`
}

Error 异常结构

func ErrorOf

func ErrorOf(err error) *Error

func NewError

func NewError(code int, message ...string) *Error

func NewHttpError

func NewHttpError(code int, message ...string) *Error

func (Error) Error

func (err Error) Error() string

type Optional added in v0.3.4

type Optional[T any] struct {
	// contains filtered or unexported fields
}

Optional 定义一个 Optional 类型。

func NewOptional added in v0.3.4

func NewOptional[T any](value T) Optional[T]

NewOptional 创建一个新的 Optional 对象。

func (Optional[T]) Get added in v0.3.4

func (o Optional[T]) Get() T

Get 获取 Optional 对象的值。

func (Optional[T]) IfPresent added in v0.3.4

func (o Optional[T]) IfPresent(consumer func(T))

IfPresent 如果 Optional 对象不为空,则执行给定的消费者。

func (Optional[T]) IsEmpty added in v0.3.4

func (o Optional[T]) IsEmpty() bool

IsEmpty 检查 Optional 对象是否为空。

func (Optional[T]) OrElseGet added in v0.3.4

func (o Optional[T]) OrElseGet(value T) T

OrElseGet 如果 Optional 对象不为空,则返回其值,否则返回给定值。

type Result

type Result struct {
	Code    int         `json:"code"`
	Success bool        `json:"success,omitempty"`
	Message interface{} `json:"message,omitempty"`
	Data    interface{} `json:"data,omitempty"`
}

Result 返回结果

func ResultNilData

func ResultNilData(code int) *Result

Result 无Data

func ResultOf

func ResultOf(code int, data interface{}) *Result

Result 构造Result

Jump to

Keyboard shortcuts

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