utils

package module
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2022 License: BSD-2-Clause Imports: 6 Imported by: 0

README

utils

Utils is a go language development toolkit that mainly includes functions such as string, slice, map, time, type judgment, type conversion, and data compression.

Installing utils
go get github.com/kirinlabs/utils
How to use utils?

Public

  import "github.com/kirinlabs/utils"

  utils.Empty(arg interface{}) bool
  utils.Export(arg interface{}) string
  utils.Json(arg interface{}) string
  utils.Decode(s string) error
  utils.Unmarshal(s string, args ...interface{}) interface{}
  
  utils.Type(arg interface{}) string
  utils.IsInt(arg interface{}) bool
  utils.IsInt64(arg interface{}) bool
  utils.IsFloat64(arg interface{}) bool
  utils.IsString(arg interface{}) bool
  utils.IsTime(arg interface{}) bool
  utils.IsBool(arg interface{}) bool
  utils.IsSlice(arg interface{}) bool
  utils.If(c bool).Then(v interface{}).Else(v interface{}).String()  string
  utils.If(c bool).Then(v interface{}).Else(v interface{}).Int()     int64 error
  utils.If(c bool).Then(v interface{}).Else(v interface{}).Float()   float64 error

String

  import "github.com/kirinlabs/utils/str"

  s := "hello github"
  str.Before(s, "github")
  str.BeforeLast(s, "github")
  str.After(s, "git")
  str.AfterLast(s, "git")
  str.StartsWith(s, "hel")
  str.EndsWitdh(s, "b")
  str.RuneIndex(s,"github")
  str.Substr(s, 2, 3)
  str.Char(s)
  str.Escape(s)
  str.Contians(s, "hub")
  str.StartsWith(s, "hel")
  str.EndsWitdh(s, "b")
  str.String(i interface{})
  str.Length(s)
  str.Ufirst(s)
  

Slice

  import "github.com/kirinlabs/utils/sli"

  sli.InSlice(v interface{}, s interface{}) bool
  sli.InInterface(v interface{}, sl []interface{}) bool
  sli.Slice(iface interface{}) ([]interface{}, error)
  sli.Unique(list *[]string) []string
  sli.UniqueInt(list *[]int) []int
  sli.UniqueInt64(list *[]int64) []int64
  sli.Chunk(slice []interface{}, size int) (chunk [][]interface{})
  sli.Range(start, end, step int64) (intslice []int64)
  sli.Pad(slice []interface{}, size int, val interface{}) []interface{}
  sli.Shuffle(slice []interface{}) []interface{}
  sli.Diff(slice1, slice2 []string) (diffslice []string)
  sli.Intersect(slice1, slice2 []string) (interSlice []string)
  sli.Reverse(list *[]string) []string
  sli.ReverseInt(list *[]int) []int
  sli.ReverseInt64(list *[]int64) []int64
  sli.ReverseFloat(list *[]float64) []float64
  sli.Rand(a []string) (b string)
  sli.RandInt(a []int) (b int)
  sli.RandInt64(a []int64) (b int64)
  sli.Sum(i []int64) (s int64)
  sli.Range(start, end, step int64) (intslice []int64)
  sli.JoinInt(s []int,sep ...string) string
  sli.SplitInt(str string, sep ...string) ([]int, error)

Convert

  import "github.com/kirinlabs/utils/convert"

  convert.Int2Bytes(v interface{}) []byte
  convert.Int(v interface{}) (int64, error)
  convert.Float(v interface{}) (float64, error)
  convert.Bool(bs []byte) (bool, error)
  convert.Bytes(buf []byte, val reflect.Value) (b []byte, ok bool)
  convert.String(iface interface{}) string
  convert.Kind(vv reflect.Value, tp reflect.Type) (interface{}, error)

Datetime

  import "github.com/kirinlabs/utils/datetime"

  datetime.Gmtime() string
  datetime.Localtime() string
  datetime.Strtotime(s string, args ...string) (time.Time, error)
  datetime.String(format ...string) string
  datetime.Year(t ...time.Time) int
  datetime.Month(t ...time.Time) int
  datetime.Day(t ...time.Time) int
  datetime.YearDay(t ...time.Time) int
  datetime.Hour(t ...time.Time) int
  datetime.Minute(t ...time.Time) int
  datetime.Second(t ...time.Time) int
  datetime.Millisecond() int64
  datetime.Microsecond() int64
  datetime.Nanosecond() int64
  datetime.Timestamp(args ...string) int64

Encrypt

  import "github.com/kirinlabs/utils/encrypt"

  encrypt.Md5(s string) string
  encrypt.Sha1(s string) string
  encrypt.Sha256(s string) string
  encrypt.Sha512(s string) string
  encrypt.Base64Encode(s string) string
  encrypt.Base64Decode(s string) string

  AES/ECB
  ae := encrypt.NewEcb([]byte("0123456789ABCDEF"))
  encrypted, err := ae.Encrypt(src []byte)   
  decrypted, err := ae.Decrypt(encrypted []byte)
  

sys

  import "github.com/kirinlabs/utils/sys"

  sys.RealPath(f string) string
  sys.IsExists(path string) bool
  sys.IsFile(f string) bool
  sys.IsDir(p string) bool

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode added in v0.1.3

func Decode(s string) interface{}

func Else added in v0.4.1

func Else(v interface{}) *ifThen

func Empty

func Empty(arg interface{}) bool

Determine if the variable is null

func Export

func Export(v interface{}) string

Returns a formatted Json string

func If added in v0.4.1

func If(c bool) *ifThen

utils.If(c).Then(v).Else(v).String()

func IsBool

func IsBool(arg interface{}) bool

func IsFloat added in v0.3.2

func IsFloat(arg interface{}) bool

Float64

func IsInt

func IsInt(arg interface{}) bool

Int

func IsInt64

func IsInt64(arg interface{}) bool

Int64

func IsSlice

func IsSlice(arg interface{}) bool

func IsString

func IsString(arg interface{}) bool

String

func IsTime

func IsTime(arg interface{}) bool

func Json

func Json(v interface{}) string

Returns a Json string

func Then added in v0.4.1

func Then(v interface{}) *ifThen

func Type

func Type(arg interface{}) string

Returns a string of variable type

func Unmarshal added in v0.3.2

func Unmarshal(s string, args ...interface{}) error

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