GithubHelp home page GithubHelp logo

laizizi / utils Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kirinlabs/utils

0.0 0.0 0.0 36 KB

Golang开发扩展库,包括字符串处理、日期转换、类型转换、切片处理、压缩、加密、AES/ECB加密解密等

License: BSD 2-Clause "Simplified" License

Go 100.00%

utils's Introduction

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

utils's People

Contributors

microkirin avatar kirinlabs avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.