Creating your GoLang package with Unit Tests

Kassim Damilola
Nov 5 · 2 min read

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.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade