utils

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2019 License: Apache-2.0 Imports: 4 Imported by: 2

README

go-utils

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ExceptionDebug = true

ExceptionDebug 表示全局默认是否是调试状态,默认:true

Functions

func GetErrorCode

func GetErrorCode(err error) string

func MoneyToYuan

func MoneyToYuan(v uint64) float64

Types

type Converter

type Converter interface {
	Err() error

	Value() interface{}

	String() string
	TryString() (string, error)

	Bool() bool
	TryBool() (bool, error)

	Int16() int16
	TryInt16() (int16, error)
	Int() int
	TryInt() (int, error)
	Int64() int64
	TryInt64() (int64, error)

	Uint16() uint16
	TryUint16() (uint16, error)
	Uint() uint
	TryUint() (uint, error)
	Uint64() uint64
	TryUint64() (uint64, error)

	Float32() float32
	TryFloat32() (float32, error)
	Float64() float64
	TryFloat64() (float64, error)
}

Converter 定义的一组转换函数,该接口用于指导其它依赖该转换的组件。 扩展 redis 或 sql 执行结果时刻返回该接口。

func Convert

func Convert(v interface{}, computedErr error, zeroIfNil ...bool) Converter

Convert 准备转换一个计算值。 computedErr 表示事先计算时产生的错误,如:函数调用 `fn()(v int, err error)`,该错误始终生效,非 TryXXX 转换报 panic。 zeroIfNil 表示在没有错误的情况下值为空,是否可以返回它们的默认值。

type DefaultConverter

type DefaultConverter struct {
	DefaultValue interface{}
	ComputedErr  error
	ZeroIfNil    bool
}

func (*DefaultConverter) Bool

func (c *DefaultConverter) Bool() bool

func (*DefaultConverter) Err

func (c *DefaultConverter) Err() error

func (*DefaultConverter) Float32

func (c *DefaultConverter) Float32() float32

func (*DefaultConverter) Float64

func (c *DefaultConverter) Float64() float64

func (*DefaultConverter) Int

func (c *DefaultConverter) Int() int

func (*DefaultConverter) Int16

func (c *DefaultConverter) Int16() int16

func (*DefaultConverter) Int64

func (c *DefaultConverter) Int64() int64

func (*DefaultConverter) String

func (c *DefaultConverter) String() string

func (*DefaultConverter) TryBool

func (c *DefaultConverter) TryBool() (bool, error)

func (*DefaultConverter) TryFloat32

func (c *DefaultConverter) TryFloat32() (float32, error)

func (*DefaultConverter) TryFloat64

func (c *DefaultConverter) TryFloat64() (float64, error)

func (*DefaultConverter) TryInt

func (c *DefaultConverter) TryInt() (int, error)

func (*DefaultConverter) TryInt16

func (c *DefaultConverter) TryInt16() (int16, error)

func (*DefaultConverter) TryInt64

func (c *DefaultConverter) TryInt64() (int64, error)

func (*DefaultConverter) TryString

func (c *DefaultConverter) TryString() (string, error)

func (*DefaultConverter) TryUint

func (c *DefaultConverter) TryUint() (uint, error)

func (*DefaultConverter) TryUint16

func (c *DefaultConverter) TryUint16() (uint16, error)

func (*DefaultConverter) TryUint64

func (c *DefaultConverter) TryUint64() (uint64, error)

func (*DefaultConverter) Uint

func (c *DefaultConverter) Uint() uint

func (*DefaultConverter) Uint16

func (c *DefaultConverter) Uint16() uint16

func (*DefaultConverter) Uint64

func (c *DefaultConverter) Uint64() uint64

func (*DefaultConverter) Value

func (c *DefaultConverter) Value() interface{}

type Error

type Error interface {
	error
	Debug() bool
	SetDebug(b bool) Error
	Code() string
	Message() string
}

type Exception

type Exception struct {
	// contains filtered or unexported fields
}

Exception 封装一个带有层级和 Code 的错误。

func Err

func Err(code string, innerOrMsg ...interface{}) *Exception

func (*Exception) Code

func (e *Exception) Code() string

func (*Exception) Debug

func (e *Exception) Debug() bool

func (*Exception) Error

func (e *Exception) Error() string

func (*Exception) MarshalJSON

func (e *Exception) MarshalJSON() ([]byte, error)

func (*Exception) Message

func (e *Exception) Message() string

func (*Exception) SetDebug

func (e *Exception) SetDebug(b bool) Error

Directories

Path Synopsis
Package assert 简单的断言工具包.
Package assert 简单的断言工具包.

Jump to

Keyboard shortcuts

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