Introduction
In this challenge, you'll demonstrate your understanding of Go Modules by creating a modular project that showcases package management skills for a small utility library. The challenge involves creating a utility package with a function that converts a string to uppercase, and a main package that imports and uses the utility package's function. You'll also need to initialize Go Modules for both packages and ensure the main package successfully runs and prints the converted string.
Build a Modular Go Project
In this challenge, you'll demonstrate your understanding of Go Modules by creating a modular project that showcases package management skills for a small utility library. To simplify the process, we've provided a setup script that initializes the project structure and pre-fills the basic code framework. Your task is to complete the TODO sections in the code.
Tasks
Navigate to
~/project/utility/helper.goand complete theTODOsection:// TODO: Implement the ToUpperCase function using strings.ToUpperNavigate to
~/project/main/main.goand complete theTODOsections:// TODO: Call the utility.ToUpperCase function // TODO: Print the result using fmt.Println
Requirements
- Complete the provided
~/project/utility/helper.goand~/project/main/main.gofiles by filling in theTODOsections. - The utility package should define a function named
ToUpperCasethat converts a string to uppercase. - The main package should call the
ToUpperCasefunction and print its result.
Examples
After completing the TODO sections, your project structure should look like this:
~/project/
├── utility/
│ ├── go.mod
│ └── helper.go
└── main/
├── go.mod
└── main.go
When you run the main package, the output should be:
cd ~/project/main
go get utility
go run main.go
HELLO, WORLD
Hints
- The
strings.ToUpperfunction from the standard library can help you convert a string to uppercase. - Use
go mod initto initialize Go Modules. (It's already done for you) - Use
go get utilityto import the local utility package in the main package.
Summary
In summary, this challenge requires you to create a modular Go project that demonstrates your understanding of Go Modules and package management. You'll need to develop a utility package with a function to convert a string to uppercase, and a main package that imports and uses the utility package's function. The challenge also involves initializing Go Modules for both packages and ensuring the main package runs successfully and prints the converted string.



