goutils

package module
v0.0.0-...-48bdaee Latest Latest
Warning

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

Go to latest
Published: May 22, 2018 License: MIT Imports: 27 Imported by: 9

README

goutils

golang utils

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RMQHttpApiTimeout time.Duration = 10 * time.Second
)
View Source
var (
	TemplateHelpers = template.FuncMap{
		"IntSub": func(v1 interface{}, v2 interface{}) int64 {
			return IntArithmetic(v1, v2, "-")
		},
		"IntAdd": func(v1 interface{}, v2 interface{}) int64 {
			return IntArithmetic(v1, v2, "+")
		},
		"ToLower": func(s interface{}) string {
			return strings.ToLower(ToString(s))
		},
		"Price": func(v int64) interface{} {
			str := strconv.FormatInt(v, 10)
			len := len(str)
			return str[:len-2] + "." + str[len-2:]
		},
		"PriceInt": func(v int64) interface{} {
			str := strconv.FormatInt(v, 10)
			len := len(str)
			return str[:len-2]
		},
		"unescape": func(s string) interface{} {
			return template.HTML(s)
		},
	}
)

Functions

func AddBase64Padding

func AddBase64Padding(value string) string

func AesCBCDecrypt

func AesCBCDecrypt(key []byte, text string) (string, error)

func AesCBCEncrypt

func AesCBCEncrypt(key []byte, text string) (string, error)

func CompareRuntimeVersion

func CompareRuntimeVersion(version string) bool

* runtime version >= version; return true * runtime version < version; return false

func CompareVersion

func CompareVersion(v1, v2 string, width int) string

func CurrentTimeMills

func CurrentTimeMills() int64

func EchoStartWithGracefulShutdown

func EchoStartWithGracefulShutdown(app *echo.Echo, addr string)

func EchoStartWithGracefulShutdownThanGo18

func EchoStartWithGracefulShutdownThanGo18(app *echo.Echo, addr string)

func EchoStartWithGracefulShutdownUseThirdPlugin

func EchoStartWithGracefulShutdownUseThirdPlugin(app *echo.Echo, addr string)

func InStringSlice

func InStringSlice(slice []string, s string) bool

func IntArithmetic

func IntArithmetic(v1, v2 interface{}, t string) (result int64)

* template helpers

func ModelType

func ModelType(value interface{}) reflect.Type

func NewEcho

func NewEcho() *echo.Echo

func NewEchoHosts

func NewEchoHosts(hosts map[string]EchoHost) *echo.Echo

func NewTemplate

func NewTemplate(name, patter string) *template.Template

func PKCS5PaddingPad

func PKCS5PaddingPad(src []byte) []byte

func PKCS5PaddingUnpad

func PKCS5PaddingUnpad(src []byte) ([]byte, error)

func RandStr

func RandStr(strlen int) string

func RandomString

func RandomString(strlen int) string

func RegisterQueue

func RegisterQueue(api, user, passwd, vhost, name, exchange, key string) error

func RemoveBase64Padding

func RemoveBase64Padding(value string) string

func ToBool

func ToBool(v interface{}) bool

func ToFloat

func ToFloat(v interface{}) float64

func ToInt

func ToInt(v interface{}) int64

func ToInt32

func ToInt32(v interface{}) int32

func ToInt64

func ToInt64(v interface{}) int64

func ToPrice

func ToPrice(f float64) int64

func ToString

func ToString(v interface{}) (s string)

Types

type DefaultLogInstance

type DefaultLogInstance struct {
	LoggerInterface
}

func (*DefaultLogInstance) Debug

func (c *DefaultLogInstance) Debug(format string, v ...interface{})

func (*DefaultLogInstance) Error

func (c *DefaultLogInstance) Error(format string, v ...interface{})

func (*DefaultLogInstance) Fatal

func (c *DefaultLogInstance) Fatal(format string, v ...interface{})

func (*DefaultLogInstance) Info

func (c *DefaultLogInstance) Info(format string, v ...interface{})

func (*DefaultLogInstance) Panic

func (c *DefaultLogInstance) Panic(format string, v ...interface{})

func (*DefaultLogInstance) Sync

func (c *DefaultLogInstance) Sync()

func (*DefaultLogInstance) Warn

func (c *DefaultLogInstance) Warn(format string, v ...interface{})

type EchoHost

type EchoHost struct {
	Echo *echo.Echo
}

type EchoTemplate

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

* echo templater support

func NewEchoRenderer

func NewEchoRenderer(name, patter string) *EchoTemplate

func (*EchoTemplate) Render

func (t *EchoTemplate) Render(w io.Writer, name string, data interface{}, c echo.Context) error

type Logger

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

func DefaultLogger

func DefaultLogger() *Logger

func ZapLogger

func ZapLogger(logger *zap.Logger) *Logger

func (*Logger) Debug

func (c *Logger) Debug(format string, v ...interface{})

