Giter VIP home page Giter VIP logo

goutils's Introduction

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'
})

goutils's People

Contributors

gaols avatar

Watchers

 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.