Creating your GoLang package with Unit Tests

Kassim Damilola
2 min readNov 5, 2019

--

The goal of the Go project is to make it easy to build simple, reliable, and efficient software and that include creating your own public package that can be used by other programmers.

This this article I showed how to create a Go-Lang package by creating a finance library. This library makes it easy to incorporate common financial calculations into your application. essentially referencing the this JavaScript library.

Project Path

The project will be published on git hub on completion, hence the project path looks something like this:

$ %GOPATH%\src\github.com\"githubUserID"\"parentProject"\"packageFolder">$ %GOPATH%\src\github.com\dammyng\kdnotes\finance>
Project structure

Amortization, the first Function

Read about amortization using this link. Amortization is the paying off of debt with a fixed repayment schedule in regular installments over a period of time.1

For total number of payments which are entered as years, entryType takes a 0, whereas for months entryType takes a 1.

package financeimport ("math")
Amortization

The complete code can be found on GitHub

Writing simple tests

Amortization tests.
running go test
PASS
ok github.com/dammyng/kdnotes/finance 0.667s

This article shows how to simple Go-Lang package in future article, We will see how to use the created package in other projects, publishing to a public repository and some error handling.

Take a Golang quiz now Check out The Ultimate Go (Golang) Programming Challenge on Udemy

--

--