func (*Logger) Error

func (c *Logger) Error(format string, v ...interface{})

func (*Logger) Fatal

func (c *Logger) Fatal(format string, v ...interface{})

func (*Logger) Info

func (c *Logger) Info(format string, v ...interface{})

func (*Logger) Panic

func (c *Logger) Panic(format string, v ...interface{})

func (*Logger) Set

func (c *Logger) Set(instance interface{})

func (*Logger) Sync

func (c *Logger) Sync()

func (*Logger) Warn

func (c *Logger) Warn(format string, v ...interface{})

type LoggerInterface

type LoggerInterface interface {
	Error(string, ...interface{})
	Debug(string, ...interface{})
	Fatal(string, ...interface{})
	Panic(string, ...interface{})
	Warn(string, ...interface{})
	Info(string, ...interface{})
	Sync()
}

type Map

type Map struct {
	Value interface{}
}

func NewMap

func NewMap(value interface{}) *Map

func (*Map) Get

func (c *Map) Get(key interface{}) (ret interface{}, ok bool)

func (*Map) GetBool

func (c *Map) GetBool(key interface{}) (bool, bool)

func (*Map) GetFloat

func (c *Map) GetFloat(key interface{}) (float64, bool)

func (*Map) GetInt32

func (c *Map) GetInt32(key interface{}) (int32, bool)

func (*Map) GetInt64

func (c *Map) GetInt64(key interface{}) (int64, bool)

func (*Map) GetSlice

func (c *Map) GetSlice(key interface{}) ([]interface{}, bool)

func (*Map) GetString

func (c *Map) GetString(key interface{}) (string, bool)

func (*Map) GetStringSlice

func (c *Map) GetStringSlice(key interface{}) ([]string, bool)

func (*Map) Int32

func (c *Map) Int32(key interface{}, def ...interface{}) int32

func (*Map) Load

func (c *Map) Load(value interface{})

func (*Map) String

func (c *Map) String(key interface{}, def ...interface{}) string

type NullString

type NullString struct {
	String string
	Valid  bool
}

func EchoCtxFormNullString

func EchoCtxFormNullString(ctx echo.Context, key string) (ret *NullString)

func EchoCtxQueryNullString

func EchoCtxQueryNullString(ctx echo.Context, key string) (ret *NullString)

type RMQHttpApi

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

func NewRMQHttpApi

func NewRMQHttpApi(host, user, passwd string) (c *RMQHttpApi, err error)

func (*RMQHttpApi) GET

func (c *RMQHttpApi) GET(apiPath string) (*http.Response, error)

func (*RMQHttpApi) Permissions

func (c *RMQHttpApi) Permissions() ([]RMQPermission, error)

func (*RMQHttpApi) Scan

func (c *RMQHttpApi) Scan(rsp *http.Response, err error) (int, []byte, error)

func (*RMQHttpApi) WhoAmI

func (c *RMQHttpApi) WhoAmI() (map[string]string, error)

type RMQPermission

type RMQPermission struct {
	User      string `json:"user"`
	Vhost     string `json:"vhost"`
	Configure string `json:"configure"`
	Write     string `json:"write"`
	Read      string `json:"read"`
}

type Resource

type Resource struct {
	Name  string
	Value interface{}
	Tags  []*Tag
}

func NewResource

func NewResource(value interface{}) *Resource

func (*Resource) GetResource

func (this *Resource) GetResource() *Resource

func (*Resource) GetTag

func (this *Resource) GetTag(name string) *Tag

func (*Resource) NewSlice

func (this *Resource) NewSlice() interface{}

func (*Resource) NewStruct

func (this *Resource) NewStruct() interface{}

func (*Resource) Tag

func (this *Resource) Tag(tag *Tag) *Tag

type Tag

type Tag struct {
	Name     string
	Type     string
	Label    string
	Memo     string
	Resource *Resource
}

type ZapLoggerInstance

type ZapLoggerInstance struct {
	LoggerInterface
	// contains filtered or unexported fields
}

func (*ZapLoggerInstance) Debug

func (c *ZapLoggerInstance) Debug(format string, v ...interface{})

func (*ZapLoggerInstance) Error

func (c *ZapLoggerInstance) Error(format string, v ...interface{})

func (*ZapLoggerInstance) Fatal

func (c *ZapLoggerInstance) Fatal(format string, v ...interface{})

func (*ZapLoggerInstance) Info

func (c *ZapLoggerInstance) Info(format string, v ...interface{})

func (*ZapLoggerInstance) Panic

func (c *ZapLoggerInstance) Panic(format string, v ...interface{})

func (*ZapLoggerInstance) Sync

func (c *ZapLoggerInstance) Sync()

func (*ZapLoggerInstance) Warn

func (c *ZapLoggerInstance) Warn(format string, v ...interface{})

Jump to

Keyboard shortcuts

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