libs

package
v0.0.0-...-53d016b Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2019 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TIME_FORMAT          = "2006-01-02 15:04:05"
	TIME_FORMAT_YYYYMMDD = "20060102"
)

Variables

View Source
var TimeFormatMap = map[string]string{
	"Y": "2006",
	"m": "01",
	"d": "02",
	"H": "15",
	"i": "04",
	"s": "05",
}

Functions

func CmdCurrentPath

func CmdCurrentPath() (string, error)

func CmdExec

func CmdExec(command string, timeout int, args ...string) ([]byte, error)

execute command with timeout

func CmdExecShell

func CmdExecShell(shell string, timeout int) ([]byte, error)

func CmdExecShellDefault

func CmdExecShellDefault(shell string) ([]byte, error)

func Copy

func Copy(dst interface{}, src interface{}) (err error)

@param dst 要被赋值的结构体,必须是指针 @param src 数据源,必须是一个结构体(非指针)

func CurDatetime

func CurDatetime() string

func Date

func Date(format string, timestamp ...int64) string

*

  • 类似php的date()函数 *
  • @param
  • @return *

func DateToTimestamp

func DateToTimestamp(dateStr string) int64

*

  • 将日期(字符串)转为时间戳

func DiffStrArr

func DiffStrArr(arr1 []string, arr2 []string) []string

*

  • 获取在arr1但不在arr2中的元素(作用跟php的array_diff一样) *

func EscapeShellArg

func EscapeShellArg(arg string) string

EscapeShellArg() adds single quotes around a string and quotes/escapes any existing single quotes allowing you to pass a string directly to a shell function and having it be treated as a single safe argument.

func FilePutContent

func FilePutContent(path string, content string) error

write content to file if file not exists, create first. if file exists, use it.

func FilterStrArr

func FilterStrArr(data []string) []string

*

  • 过滤空字符串数组
  • eg: ["aaa", "", "bbb"]

func GenerateUrl

func GenerateUrl(host string, pathString string, urlValueMap map[string]string) (string, error)

func GetNow

func GetNow() string

func InArray

func InArray(obj interface{}, target interface{}) bool

* 判断obj是否存在于target中,类似于php的in_array方法

func JsonStr

func JsonStr(v interface{}) string

func Map2Struct

func Map2Struct(mapObj interface{}, structObj interface{}) error

mapObj - map 实例 structObj - 结构体实例指针

func Md5Str

func Md5Str(s string) string

*

  • Md5加密字符串

func ParseTemplate

func ParseTemplate(templateStr string, data interface{}) (string, error)

parse golang template

func ReplaceTemplateContent

func ReplaceTemplateContent(fileContent []byte, configMap map[string]string) (changeContent []byte, err error)

func SliceInt64ToSliceIntf

func SliceInt64ToSliceIntf(s []int64) []interface{}

func Struct2Map

func Struct2Map(obj interface{}, toUnderline ...bool) map[string]interface{}

结构体转为 map obj 必须是结构体实例,不可以是指针 toUnderLine, 是否需要将驼峰转为 下划线

func Struct2MapFromMapKeyTag

func Struct2MapFromMapKeyTag(obj interface{}) map[string]string

for example :

    type A struct {
	      str string `mapKey: "MAP_STRING"`
    }
    a := &A{
      str: "val"
    }
    m := Struct2MapFromMapKeyTag(a)
    m["MAP_STRING"] == "val"

func Substr

func Substr(str string, start, length int) string

*

  • 截取字符串

func TarPackage

func TarPackage(workspace, pkgPath string, files []string, excludes []string) ([]byte, string, error)

pack version package

func TransToCamel

func TransToCamel(s string) string

字符串:下划线转驼峰

func TransToUnderline

func TransToUnderline(s string) string

snake string, XxYy to xx_yy , XxYY to xx_yy

func UniqueStrArr

func UniqueStrArr(data []string) []string

*

  • 过滤重复的字符串元素
  • eg: ["a", "b", "a"]

func Utc2LocalDate

func Utc2LocalDate(d string) (string, error)

UTC 时间转本地时间

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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