My First Go Package: Nopol

Nopol is Go package to check and format Indonesian vehicle’s registration (police number)

I’m currently learning Go, and it’s fascinating!

I created an application in Go for one of my project. The project was porting and rewriting a legacy C# application to new application.

In my opinion, creating a production application is an effective method to speed up my learning. If the application will be used in production, so I have to write code seriously and learn deeply to make sure the application will not blow up.

One aspect I want to master in Go is creating a package. In Go, we’re suggested to split application into packages to make it small and fast. The concept of microservice is the goal in mind.

The other advantage of using package is reusability. We don’t want to repeatedly writing same code everywhere. Just import a package, use it, and we’re ready to go.

In Go, we’re encouraged to create a package with specific usage. That’s why the package name is very straight forward and reflecting its function.

In one part of my project, I need to format a string from database as a vehicle registration number (police number) format. Not all the strings were formatted correctly because it came from user input from other application which allow user to free inserting string without applying any validation.

I want to format this string for better readibility and following vehicle registration number standard.

Vehicle Registration Number

an example of vehicle registration number in Indonesia

In Indonesia, all motorized vehicles must be registered in the police office. Based on chassis number, engine number, vehicle model, and vehicle color, the police issue a registration number that has to be attached in front and the back of the vehicle.

This registration number (some people called as police number or license number) has following format AA XXXX AAA.

  • First segment of one or two letters represent the area of the registration
  • Second segment of numbers that range from one to four digits represent the identification
  • Last segment of one to three letters represent the detailed region, vehicle type, and additional info
  • In addition, the subscript segment below the registration number represent the expiration month and year of the registration

This is an example of the police number in Indonesia, AD 6742 DZ.

The AD part shows that the vehicle area is from Surakarta (Central Java) region. The 6742 show the identification number. Finally, the DZ part show the detailed origin of the vehicle, which is from Karanganyar district.

People sometime write like this: AD6742DZ, AD-6742-DZ, or even AD.6742.DZ. Even worse, they sometime write in using lowercase, for example, ad 6742 dz.

To unify this various format into a standard format, I wrote a Go package to do this task. The name of the package is Nopol (abbrevation of nomor polisi in Indonesian).

To use it, just go get-ing, importing, and you’re ready to go by using it like this.

import "github.com/matriphe/nopol"
func main() {
num, err := nopol.Format("Ad6742 dz") // num will return AD 6742 DZ
}

I hope this package will be useful for someone who has problem like me. And also feel free to comment, address issue, or make a pull request there.

Like what you read? Give Muhammad Zamroni a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.