Types of Modules

Types of Modules

In this tutorial, we will discuss types of modules in GO language. We learn that module is a directory containing nested go packages.

Types of Modules

So essentially module can be treated as a package only that contains nested packages. We have seen in the package tutorial can a package can be either an executable package or a utility package (non-executable). Similar to package, modules can be of two types.

1. Executable module

We already know that main is the executable package in Go Language. Hence a module containing the main package is the executable module. 

The main package will contain a main function that denotes the start of a program. On installing the module having main package it will be create an executable in the $GOBIN directory.

2. Non-Executable module or Utility Module

Any package other than main package is a non-executable package. It is not self executable. It just contains the utility function and other utility things which can be utilized by an executable package.

Hence if the module doesn’t contain the main package then it will be a non-executable or utility module. This module is meant to be used as a utility and will be imported by other modules.

To create a executable for a module  (Only for module with main package)

  • Do a go build and it will create the executable in the current directory
  • Do a go install and it will create the executable in the $GOBIN directory

Types of Modules

Scroll to top