Elian  Harber

Elian Harber

1655712240

Gommon: Common Packages for Go

Gommon 

Common packages for Go

Bytes

  • Format bytes integer to human readable bytes string.
  • Parse human readable bytes string to bytes integer.

Installation

go get github.com/labstack/gommon/bytes

Usage

Format

println(bytes.Format(13231323))

12.62MB

Parse

b, _ = Parse("2M")
println(b)

2097152

Color

Style terminal text.

Installation

go get github.com/labstack/gommon/color

Windows?

Try cmder or https://github.com/mattn/go-colorable

Usage

import github.com/labstack/gommon/color

Colored text

color.Println(color.Black("black"))
color.Println(color.Red("red"))
color.Println(color.Green("green"))
color.Println(color.Yellow("yellow"))
color.Println(color.Blue("blue"))
color.Println(color.Magenta("magenta"))
color.Println(color.Cyan("cyan"))
color.Println(color.White("white"))
color.Println(color.Grey("grey"))

Colored Text

Colored background

color.Println(color.BlackBg("black background", color.Wht))
color.Println(color.RedBg("red background"))
color.Println(color.GreenBg("green background"))
color.Println(color.YellowBg("yellow background"))
color.Println(color.BlueBg("blue background"))
color.Println(color.MagentaBg("magenta background"))
color.Println(color.CyanBg("cyan background"))
color.Println(color.WhiteBg("white background"))

Colored Background

Emphasis

color.Println(color.Bold("bold"))
color.Println(color.Dim("dim"))
color.Println(color.Italic("italic"))
color.Println(color.Underline("underline"))
color.Println(color.Inverse("inverse"))
color.Println(color.Hidden("hidden"))
color.Println(color.Strikeout("strikeout"))

Emphasis

Mix and match

color.Println(color.Green("bold green with white background", color.B, color.WhtBg))
color.Println(color.Red("underline red", color.U))
color.Println(color.Yellow("dim yellow", color.D))
color.Println(color.Cyan("inverse cyan", color.In))
color.Println(color.Blue("bold underline dim blue", color.B, color.U, color.D))

Mix and match

Enable/Disable the package

color.Disable()
color.Enable()

New instance

c := New()
c.Green("green")

WORK IN PROGRESS

Usage

log_test.go

Author: labstack
Source Code: https://github.com/labstack/gommon 
License: MIT license

#go #golang #color #email 

What is GEEK

Buddha Community

Gommon: Common Packages for Go
Fannie  Zemlak

Fannie Zemlak

1599854400

What's new in the go 1.15

Go announced Go 1.15 version on 11 Aug 2020. Highlighted updates and features include Substantial improvements to the Go linker, Improved allocation for small objects at high core counts, X.509 CommonName deprecation, GOPROXY supports skipping proxies that return errors, New embedded tzdata package, Several Core Library improvements and more.

As Go promise for maintaining backward compatibility. After upgrading to the latest Go 1.15 version, almost all existing Golang applications or programs continue to compile and run as older Golang version.

#go #golang #go 1.15 #go features #go improvement #go package #go new features

Send Email in Golang using Go Mail Package | Emails in Go

Send an email with Golang using a popular package Gomail.

Gomail is a simple and efficient package to send emails. It is well tested and documented.
Gomail can only send emails using an SMTP server. But the API is flexible and it is easy to implement other methods for sending emails using a local Postfix, an API, etc.
Install Gomail: go get gopkg.in/gomail.v2

#golang #Gomail #emailGolang #GolangEMail

#golang #go mail package #go

Elian  Harber

Elian Harber

1655712240

Gommon: Common Packages for Go

Gommon 

Common packages for Go

Bytes

  • Format bytes integer to human readable bytes string.
  • Parse human readable bytes string to bytes integer.

Installation

go get github.com/labstack/gommon/bytes

Usage

Format

println(bytes.Format(13231323))

12.62MB

