Skip to content

gaols/goutils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

goutils

Description

Some common utilities to make your development more productive.

Install

go get github.com/gaols/goutils

utilities

stringutils

if you come from Java, you should familiar with the those apis. It's the go implementation of apache commons for string manipulation.

import "github.com/gaols/goutils"

goutils.Reverse("fox")                // out: xof
goutils.LeftPad("fox", 5, 'z')        // out: zzfox
goutils.RightPad("fox", 5, 'z')       // out: foxzz
goutils.IsBlank(" ")                  // out: true
goutils.IsBlank("a")                  // out: false
goutils.IsEmpty("")                   // out: true
goutils.IsEmpty(" ")                  // out: false
goutils.DefaultIfBlank(" ", "hello")  // out: hello
goutils.DefaultIfBlank("c", "hello")  // out: c
goutils.DefaultIfEmpty("", "hello")   // out: hello
goutils.DefaultIfEmpty("c", "hello")  // out: c
goutils.Substring("hello", 0, 1)      // out: h
goutils.IsAnyBlank("hello", "")       // out: true
goutils.IsAnyBlank("hello")           // out: false

dateutils

date utils has a lot of date related sugar methods.

goutils.Today()
goutils.Yesterday()
goutils.BeginningOfThisWeek()
goutils.BeginningOfThisMonth()
goutils.BeginningOfThisYear()
goutils.LastWeek()
goutils.LastMonth()
goutils.LastYear()
// ... and many others

timeutils

// assumes time now is: 2017-12-27 21:15:15
goutils.FmtTime(time.Now(), "-datetime")      // out: 2017-12-27 21:15:15
goutils.FmtTime(time.Now(), "-datetime-")     // out: 2017-12-27 21:15
goutils.FmtTime(time.Now(), "-datetime--")    // out: 2017-12-27 21
goutils.FmtTime(time.Now(), "-date")          // out: 2017-12-27
goutils.FmtTime(time.Now(), "time")           // out: 21:15:15
goutils.FmtTime(time.Now(), "time-")          // out: 21:15
goutils.FmtTime(time.Now(), "time--")         // out: 21

goutils.FmtTime(time.Now(), "/datetime")      // out: 2017/12/27 21:15:15
goutils.FmtTime(time.Now(), "/datetime-")     // out: 2017/12/27 21:15
goutils.FmtTime(time.Now(), "/datetime--")    // out: 2017/12/27 21
goutils.FmtTime(time.Now(), "/date")          // out: 2017/12/27

goutils.FmtTime(time.Now(), ".datetime")      // out: 2017.12.27 21:15:15
goutils.FmtTime(time.Now(), ".datetime-")     // out: 2017.12.27 21:15
goutils.FmtTime(time.Now(), ".datetime--")    // out: 2017.12.27 21
goutils.FmtTime(time.Now(), ".date")          // out: 2017.12.27

goutils.FmtTime(time.Now(), "xzzz")           // error
goutils.MustFmtTime(time.Now(), "xzzz")       // panic
goutils.MustParseTime("2017-12-27", "-date")  // time object@2017-12-27

terminal color utils

goutils.GreenText("%s is very cool", "something")
goutils.RedText("this text will be red")

if more colorized text is required, use github.com/fatih/color instead.

input utils

goutils.Confirm will block the program and force user to make a choice before doing any other things.

goutils.Confirm("are you sure(y/n)?", []string {"y"}, []string {"n"}, func() {
  // do something when user input 'n'
})

About

Let goutils to accelerate your dev speed

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages