5 Golang Modules/Packages That Every Developer Should Know

5 Golang Modules/Packages That Every Developer Should Know

5 New packages that you should now as a Golang dev

Go is a speedy, easy-to-learn, and handy new programming language developed by Google.

One of the most impressive things that come with the Golang is its documentation. It is like laravel, incredibly extensive, and easy to use. In this article, I will give you a look at the 5 Golang packages that every Go developer should know.

Goose - Database Migrations

Goose is the best DB migration tool to use in Golang. With this package, it becomes so easy to alter your DB schema.

1_cP_1S4ZVo6qyzvOdp81QNw.png

Installing Goose

Run the following command:

$ go get github.com/pressly/goose

You can also decide to use the light-weight version:

$ go build -tags='no_postgres no_mysql no_sqlite3' -i -o goose ./cmd/goose

Using Goose

To use Goose, you can create a new SQL migration by running the following command:

$ goose create new_column sql

For more in-depth documentation, I recommend you to visit their official page.

Go Kit - Microservices

Go Kit is a convenient package for dealing with microservices.

1_ZjSLh3x8hqGDKLsprrOzMw.png

Installing Go Kit

To install Go Kit, run the following command in your terminal:

$ go get github.com/go-kit/kit

Using Go Kit

Create a new project and create a new model for yourself.

package article
import (
    "time"
)
type Article struct {
    ID        string    `json:"id"`
    Username  string    `json:"username"`
    Content   string    `json:"content"`
    Text      string    `json:"title"`
    CreatedOn time.Time `json:"created_on"`
}

You can use this model in a service:

package article
import (
    "context"
)
type TodoService interface {
    GetAllForUser(ctx context.Context, username string) ([]Article, error)
    GetByID(ctx context.Context, id string) (Article, error)
    Add(ctx context.Context, article Article) (Article, error)
    Update(ctx context.Context, id string, article Article) error
    Delete(ctx context.Context, id string) error
}

Authboss - Modular Authentication

Authboss is a beneficial Modular Authentication package.

1_j2_dXHkFkJfU0NhvjbQJVQ.png

Installing Authboss

You can install Authboss by running the following command:

$ go get -u github.com/volatiletech/authboss/v3

Using Authboss

Authboss is quite an impressive module, so if you want to get a good understanding of how to use it, I'd recommend you to take a look at their documentation.

Gingko - Testing Framework

With Gingko, you can easily write tests for your Golang projects, and with this package, you can make it particularly easy to read for even non-technical people.

1_FasP088bajCkCo7E_JSyHA.png

Installing Gingko

To install this package, run the following command:

$ go get github.com/onsi/ginkgo/ginkgo

Using Gingko

To use Gingko, you need to bootstrap a new testing environment:

$ ginkgo bootstrap

For further explanation, check out their excellent documentation.

NSQ - Messaging Platform

NSQ is "A real-time distributed messaging platform." which can be very useful when you're looking for a system that can scale.

1_1368nkpmbnJzPFvWYl1bWA.png

Installing NSQ To install NSQ, we use the following command:

$ git clone https://github.com/nsqio/nsq
$ cd nsq
$ make

Using NSQ

Since NSQ is quite hard to understand right off the back, you'll definitely need to check out their documentation.

Takeaway - Bottom Line

As you can see, there are quite some handy packages for this relatively new programming language: Go. I hope that I gave you some new insights. You can use them at any time and ask me questions about them.