Parse

b, _ = Parse("2M")
println(b)

2097152

Color

Style terminal text.

Installation

go get github.com/labstack/gommon/color

Windows?

Try cmder or https://github.com/mattn/go-colorable

Usage

import github.com/labstack/gommon/color

Colored text

color.Println(color.Black("black"))
color.Println(color.Red("red"))
color.Println(color.Green("green"))
color.Println(color.Yellow("yellow"))
color.Println(color.Blue("blue"))
color.Println(color.Magenta("magenta"))
color.Println(color.Cyan("cyan"))
color.Println(color.White("white"))
color.Println(color.Grey("grey"))

Colored Text

Colored background

color.Println(color.BlackBg("black background", color.Wht))
color.Println(color.RedBg("red background"))
color.Println(color.GreenBg("green background"))
color.Println(color.YellowBg("yellow background"))
color.Println(color.BlueBg("blue background"))
color.Println(color.MagentaBg("magenta background"))
color.Println(color.CyanBg("cyan background"))
color.Println(color.WhiteBg("white background"))

Colored Background

Emphasis

color.Println(color.Bold("bold"))
color.Println(color.Dim("dim"))
color.Println(color.Italic("italic"))
color.Println(color.Underline("underline"))
color.Println(color.Inverse("inverse"))
color.Println(color.Hidden("hidden"))
color.Println(color.Strikeout("strikeout"))

Emphasis

Mix and match

color.Println(color.Green("bold green with white background", color.B, color.WhtBg))
color.Println(color.Red("underline red", color.U))
color.Println(color.Yellow("dim yellow", color.D))
color.Println(color.Cyan("inverse cyan", color.In))
color.Println(color.Blue("bold underline dim blue", color.B, color.U, color.D))

Mix and match

Enable/Disable the package

color.Disable()
color.Enable()

New instance

c := New()
c.Green("green")

WORK IN PROGRESS

Usage

log_test.go

Author: labstack
Source Code: https://github.com/labstack/gommon 
License: MIT license

#go #golang #color #email 

Pkgreflect: A Go Preprocessor for Package Scoped Reflection

pkgreflect - A Go preprocessor for package scoped reflection

Problem: Go reflection does not support enumerating types, variables and functions of packages.

pkgreflect generates a file named pkgreflect.go in every parsed package directory. This file contains the following maps of exported names to reflection types/values:

var Types = map[string]reflect.Type{ ... }
var Functions = map[string]reflect.Value{ ... }
var Variables = map[string]reflect.Value{ ... }
var Consts = map[string]reflect.Value{ ... }

Command line usage:

pkgreflect --help
pkgreflect [-notypes][-nofuncs][-novars][-noconsts][-unexported][-norecurs][-gofile=filename.go] [DIR_NAME]

If -norecurs is not set, then pkgreflect traverses recursively into sub-directories. If no DIR_NAME is given, then the current directory is used as root.

Author: Ungerik
Source Code: https://github.com/ungerik/pkgreflect 
License: MIT License

#go #golang #packaging 

Joseph  Murray

Joseph Murray

1624048020

How to Find All the Classes of a Package in Java

In this article let’s take a look at how to find all classes of a package in Java

To find all classes of a package in Java we can use the ClassHunter of Burningwave Core library. So we start by adding the following dependency to our pom.xml:

XML

1

<dependency>2
    <groupId>org.burningwave</groupId>3
    <artifactId>core</artifactId>4
    <version>8.4.0</version>5
</dependency>

The next steps are the following:

  • retrieving the ClassHunter through the ComponentContainer
  • defining a regular expression that we must pass to the **ClassCriteria **object that will be injected into the **SearchConfig **object
  • calling the **loadInCache **method that loads in the cache all loadable classes of the indicated paths, then applies the criteria filter and then returns the **SearchResult **object which contains the classes that match the criteria

#java #classes #class #packages #package #how to find all the classes of a package in java