Skip to main content
In this lesson you’ll learn how to create a Go module, add a local package, and import that package from main. We’ll build a small module named github.com/Priyanka-yadavv/cryptit that demonstrates a simple Caesar-style encryption (shift each character’s Unicode code point by 3). This exercise covers module initialization, package layout, exported identifiers, and running the program.

What you’ll build

  • Module: github.com/Priyanka-yadavv/cryptit
  • Packages:
    • encrypt — implements the encryption algorithm (algorithm.go)
    • decrypt — reserved for the decryption algorithm (to be added later)
  • At the module root: main.go — imports and uses encrypt
The encryption is a simple Caesar-style shift: add 3 to each rune (Unicode code point). Examples:
  • A -> D
  • M -> P
Planned project layout:
File overview

1. Create the module

Create the project directory and initialize a Go module using your repository import path (omit the https:// prefix):
Example go.mod generated (truncated):

2. Create the encrypt package

  1. Add the encrypt directory and the algorithm.go file:
  1. Implement an exported Encrypt function. Exported names in Go must begin with an uppercase letter so other packages can import and use them. The example below uses strings.Builder for efficient string concatenation while preserving the intended shift-by-3 behavior.
This implementation preserves Unicode behavior by iterating over runes (not bytes) and is idiomatic for building strings efficiently.

3. Create main.go to use the package

At the module root, create main.go and import the local package by using the module path followed by the package folder name.
Note that the import path is the module path plus /encrypt, matching the directory structure.

4. Build and run

From the module root run:
Expected output:
In Go, an identifier (function, type, variable, or constant) is exported from a package when its name begins with an uppercase letter. Exported identifiers are accessible to importing packages; unexported identifiers begin with a lowercase letter and are only visible inside the same package.

Summary

  • Initialized a module: github.com/Priyanka-yadavv/cryptit.
  • Created an encrypt package with an exported Encrypt function that shifts each rune by 3.
  • Added main.go at the module root to import and use encrypt.Encrypt.
  • You can later add a decrypt package to reverse the transformation.

Watch Video