GoLang helper module for fast development of CLI tools

Cipheras
2 min readApr 29, 2021

So the story starts with development of a cyber security tool in GoLang. While I was trying to make that tool it clicked my mind to make a helper module so that when I make any tool I don’t have to write all these code again & again and can focus mainly on the functionality of my tool.

GOHELPER

github.com/cipheras/gohelper

Cprint example

A GO module to help in projects in generating formatted logs in log files and colored messages on the terminal.

Installation

Import the module in your project and do.

go get github.com/cipheras/gohelper

Usage

gohelper basically has two features, creating formatted logs in a file and show formatted texts on console.To use gohelper, one just have to import the module. Best thing of this module is that you don’t have to rely on this modules log module, you can use original log module with it also.

Available features:

  • Try(err, bool, msg) — for logging into file and also showing on terminal.
  • Cprint(mode, msg) — to print colored texts/info/messages on terminal.
  • Cwindows() — to also show these colored texts/info/messages on windows cmd.
  • Flog() — to use gohelper’s log instead of your own.

Cases:

  • Try(nil, bool, msg) — will log as INFO in the file.
  • Try(err, bool, msg) — if err==nil, will log the msg as INFO. If err!=nil, it will log the err & msg as ERROR and also show ERROR msg on terminal.
  • Try(err, true, msg) — will exit if err!=nil & log as ERROR.
  • Try(err, false, msg) — will not exit & if err!=nil, will log as WARN.
  • Try(err, bool) — will log but don’t show on terminal.

In all the above cases, it will always log as INFO, if err==nil. If msg is given it will be shown on terminal, if not then it will be only logged.
In some cases, if there is no error to check and we still wanna log ERROR, we can use custom error using,

Try(errors.New(“custom error”, bool))

Try this module and in case of any query or issue, contact the author. For other uses and info read README.md

For more information, issue or contact go to the github repo.

Thanks for reading!!

--

--