strutil

package
v0.0.0-...-73717b0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrConvType = errors.New("convert value type error")
View Source
var SprintToStrFunc = func(v interface{}) (string, error) {
	if v == nil {
		return "", nil
	}
	return fmt.Sprint(v), nil
}

SprintToStrFunc convert any value to string by fmt.Sprint

Functions

func CalculateContentMD5

func CalculateContentMD5(data io.Reader, size int64) (string, error)

func NewRequestId

func NewRequestId() string

func NewUUID

func NewUUID() string

func SafeString

func SafeString(in interface{}) string

SafeString convert value to string, will ignore error

func ToStringWithFunc

func ToStringWithFunc(val interface{}, fbFn ToStringFunc) (str string, err error)

ToStringWithFunc convert value to string, with a func to fallback handle.

On not convert:

  • If fbFn is nil, will return ErrConvType.
  • If fbFn is not nil, will call it to convert.

func UriEncode

func UriEncode(uri string, encodeSlash bool) string

Types

type ToStringFunc

type ToStringFunc func(v interface{}) (string, error)

ToStringFunc try to convert value to string, return error on fail

Jump to

Keyboard shortcuts

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