Skip to content

Your First Module

Status: Placeholder - Content coming soon

Prerequisites: Quick Start Guide, Go 1.21+ installed

Planned Content

This tutorial will teach you how to create a complete Go module from scratch in an r2r monorepo.

What You'll Learn

  • Create a simple Go module (hello-world-service)
  • Write table-driven unit tests (*_test.go)
  • Define the module contract in .r2r/eac/repository.yml
  • Understand module types, dependencies, and artifacts
  • Build and test with r2r build and r2r test
  • Verify module registration with r2r show modules

Tutorial Structure

  1. Set up module directory structure
  2. Create go/hello-world-service/ directory
  3. Initialize Go module with go mod init
  4. Understand Go module organization

  5. Write the implementation

  6. Create service.go with a simple greeting function
  7. Follow Go idiomatic conventions
  8. Keep it simple and focused

  9. Write unit tests

  10. Create service_test.go
  11. Implement table-driven tests
  12. Run tests with go test

  13. Register the module

  14. Add module contract to .r2r/eac/repository.yml
  15. Define module type, dependencies, and build configuration
  16. Understand contract schema

  17. Build and test with r2r

  18. Build: r2r build hello-world-service
  19. Test: r2r test hello-world-service
  20. Inspect artifacts: r2r show artifacts hello-world-service

  21. Understand module metadata

  22. Module types (go-app, go-lib, go-tool, etc.)
  23. Dependencies between modules
  24. Build artifacts and their purpose

Example Module

The tutorial will create a simple greeting service:

package greet

func Greet(name string) string {
    if name == "" {
        return "Hello, Guest!"
    }
    return fmt.Sprintf("Hello, %s!", name)
}

With comprehensive table-driven tests and proper error handling.

Key Concepts Covered

  • Go module structure in monorepo
  • Module contracts and registration
  • Table-driven testing pattern
  • Build artifacts and dependencies
  • r2r build and test commands

Next Steps

After completing this tutorial, you'll understand module fundamentals. Continue to Understanding Test Suites to learn about test levels and when to use each.


Tutorials | How-to Guides | Explanation | Reference

You are here: Tutorials — learning-oriented guides that take you through steps to complete a project.